Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write a program that will read all this information for last month’s sales and summarize the total sales by salesperson by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month,
print the results in tabular format with each of the columns representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns.
(Sales Summary) Use a two-dimensional array to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each different type of product sold. Each slip contains the following:
a) The salesperson number
b) The product number
c) The total dollar value of that product sold that day
```
#include
#include
using namespace std;
int main()
{
const int PEOPLE = 5;
const int PRODUCTS = 6;
double sales[ PEOPLE ][ PRODUCTS ] = { 0.0 };
double value;
double totalSales;
double productSales[ PRODUCTS ] = { 0.0 };
int salesPerson;
int product;
// enter sales slips
cout << "Enter the salesperson (1 - 4), product number (1 - 5), and "
<< "total sales.\nEnter -1 for the salesperson to end input.\n";
cin >> salesPerson;
// continue receiving input for each salesperson until -1 is entered
while ( salesPerson != -1 )
{
cin >> product >> value;
sales[ salesPerson ][ product ] += value;
cin >> salesPerson;
} // end while
cout << "\nThe total sales for each salesperson are displayed at the "
<< "end of each row,\n" << "and the total sales for each product "
<< "are displayed at the bottom of each column.\n " << setw( 12 )
<< 1 << setw( 12 ) << 2 << setw( 12 ) << 3 << setw( 12 ) << 4
<< setw( 12 ) << 5 << setw( 13 ) << "Total\n" << fixed << showpoint;
// display salespeople and sales
for ( int i = 1; i < PEOPLE; i++ )
{
totalSales = 0.0;
cout << i;
// add total sales, and display individual sales
for ( int j = 1; j < PRODUCTS; j++ )
{
totalSales += sales[ i ][ j ];
cout << setw( 12 ) << setprecision( 2 ) << sales[ i ][ j ];
productSales[ j ] += sales[ i ][ j ];
} // end inner for
cout << setw( 12 ) << setprecision( 2 ) << totalSales << '\n';
} // end outer for
cout << "\nTotal" << setw( 8 ) << setprecision( 2 )
<< productSales[ 1 ];
// display total product sales
for ( int j = 2; j < PRODUCTS; j++ )
cout << setw( 12 ) << setprecision( 2 ) << productSales[ j ];
cout << endl;
} // end main
```
Enter the salesperson (1 - 4), product number (1 - 5), and total sales.
Enter -1 for the salesperson to end input.
1 2 500
1 5 1000
2 3 45
2 1 1500
4 4 700
-1
The total sales for each salesperson are displayed at the end of each row,
and the total sales for each product are displayed at the bottom of each
column.
1 2 3 4 5 Total
1 0.00 500.00 0.00 0.00 1000.00 1500.00
2 1500.00 0.00 45.00 0.00 0.00 1545.00
3 0.00 0.00 0.00 0.00 0.00 0.00
4 0.00 0.00 0.00 700.00 0.00 700.00
Total 1500.00 500.00 45.00 700.00 1000.00
You might also like to view...
An abstract class is
A) one that has at least one pure virtual function. B) one that supports polymorphism. C) one that has all of its member functions declared private. D) one that has all of its member variables declared private. E) None of the above
You can open the Start menu by clicking the Start button or by pressing the ________ key
A) Enter B) Windows logo C) Start D) Tab
The stacking element allows elements to be placed one on top of another
Indicate whether the statement is true or false
A Wi-Fi ______ is a wireless local area network that provides Internet access to the public.
Fill in the blank(s) with the appropriate word(s).