Please do bonus as well Sales Report: A company has four salespeople (1 to 4) wh
ID: 3813197 • Letter: P
Question
Please do bonus as well Sales Report: A company has four salespeople (1 to 4) who sell five different products (1 to 5). Download a file named salesdata.txt that contains the sales data for last month. The rows represent the sales made by each salesperson for each of the 5 products. Write a modular C++ program salesreport.cpp that has: (a) a function getdata that will read in all the sales data from the file into a 2-dimensional array, (b) a function printsalesreport that will print the sales results in tabular format with each of the rows representing a particular salesperson and each of the columns representing a particular product. Cross total each column to get the total sales of each product for last month; cross total each row to print 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. (c) a function main that calls the other functions. Salesperson of the Month: Copy your salesreport.cpp program into salesmvp.cpp. Add an additional function that computes and displays the top salesperson (1, 2, 3, or 4) for last month and the total sales made by that person last month.Explanation / Answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int sales[4][5];
/* Assuming file format is:
3 4 6 8 1
2 4 5 6 9
4 4 6 2 5
2 3 5 6 0
arr[i][j] denotes sales of jth product by ith salesman
*/
void getdata()
{
ifstream read("a.txt");
for(int i=0;i<4;i++)
for(int j=0;j<5;j++)
read>>sales[i][j];
}
void printsalesreport()
{
cout<<"Salesperson Product1 Product2 Product3 Product4 Product5 Total ";
cout<<"Salesperson1 "<<sales[0][0]<<" "<<sales[0][1]<<" "<<sales[0][2]<<" "<<sales[0][3]<<" "<<sales[0][4]<<" "<<sales[0][0]+sales[0][1]+sales[0][2]+sales[0][3]+sales[0][4]<<endl;
cout<<"Salesperson2 "<<sales[1][0]<<" "<<sales[1][1]<<" "<<sales[1][2]<<" "<<sales[1][3]<<" "<<sales[1][4]<<" "<<sales[1][0]+sales[1][1]+sales[1][2]+sales[1][3]+sales[1][4]<<endl;
cout<<"Salesperson3 "<<sales[2][0]<<" "<<sales[2][1]<<" "<<sales[2][2]<<" "<<sales[2][3]<<" "<<sales[2][4]<<" "<<sales[2][0]+sales[2][1]+sales[2][2]+sales[2][3]+sales[2][4]<<endl;
cout<<"Salesperson4 "<<sales[3][0]<<" "<<sales[3][1]<<" "<<sales[3][2]<<" "<<sales[3][3]<<" "<<sales[3][4]<<" "<<sales[3][0]+sales[3][1]+sales[3][2]+sales[3][3]+sales[3][4]<<endl;
cout<<"Total "<<sales[0][0]+sales[1][0]+sales[2][0]+sales[3][0]<<" "<<sales[0][1]+sales[1][1]+sales[2][1]+sales[3][1]<<" "<<sales[0][2]+sales[1][2]+sales[2][2]+sales[3][2]<<" "<<sales[0][3]+sales[1][3]+sales[2][3]+sales[3][3]<<" "<<sales[0][4]+sales[1][4]+sales[2][4]+sales[3][4]<<endl;
}
void topsalesperson()
{
int a1 = sales[0][0]+sales[0][1]+sales[0][2]+sales[0][3]+sales[0][4];
int a2 = sales[1][0]+sales[1][1]+sales[1][2]+sales[1][3]+sales[1][4];
int a3 = sales[2][0]+sales[2][1]+sales[2][2]+sales[2][3]+sales[2][4];
int a4 = sales[3][0]+sales[3][1]+sales[3][2]+sales[3][3]+sales[3][4];
if(a1 > a2 && a1 > a3 && a1 > a4)
cout<<"Person 1: "<<a1<<endl;
else if(a2 > a1 && a2 > a3 && a2 > a4)
cout<<"Person 2: "<<a2<<endl;
else if(a3 > a1 && a3 > a2 && a3 > a4)
cout<<"Person 3: "<<a3<<endl;
else
cout<<"Person 4: "<<a4<<endl;
}
int main()
{
getdata();
printsalesreport();
topsalesperson();
return 0;
}