1) Write a program that asks the user to enter the names of three salesmen. The
ID: 3535293 • Letter: 1
Question
1) Write a program that asks the user to enter the names of three salesmen. The program should
then accept the sales produced for each quarter of the year. Display the name, and the total sales
amount, of each salesman.
Hint: Consider using two arrays in parallel. One array holds the name of the salesman (string
data type) and the other array holds the sales numbers (double data type). Since the data for
each salesman is of different data types, you cannot use one array to hold all of the data. (An
array is a collection of identical data types.) Arrays are considered to be parallel if one of the
subscripts in each array references the same thought (e.g. name[1] holds the name for the second
salesman and the sales data for the second salesman would be in sales[1]… ).
Hint: It is possible to solve this problem using a two dimensional array to hold the sales data with
one dimension referring to quarter and the other dimension referring to the sales amount for the
quarter. See if you can solve the problem, by calculating the total sales for each salesman as the
data is entered and storing only the names of the salesman and the total sales for each salesman.
Consider whether this problem could actually be solved without arrays. (Exercise 1 yes, but you
will need your two dimensional array for Exercise 2 below).
2) Extend above such that the name, and the corresponding sales amount, of the salesman
who sold the highest sales are displayed for each quarter.
Explanation / Answer
#include<iostream.h>
#include<string.h>
void main()
{
int sale[3][4] // 3 for 3 salesman and 4 for 4 quarters
int i,j,k=0;
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
cin>> sale[i][j];
}
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
k=k+sale[i][j];
cout<<"total sale for salesman is"<<k<<endl;
}
}//end of main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.