Use a twodimensional array to solve the following problem A

Use a two-dimensional array to solve the following problem: A company has four salespeople - Sales Person 1, Sales Person 2, Sales Person 3, and Sales Person 4. The company sells 5 products - Product 1, Product 2, Product 3, Product 4, and Product 5. Each day, a sales person hands in a slip with the following information: Sales Person Number (1-4), Product Number (1-5), and dollar value of that product sold. This dollar value should be entered in the appropriate place in the multi-dimensional array. Keep asking for data input until a -1 is entered for the sales person number (sentinel). Output: Your output should reflect the array in tabular format ALONG with cross-sectional totals. For example, your program should look something like this: Enter Sales Person Number (1-4) or-1 to quit and view data: 1 Enter the Product Number (1-5): 1 Enter the dollar value: 1000 Enter Sales Person Number (1-4) or-1 to quit and view data: 2 Enter the Product Number (1-5): 1 Enter the dollar value: 2000 Enter Sales Person Number (1-4) or-1 to quit and view data: 2 Enter the Product Number (1-5): 2 Enter the dollar value: 500 Enter Sales Person Number (1-4) or-1 to quit and view data: -1 Sales Person Product 1 Product 2 Product 3 Product 4 Product 5 Sales Person Totals

Solution

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
#include <iomanip>
using std::setiosflags;
using std::setprecision;
using std::setw;
int main()
{
const int PEOPLE = 5, PRODUCTS = 6;
double sales[ PEOPLE ][ PRODUCTS ] = { 0.0 }, value,totalSales, productSales[ PRODUCTS ] = { 0.0 };int salesPerson, product;
cout << \"Enter the sales person (1 - 4), \"<< \"product number (1 - 5)\ and total sales.\"<< \"Enter -1 for the sales person to end input.\ \";
cin >> salesPerson;
while ( salesPerson != -1 )
{
cin >> product >> value;
sales[ salesPerson ][ product ] += value;
cin >> salesPerson;
}
cout << \"\ The total sales for each sales person \"<< \"are displayed\ at the end of each row,\"<< \"and the total sales for each\ product \" << \"are displayed at the bottom of each column.\ \"<< setw( 10 ) << 1 << setw( 10 ) << 2<< setw( 10 ) << 3 << setw( 10 ) << 4<< setw( 10 ) << 5 << setw( 12 ) << \"Total\ \"<< setiosflags( ios::fixed | ios::showpoint );
for ( int i = 1; i < PEOPLE; ++i )
{
totalSales = 0.0;
cout << i;
for ( int j = 1; j < PRODUCTS; ++j )
{
totalSales += sales[ i ][ j ];
cout << setw( 10 ) << setprecision( 2 )<< sales[ i ][ j ];
productSales[ j ] += sales[ i ][ j ];
}
cout << setw( 10 ) << setprecision( 2 )
<< totalSales << \'\ \';
}
cout << \"\ Total\" << setw( 6 ) << setprecision( 2 )<< productSales[ 1 ];
for ( int j = 2; j < PRODUCTS; ++j )
cout << setw( 10 ) << setprecision( 2 )<< productSales[ j ];
cout << endl;
return 0;
}

 Use a two-dimensional array to solve the following problem: A company has four salespeople - Sales Person 1, Sales Person 2, Sales Person 3, and Sales Person 4

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site