Question

This program is intended for C++ A special type of situation, called a controlled break, can...

This program is intended for C++

A special type of situation, called a controlled break, can occur when processing records of data must temporarily pause because a key value has changed. For example, a control break might occur in a report that contains subtotals for groupings of records.

This program requires such a procedure.  

Sales people at a local car dealership are paid by commission. For every car sale, a sales person earns 30% of the base price or $100, whichever is higher.  

Write a program that uses of a loop to read through and process records in a file. Whenever the program encounters a new employee id, it should pause processing long enough to display the total of the previous employee’s commissions before processing the record just read. After all records have been processed, the program should display a count of the records processed, the total sales, and the total commissions paid out. A sample output follows:

                                        WEEKLY SALES REPORT

Employee Retail Base Commission

101 24125.00 1201.00     360.30

101    7650.00 350.00     105.00

101    38460.00 1517.00     455.10

***Total Commission for 101: 920.40

                                102 10500.00 500.00        150.00

102 7500.00   250.00        100.00

102 17551.00 1120.00        336.00

102 12400.00 400.00        120.00

***Total Commission for 102: 706.00

103 41500.00   550.00        165.00

103 18670.00 1250.00        375.00

103 6700.00 250.00        100.00

103 17067.00 1018.00        305.40

***Total Commission for 103: 945.40

Records:   11

Total Sales: 202123.00

Total Commissions: 2571.80

A sample input file, carsales.dat, to generate the report is shown below. The first value in a line is the employee id. The second value is the retail sale amount of the car (without tax.) The third item is the base price on which the sales person’s commission is determined. Note: It is important that our data set is sorted by sales person id number. If the data set is not sorted, the control-break process won't work.

101

24125 1201

101

7650 350

101

38460 1517

102

10500 500

102

7500 250

102

17551 1120

102

12400   400

103

41500   550

103

18670 1250

103

6700 250

103

17067 1018

Tips:

  • Make sure the input file exists prior to starting to process records. If the file does not exist, end the program.
  • When we read the first record, we need to initialize a variable we will use to compare all following records against to see if the employee id has changed. Typically, we complete this step prior to starting the loop which processes all subsequent records.
  • During normal processing, we accumulate a subtotal for the current sales person each time we loop. When the key field changes (and the control break occurs), we print the subtotal, reset the subtotal to 0, and reset the variable used to compare all following records to the new id number just read in.
  • Once the last record is read in and the loop ends, we will need to perform one last subtotal line prior to printing summary totals.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In case of any query do comment. Please rate answer as well. Thanks

Code;

#include <iostream>
#include<iomanip>
#include <fstream>

using namespace std;

int main()
{
//input file handle
   ifstream inputFile;
  
   int employeeId, previousEmployeeId, recordCount=0;
   float sales, basePrice,commission, employeeCommission=0, totalSales=0, totalCommission=0;
  
   //open input file
   inputFile.open("carsales.dat");
  
//if fail to open the file then end the program
if(inputFile.fail())
{
std::cout << "File open error" << std::endl;
return -1;
}
  
//display the header
cout <<"\t\tWEEKLY SALES REPORT" <<endl;
cout <<"Employee Retail\t\tBase\tCommission" <<endl;
//read first line of data
inputFile >> employeeId >> sales >> basePrice;
previousEmployeeId = employeeId;
  

do
{
recordCount++; //increase record count
commission = basePrice * 0.3; //set commission to 30 % of base price
if(commission < 100) //if commission is less than 100 then set it to 100
commission = 100;
totalSales += sales; //add sales to totalSales
totalCommission += commission; //add commission to totalCommission
  
if(previousEmployeeId == employeeId)
{
//if same employee then add it to employeeCommission
employeeCommission += commission;
//display employee data
cout << employeeId << setprecision(2) << fixed << "\t" <<setw(8) << sales << "\t" << basePrice << "\t" << commission <<endl;
}
else
{
//if new eomployee then display the data of previous Employee and then for new Employee
cout <<"***Total Commission for " << previousEmployeeId << ": " << employeeCommission <<endl;
cout << employeeId << setprecision(2) << fixed << "\t" << setw(8) << sales << "\t" << basePrice << "\t" << commission <<endl;
//reset the commission and previousEmployeeId
employeeCommission=commission;
previousEmployeeId = employeeId;
}
  
}while(inputFile >> employeeId >> sales >> basePrice);
  
//last employee final data
cout <<"***Total Commission for " << previousEmployeeId << ": " << employeeCommission <<endl;
//overall count and sales
cout <<"Records: " << recordCount <<endl;
cout <<"Total Sales: " << totalSales <<endl;
cout << "Total Commissions: " << totalCommission <<endl;
  
return 0;
}

=========screen shot of the code for indentation=======

input file:

Output:

Add a comment
Know the answer?
Add Answer to:
This program is intended for C++ A special type of situation, called a controlled break, can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Need help with this code. Can't use "using namespace std;" Control break report Objectives Read...

    C++ Need help with this code. Can't use "using namespace std;" Control break report Objectives Read data from a text file Write data to a text file Correctly end a file input loop when end of file is reached Process control breaks correctly Calculate sums for grouping of input data Implement an algorithm Format output data on a report neatly Test and debug a program Overview This assignment involves the creation of a level break report. The data file provided...

  • (Python) Write a program called sales.py that uses a list to hold the sums of the...

    (Python) Write a program called sales.py that uses a list to hold the sums of the sales for each month. The list will have 12 items with index 0 corresponds with month of “Jan”, index 1 with month “Feb”, etc. o Write a function called Convert() which is passed a string which is a month name (ex. “Jan”) and returns the matching index (ex. 0). Hint – use a list of strings to hold the months in the correct order,...

  • Information About This Project             In the realm of database processing, a flat file is a...

    Information About This Project             In the realm of database processing, a flat file is a text file that holds a table of records.             Here is the data file that is used in this project. The data is converted to comma    separated values ( CSV ) to allow easy reading into an array.                         Table: Consultants ID LName Fee Specialty 101 Roberts 3500 Media 102 Peters 2700 Accounting 103 Paul 1600 Media 104 Michael 2300 Web Design...

  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • Can you help us!! Thank you! C++ Write a program that can be used by a...

    Can you help us!! Thank you! C++ Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...

  • Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read...

    Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...

  • This project will allow you to write a program to get more practice with the stack...

    This project will allow you to write a program to get more practice with the stack and queue data structures, as well as more practice with object-oriented ideas that we explored in the previous projects. In this assignment you will be writing a simulation of an order-fulfillment system for a company like Amazon.com. These companies take orders for products and ship them to customers based on what they have in inventory. For this assignment you will be performing a scaled-back...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT