need help to complet this program please: Assume that the input values contain a
ID: 3549859 • Letter: N
Question
need help to complet this program please:Assume that the input values contain a sales report of a company.
Write a program that calculates the average sales and the total sales of each salesman
as well as the total sales of each quarter.
For example, for the following sales report:
Salesman Q1 Q2 Q3 Q4
Willie 11.3 9.1 4.6 2.1
Biff 1.1 0.5 2.7 1.2
Al 3.4 2.5 1.2 2.3
Dave 23.7 19.9 34.3 28.5
Jack 17.4 22.8 51.8 12.5
Bill 143.9 97.8 114.2 88.8
the output of the program should look like the following:
Salesman Q1 Q2 Q3 Q4 Total Average
Willie 11.3 9.1 4.6 2.1 27.1 6.78
Biff 1.1 0.5 2.7 1.2 5.5 1.38
Al 3.4 2.5 1.2 2.3 9.4 2.35
Dave 23.7 19.9 34.3 28.5 106.4 26.60
Jack 17.4 22.8 51.8 12.5 104.5 26.13
Bill 143.9 97.8 114.2 88.8 444.7 111.18
Total 200.8 152.6 208.8 135.4
*/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main( )
{
const int NumOfSalesman = 6; // the number of salesmen
string salesman[NumOfSalesman]; // contains the names of salesmen
float salesreport[NumOfSalesman][4]; // contains the sales report
float salesmanTotal[NumOfSalesman]; // the total sales of salesmen
float salesmanAvg[NumOfSalesman]; // the average sales of salesmen
float quarterTotal[4]; // the taotal sales of each quarter
// read the sales report
cin.ignore(256, ' '); // ignore the first line -- the table head
for ( int index=0; index<NumOfSalesman; index++ )
{
cin >> salesman[index]; // read the name of the first salesman
// read quarter sales of the salesman specified by the index
for ( int quarter=0; quarter<4; quarter++ )
cin >> salesreport[index][quarter];
}
//1. calculate the total sales and average sales of each sales man
1. calculate the total sales and average sales of each sales man
//2. calculate the total sales of each quarter
2. calculate the total sales of each quarter
// output the table head
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;
// output statistics of each salesman
for ( int index=0; index<NumOfSalesman; index ++ )
{ // output each row
cout << setw(10) << left << salesman[index];
for ( int quarter=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;
}
//output quarter total
cout << endl << setw(10) << left << "Total";
for( int quarter=0; quarter<4; quarter++ )
cout << setw(10) << right << setprecision(2) << fixed << quarterTotal[quarter];
cout << endl;
return 0;
}
need help to complet this program please:
Assume that the input values contain a sales report of a company.
Write a program that calculates the average sales and the total sales of each salesman
as well as the total sales of each quarter.
For example, for the following sales report:
Salesman Q1 Q2 Q3 Q4
Willie 11.3 9.1 4.6 2.1
Biff 1.1 0.5 2.7 1.2
Al 3.4 2.5 1.2 2.3
Dave 23.7 19.9 34.3 28.5
Jack 17.4 22.8 51.8 12.5
Bill 143.9 97.8 114.2 88.8
the output of the program should look like the following:
Salesman Q1 Q2 Q3 Q4 Total Average
Willie 11.3 9.1 4.6 2.1 27.1 6.78
Biff 1.1 0.5 2.7 1.2 5.5 1.38
Al 3.4 2.5 1.2 2.3 9.4 2.35
Dave 23.7 19.9 34.3 28.5 106.4 26.60
Jack 17.4 22.8 51.8 12.5 104.5 26.13
Bill 143.9 97.8 114.2 88.8 444.7 111.18
Total 200.8 152.6 208.8 135.4
*/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main( )
{
const int NumOfSalesman = 6; // the number of salesmen
string salesman[NumOfSalesman]; // contains the names of salesmen
float salesreport[NumOfSalesman][4]; // contains the sales report
float salesmanTotal[NumOfSalesman]; // the total sales of salesmen
float salesmanAvg[NumOfSalesman]; // the average sales of salesmen
float quarterTotal[4]; // the taotal sales of each quarter
// read the sales report
cin.ignore(256, ' '); // ignore the first line -- the table head
for ( int index=0; index<NumOfSalesman; index++ )
{
cin >> salesman[index]; // read the name of the first salesman
// read quarter sales of the salesman specified by the index
for ( int quarter=0; quarter<4; quarter++ )
cin >> salesreport[index][quarter];
}
//1. calculate the total sales and average sales of each sales man
1. calculate the total sales and average sales of each sales man
//2. calculate the total sales of each quarter
2. calculate the total sales of each quarter
// output the table head
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;
// output statistics of each salesman
for ( int index=0; index<NumOfSalesman; index ++ )
{ // output each row
cout << setw(10) << left << salesman[index];
for ( int quarter=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;
}
//output quarter total
cout << endl << setw(10) << left << "Total";
for( int quarter=0; quarter<4; quarter++ )
cout << setw(10) << right << setprecision(2) << fixed << quarterTotal[quarter];
cout << endl;
return 0;
}
Explanation / Answer
/*
Salesman Q1 Q2 Q3 Q4
Willie 11.3 9.1 4.6 2.1
Biff 1.1 0.5 2.7 1.2
Al 3.4 2.5 1.2 2.3
Dave 23.7 19.9 34.3 28.5
Jack 17.4 22.8 51.8 12.5
Bill 143.9 97.8 114.2 88.8
the output of the program should look like the following:
Salesman Q1 Q2 Q3 Q4 Total Average
Willie 11.3 9.1 4.6 2.1 27.1 6.78
Biff 1.1 0.5 2.7 1.2 5.5 1.38
Al 3.4 2.5 1.2 2.3 9.4 2.35
Dave 23.7 19.9 34.3 28.5 106.4 26.60
Jack 17.4 22.8 51.8 12.5 104.5 26.13
Bill 143.9 97.8 114.2 88.8 444.7 111.18
Total 200.8 152.6 208.8 135.4
*/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main( )
{
const int NumOfSalesman = 6; // the number of salesmen
string salesman[NumOfSalesman]; // contains the names of salesmen
float salesreport[NumOfSalesman][4]; // contains the sales report
float salesmanTotal[NumOfSalesman]; // the total sales of salesmen
float salesmanAvg[NumOfSalesman]; // the average sales of salesmen
float quarterTotal[4]; // the taotal sales of each quarter
// read the sales report
cin.ignore(256, ' '); // ignore the first line -- the table head
for ( int index=0; index<NumOfSalesman; index++ )
{
cin >> salesman[index]; // read the name of the first salesman
// read quarter sales of the salesman specified by the index
for ( int quarter=0; quarter<4; quarter++ )
cin >> salesreport[index][quarter];
}
//1. calculate the total sales and average sales of each sales man
for ( int index=0; index<NumOfSalesman; index++)
{
salesmanTotal[index] = 0;
for(int j=0; j<4; j++)
salesmanTotal[index] = salesmanTotal[index] + salesreport[index][j];
salesmanAvg[index] = salesmanTotal[index]/4;
}
//2. calculate the total sales of each quarter
for(int j=0; j<4; j++)
{
quarterTotal[j] = 0;
for ( int index=0; index<NumOfSalesman; index++)
{
quarterTotal[j] = quarterTotal[j]+salesreport[index][j];
}
}
// output the table head
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;
// output statistics of each salesman
for ( int index=0; index<NumOfSalesman; index ++ )
{ // output each row
cout << setw(10) << left << salesman[index];
for ( int quarter=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;
}
//output quarter total
cout << endl << setw(10) << left << "Total";
for( int quarter=0; quarter<4; quarter++ )
cout << setw(10) << right << setprecision(2) << fixed << quarterTotal[quarter];
cout << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.