Use a two-dimensional array to solve the following problem. A company has four s
ID: 3624147 • Letter: U
Question
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
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
Explanation / Answer
Dear user, Here is the code below: #include<iostream>using std::cout; using std::cin; using std::endl; # include <iomanip> using std::setw; int main( ) { int sales[150][5]; char choice = '1'; int day = 0, row = 0; for (int i = 0 ; i < 4; i++) for ( int j = 0; j < 5; j++) sales[ i ][ j ] = 0; cout << " Report of the Products and Salesman sales. " ; do { cout << endl << "Enter the details of the day " << ( day + 1 ); do { cout << endl << "Enter the salesperson number : "; cin >> sales[ row ][ 0 ]; cout << endl << "Enter the product number : "; cin >> sales[ row ][ 1 ]; cout << endl << "Enter the total dollar value of that product sold that day : "; cin >> sales[ row ][ 2 ]; sales[ row ][ 3 ] = day + 1; cout << endl << "Do you want to enter one more (Y/N) : "; cin >> choice; row++; } while ( tolower( choice ) != 'n' ); day++; } while ( day < 30 ); int productTotal, salesmanSales[ 4 ]; for ( int d = 1; d <= day; d++ ) { for ( int z = 0; z < 4; z++ ) salesmanSales[ z ] = 0; cout << endl << endl << " Sales Summary for the day" << d << endl; cout << "Product# Salesman1 Salesman2 Salesman3 Salesman4 Totals"; for ( int product = 1; product < 6; product++ ) { productTotal = 0; cout << endl << setw(5) << product ; for ( int sperson = 1; sperson < 5; sperson++ ) { bool found = false; for ( int r = 0; r < row; r++ ) { if ( sales[ r ][ 1 ] == product ) if ( sales[ r ][ 0 ] == sperson) if ( sales[ r ][ 3 ] == d ) { productTotal += sales[ r ][ 2 ]; salesmanSales[sperson-1] += sales[r][2]; cout << setw(13) << sales[ r ][ 2 ]; found = true; } } if ( found == false ) cout << setw(13) << "0"; if ( found == false ) cout << setw(13) << "0"; }
cout << setw(10) << productTotal; }
cout << endl << "Total"; productTotal = 0; for ( int z = 0; z < 4; z++ ) { cout << setw(13) << salesmanSales[ z ]; productTotal += salesmanSales[ z ]; } cout << setw(10) << productTotal; } return 0; }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.