Writeaprogramthatcalculatestheaveragesalesandthetotalsalesofeachsalesman aswella
ID: 3648843 • Letter: W
Question
Writeaprogramthatcalculatestheaveragesalesandthetotalsalesofeachsalesman
aswellasthetotalsalesofeachquarter.
Forexample,forthefollowingsalesreport:
SalesmanQ1Q2Q3Q4
Willie11.39.14.62.1
Biff1.10.52.71.2
Al3.42.51.22.3
Dave23.719.934.328.5
Jack17.422.851.812.5
Bill143.997.8114.288.8
theoutputoftheprogramshouldlooklikethefollowing:
SalesmanQ1Q2Q3Q4TotalAverage
Willie11.39.14.62.127.16.78
Biff1.10.52.71.25.51.38
Al3.42.51.22.39.42.35
Dave23.719.934.328.5106.426.60
Jack17.422.851.812.5104.526.13
Bill143.997.8114.288.8444.7111.18
Total200.8152.6208.8135.4
*/
#include<iostream>
#include<string>
#include<iomanip>
usingnamespacestd;
intmain()
{
constintNumOfSalesman=6;//thenumberofsalesmen
stringsalesman[NumOfSalesman];//containsthenamesofsalesmen
floatsalesreport[NumOfSalesman][4];//containsthesalesreport
floatsalesmanTotal[NumOfSalesman];//thetotalsalesofsalesmen
floatsalesmanAvg[NumOfSalesman];//theaveragesalesofsalesmen
floatquarterTotal[4];//thetaotalsalesofeachquarter
//readthesalesreport
cin.ignore(256,' ');//ignorethefirstline--thetablehead
for(intindex=0;index<NumOfSalesman;index++)
{
cin>>salesman[index];//readthenameofthefirstsalesman
//readquartersalesofthesalesmanspecifiedbytheindex
for(intquarter=0;quarter<4;quarter++)
cin>>salesreport[index][quarter];
}
//1.calculatethetotalsalesandaveragesalesofeachsalesman
1. calculate the total sales and average sales of each sales man
//2.calculatethetotalsalesofeachquarter
2. calculate the total sales of each quarter
//outputthetablehead
cout<<setw(10)<<left<<"Salesman"
<<setw(10)<<right<<"Q1"
<<setw(10)<<right<<"Q2"
<<setw(10)<<right<<"Q3"
<<setw(10)<<right<<"Q4"
<<setw(15)<<right<<"Total"
<<setw(10)<<right<<"Average"
<<endl<<endl;
//outputstatisticsofeachsalesman
for(intindex=0;index<NumOfSalesman;index++)
{//outputeachrow
cout<<setw(10)<<left<<salesman[index];
for(intquarter=0;quarter<4;quarter++)
cout<<setw(10)<<setprecision(2)<<fixed<<right<<salesreport[index][quarter];
cout<<setw(15)<<setprecision(2)<<fixed<<right<<salesmanTotal[index]
<<setw(10)<<setprecision(3)<<fixed<<right<<salesmanAvg[index]
<<endl;
}
//outputquartertotal
cout<<endl<<setw(10)<<left<<"Total";
for(intquarter=0;quarter<4;quarter++)
cout<<setw(10)<<right<<setprecision(2)<<fixed<<quarterTotal[quarter];
cout<<endl;
return0;
}
Explanation / Answer
//Is there a reason that all the spacing are removed? Also, you have 4 quarters, but you have 5 quarters of input? //1.calculatethetotalsalesandaveragesalesofeachsalesman int temp; for(int j=0;jRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.