Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use a two-dimensional array to solve the following problem. A company has four s

ID: 3638365 • 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. Salesperson number b. Product number c. 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 sorted 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

here is download link for code http://www.eecs.wsu.edu/~cs150/tutorial/array/code6_10.c following is program 1 /******************************************************************************* 2 * This program reads in sales data for a month and summarizes it by salesperson 3 * and type of sales made 4 ********************************************************************************/ 5 #include 6 7 void getSales(float[ ][5]); 8 void printHeader(void); 9 void printSales(float[ ][5]); 10 11 12 int main(void) 13 { 14 /* declare and initialize the array */ 15 float sales[4][5] = {0.0}; 16 17 /* call the function to read in the sales from the user*/ 18 getSales(sales); 19 20 /*call the function to display the table header */ 21 printHeader(); 22 23 /* call the function to display the sales */ 24 printSales(sales); 25 26 return 0; 27 } 28 29 30 /************* getSales **************************** 31 * Description: reads sales figures in from the user 32 * until the user enters -1 33 * Parameters: 2-dimensional float array (4 X 5) 34 * Return Type: void 35 ***************************************************/ 36 void getSales(float sales[ ][5]) 37 { 38 int salesPerson; 39 int product; 40 float value; 41 42 printf(" Enter the salesperson, product, and total sales. "); 43 printf("(Enter -1 for the salesperon to end input): "); 44 scanf("%d", &salesPerson); 45 46 while (salesPerson != -1) 47 { 48 scanf("%d%f", &product, &value); 49 sales[salesPerson - 1][product - 1] += value; 50 printf(" Enter the salesperson, product, and total sales. "); 51 printf("(Enter -1 for the salesperon to end input): "); 52 scanf("%d", &salesPerson); 53 } 54 } 55 56 57 /*************** printHeader ************************* 58 * Description: displays the header for the table 59 * Parameters: none 60 * Return Type: none 61 *****************************************************/ 62 void printHeader(void) 63 { 64 printf(" The total sales for each salesperson "); 65 printf(" are displayed at the end of each row "); 66 printf(" and the total sales for each product "); 67 printf(" are displayed at the bottom of each column "); 68 printf("Sales-0s ", "Products"); 69 printf("person ?????%9s ", 1, 2, 3, 4, 5, "Total"); 70 71 } 72 73 74 /************* printSales **************************** 75 * Description: displays the sales and summaries 76 * Parameters: 2-dimensional float array 77 * Return Type: void 78 ***************************************************/ 79 void printSales(float sales[ ][5]) 80 { 81 float totalSales; 82 int i, j; 83 float productSales[5] = {0.0}; 84 85 for (i = 0; i < 4; i++) 86 { 87 totalSales = 0.0; 88 printf("= ", i+1); 89 90 for (j = 0; j < 5; j++) 91 { 92 totalSales += sales[i][j]; 93 productSales[j] += sales[i][j]; 94 printf("%8.2f", sales[i][j]); 95 } 96 97 printf("%8.2f ", totalSales); 98 } 99 100 printf("Total "); 101 102 for (j = 0; j < 5; j++) 103 printf("%8.2f", productSales[j]); 104 105 printf(" "); 106 }