/****************************************************** ** Name: ** Filename: salesslip.cpp ** Project #: ** Project Description: Use a double-subscripted 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 in a disk file. 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 double-subscripted array sales. After processing all the information for last month, print the results in tabular format where each of the columns represents a particular product and each of the rows represents a particular salesperson. Cross total each row to get the total sales by salesperson for last month; and cross total each column to get the total sales of each product during the last month. Your tabular printout should include these cross totals to the right of the totaled rows and at the bottom of the totaled columns. With the included data, the totaled information you should obtain is as follows: Salesperson Amount Product Amount 1 88084 1 68233 2 70600 2 63487 3 78905 3 61467 4 83826 4 69012 5 59216 ** Output: Tabular printout of data for total sales by each salesperson and total sales of each product during the last month. ** Input: Data input from file datafile.txt ** Algorithm: Display purpose of program and what is to be performed. Input data for salesperson, product and dollar value of product sold that day. When -1 is detected in file for salesperson, then end program. Calculate amount of each product for each employee Total amount of all products sold by all salespersons Total amount of each product sold. Compute grand total. Display results in a 5 by 6 table. End program ******************************************************/ // Include files #include // used for cin, cout #include #include #include using namespace std; // Global Type Declarations // Function Prototypes void instruct (void); void pause (); //Global Variables - should not be used without good reason. int main () { // Declaration section const int EMPLOYEE = 5, PRODUCTS = 6; double sales[ EMPLOYEE ][ PRODUCTS ] = { 0.0 }, value, totalSales, productSales[ PRODUCTS ] = { 0.0 }, grandTotal = 0; int salesPerson, product; ifstream inDataFile ("A:/datafile.txt", ios::in ); // Executable section instruct (); { if ( !inDataFile ) { cerr << "File could not be opened\n"; exit( 1 ); } cout << "\t ***************** Reading Data From File *********" << "*******"; pause (); inDataFile >> salesPerson; while ( salesPerson != -1 ) { inDataFile >> product; inDataFile >> value; sales[ salesPerson ][ product ] += value; inDataFile >> salesPerson; } cout << "\n\t The total sales for each sales person " << "are displayed\n\t at the end of each row," << "and the total sales for each\n\t product " << "are displayed at the bottom of each column.\n" << "-----------------------------------------------------" << "--------------------------\n\n\n" << "Sales |\t<---------------------- Products -----------" << "---------->\n" << "Person|\n" << "_____________________________________________________" << "__________________________\n" << setw( 10 ) << 1 << setw( 13 ) << 2 << setw( 13 ) << 3 << setw( 13 ) << 4 << setw( 13 ) << 5 << setw( 16 ) << "Total\n" << "_____________________________________________________" << "__________________________\n\n" << setiosflags( ios::fixed | ios::showpoint ); for ( int i = 1; i < EMPLOYEE; ++i ) { totalSales = 0.0; cout << i; for ( int j = 1; j < PRODUCTS; ++j ) { totalSales += sales[ i ][ j ]; cout << setw( 13 ) << setprecision( 2 ) << sales[ i ][ j ]; productSales[ j ] += sales[ i ][ j ]; } cout << setw( 13 ) << setprecision( 2 ) << totalSales << '\n'; } cout << "\n_____________________________________________________" << "__________________________\n" << setw( 80 ) << " Grand Total\n" << setw( 80 ) << "-----------\n"; cout << "Total " << setw( 6 ) << setprecision( 2 ) << productSales[ 1 ]; for ( int j = 2; j < PRODUCTS; ++j ) cout << setw( 13 ) << setprecision( 2 ) << productSales[ j ]; for (j = 0; j < PRODUCTS; ++j) grandTotal += productSales[j]; cout << setw( 13 ) << grandTotal << "\n" << endl; } pause (); return 0; } void instruct (void) { // Declaration section cout << "This program will access the sales data information for last " << "months sales by\neach salesperson. This information is contained in " << "the disk file datafile.txt.\nThe program will then take the data and " << "compute the total sales by salesperson\nfor last month, and the total " << "sales of each product during the last month and\ndisplay the results " << "on the screen.\n" << "\n_____________________________________________________" << "__________________________\n" << endl; pause (); // Executable section } void pause () { // Declaration section // Executable section cout << "\nPress any key to continue..."; getch(); cout << "\r"; cout << " "; cout << "\r"; } /* Program Output This program will access the sales data information for last months sales by each salesperson. This information is contained in the disk file datafile.txt. The program will then take the data and compute the total sales by salesperson for last month, and the total sales of each product during the last month and display the results on the screen. _______________________________________________________________________________ Press any key to continue... ***************** Reading Data From File **************** Press any key to continue... 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. ------------------------------------------------------------------------------- Sales | <---------------------- Products ---------------------> Person| _______________________________________________________________________________ 1 2 3 4 5 Total _______________________________________________________________________________ 1 16214.00 15467.00 23850.00 19057.00 13496.00 88084.00 2 10998.00 16014.00 13078.00 22507.00 8003.00 70600.00 3 17085.00 18833.00 9328.00 9023.00 24636.00 78905.00 4 23936.00 13173.00 15211.00 18425.00 13081.00 83826.00 _______________________________________________________________________________ Grand Total ----------- Total 68233.00 63487.00 61467.00 69012.00 59216.00 321415.00 Press any key to continue... */