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

C++ Brewster\'s Used Car\'s, Inc. employ several sales people. Brewster, the own

ID: 3708755 • Letter: C

Question

C++

Brewster's Used Car's, Inc. employ several sales people. Brewster, the owner of the company, has provided a file that contains sales records for each salesperson for the past month. Each record in the file contains the following two fields: The salesperson's ID number, as an integer and the amount of a sale, as a real number. The records are already sorted by salesperson ID. Brewster wants you to design a program that prints a sales report. The report should show each salesperson's sales and the total sales for that salesperson. The report should also show the total sales for all salespeople for the month.

Here is an example of how the sales report should appear:

Brewster's Used Cars, Inc. Sales Report

Salesperson ID Sale Amount ======================================

100 100 100 Total sales for this salesperson: $27,000.00

101 101 101 Total sales for this salesperson: $44,500.00

102 102 102 Total sales for this salesperson: $48,000.00 Total of all sales: $119,500.00

$10,000.00 $12,000.00 $5,000.00

$14,000.00 $18,000.00 $12,500.00

$13,500.00 $14,500.00 $20,000.00

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
ifstream myfile ("mytext.txt"); //filestream object to operation on file file name is mytext.txt
if (!myfile.is_open()) //opening file for reading from the file
{
cout<<"error in opening file"<<endl; //error message
return 0; //error in opening of file then return
}
int id;
double sale,totalsale=0;
cout<<"Salesperson ID Sale Amount ======================================"<<endl;
while ( myfile >> id, myfile >> sale) //reading salesman id and its total sales of sales person line by line
{
cout << id <<" Total sales for this salesperson: $"<<sale<<endl; //displaying id as salesman id and sale as salesman amount
totalsale+=sale; //calculating total amount sale in a month
}
myfile.close();
cout<<endl<<"Total of all sales: $"<<totalsale<<endl; //displaying total amount sales in a month
return 0;
}

Input file contains:

100100100 27000.00

101101101 44500.00

102102102 48000.00

103103103 68000.00

104104104 49000.00

Output:

Salesperson ID Sale Amount ======================================
100100100 Total sales for this salesperson: $27000
101101101 Total sales for this salesperson: $44500
102102102 Total sales for this salesperson: $48000
103103103 Total sales for this salesperson: $68000
104104104 Total sales for this salesperson: $49000

Total of all sales: $236500