Use a two-dimensional array to solve the following problem: A company has four s
ID: 3631099 • Letter: U
Question
Use a two-dimensional array to solve the following problem: A company has four sales people (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each type of product sold. Each slip contains the following:
• The salesperson number (1 to 4)
• The product number (1 to 5)
• The total dollar value of that product sold that day (in dollars and cents)
Thus each salesperson passes in between 0 and 5 sales slips per day depending on how many different products they sold that day. Assume that all the slips for last month are available. Write an application that will read all this informationfor last month’s sales (console input) and summarize the total sales by salespersion and by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, display the results in tabular format, with each column representing a particular salespersion and each row representing a particular product. Cross-total each row to get the total sales for each product for last month. Cross-total each column to get the total sales by salesperson for last month. Your tabular output should include these cross-totals to the right of the totaled rows and to the bottom of the totaled columns.
Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
int main()
{
double sales[4][5];
int i = 0, j = 0;
double total,grandtotal;
for(i = 0; i < 4; i++)
{cout<<"for salesman "<<(i+1)<<": ";
for(j = 0; j < 5; j++)
{cout<<"Enter sales for item " <<(j+1)<< ": ";
cin>>sales[i][j];
}
cout<<endl;
}
grandtotal=0;
cout<<" Salesman item 1 item 2 item 3 item 4 item 5 total ";
for(i = 0; i < 4; i++)
{cout<<" "<<(i+1)<<" ";
total=0;
for(j=0;j<5;j++)
{total+=sales[i][j];
cout<<sales[i][j]<<" ";
}
cout<<total<<endl;
grandtotal+=total;
}
cout<<" Total ";
for(i=0;i<5;i++)
{total=0;
for(j=0;j<4;j++)
total+=sales[j][i];
cout<<total<<" ";
}
cout<<grandtotal<<endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.