Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Array Help. I need help on the second picture not the first. Problem descrip

ID: 3869366 • Letter: C

Question

C++ Array Help. I need help on the second picture not the first. Problem description Write a program that asks the user to enter the names of three salesmen. The program should then accept the sales produced for salesman for each quarter of the year. Display the name, and the total sales amount, of each salesman. Name your program Lab11 Exercise1.cpp. Your program should have at least three functions: Your main, a second function that reads in the salesman name and sales amounts for the quarters, and a third function that displays the results. Do not use any global variables. You will need to pass data to the functions as parameters. 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

Explanation / Answer

#include <iostream>

using namespace std;

void readData(string name[3],double sales[3][4])

{

int i,j;

  

for(i=0;i<3;i++)

{

cout<<" Enter in the name of the salesman " <<(i+1);

cin>>name[i];

  

cout<<" Now enter in the sales for each quarter for "<<name[i];

for(j=0;j<4;j++)

{

cout<<" Enter in data for quarter "<<(j+1)<<" : ";

cin>>sales[i][j];

  

}

  

  

}

}

void display(string name[3],double sales[3][4])

{

int i,j;

string n;

  

double highestSale[4];

for(j=0;j<4;j++)

{

highestSale[j] = 0;

for(i=0;i<3;i++)

{

if(highestSale[j]<sales[i][j])

{

highestSale[j] = sales[i][j];

n= name[i];

}

  

}

cout<<" The Salesman "<<n<<" has highest sales for quarter "<<highestSale[j]<<endl;

}

  

  

}

int main()

{

string name[3];

double sales[3][4];

  

readData(name,sales);

  

display(name,sales);

return 0;

}

output:

Enter in the name of the salesman 1
Now enter in the sales for each quarter for Leo
Enter in data for quarter 1 : 23001
Enter in data for quarter 2 : 82002
Enter in data for quarter 3 : 56003
Enter in data for quarter 4 : 95004
Enter in the name of the salesman 2
Now enter in the sales for each quarter for Jane
Enter in data for quarter 1 : 93011
Enter in data for quarter 2 : 37012
Enter in data for quarter 3 : 81013
Enter in data for quarter 4 : 94014
Enter in the name of the salesman 3
Now enter in the sales for each quarter for Judy
Enter in data for quarter 1 : 43710
Enter in data for quarter 2 : 83721
Enter in data for quarter 3 : 92732
Enter in data for quarter 4 : 92177
The Salesman Jane has highest sales for quarter 93011

The Salesman Judy has highest sales for quarter 83721

The Salesman Judy has highest sales for quarter 92732

The Salesman Leo has highest sales for quarter 95004