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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Header Files
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education