MCC - Marquez - CIS162AB - C++ Level I
P04 Monthend Payroll Loop - 30 points![]()
In this C++ programming project the student incorporates nested loops, data validation, arithmetic expressions, and simple input/output functions into one program.This program will be used by payroll clerks to determine the total gross pay for the month by processing the weekly hours worked of their employees. We will not be concerned with calculating taxes and net pay. The user will be asked to input the number of employees to process. If a zero is entered, the loop to process the number of employees should be by passed. Only positive integers and zero should be allowed as input, so negative numbers should result on a error message being displayed. For each employee entered: Prompt for the hourly rate. The rate must be between $5.25 and $30.00 inclusive, else display an error message. Prompt for the number of hours worked in each of the four weeks of the month. The input should be on the same line separated by spaces. The hours will be entered as whole numbers (integers). The hours worked for any week can be zero, but all four weeks cannot be zero. The hours worked must be between 0 and 60 inclusive. Display a specific error message for each of the three validations. Calculate the gross pay for each week. For the hours between 1 and 40, the employee is paid at their hourly rate. For the hours between 41 and 50, the employee is paid 1.5 times the hourly rate. For the hours between 51 and 60, the employee is paid double time (2.0). The overtime rates must be stored in constant variables such as: RATE1 = 1.0 RATE2 = 1.5 RATE3 = 2.0 If RATE1 is defined, do NOT use it in the formula because multiplying by one gives the same value. Display a detail line for each employee that contains the hourly rate, hours worked, amount earned at each rate, and the gross pay for each week for a total of 4 lines. Display a total line for each employee that contains the total hours, totals at each rate, and total gross pay for the month. See the sample output below. After processing all of the employees, display report totals that include the total hours, totals at each rate, the total gross pay of all employees processed. In addition display the number of employees processed, and the average total gross pay of all of the employees processed. Before dividing for the average, make sure the employee count is not equal to zero. See the sample output below. The detail lines, employee totals, and report totals should all line up under some appropriate column headings. See the sample output below. Requirements: Do not use arrays or functions in this assignment. Submit the source code file, sample output for the three cases and sample output of at least 3 of the error messages displayed by the data validation routines. You will copy and paste text from various screens into one output.txt file. For the prompt "Enter the number of employees to process:", enter a value of 3, and then use the cases listed below to generate the sample output. Cases: Hourly Hours Hours Hours Hours Case # Rate Week1 Week2 Week3 Week4 ------ ----- ----- ----- ----- ----- 1 10.25 35 45 55 30 2 12.50 45 55 40 50 3 15.00 60 39 41 51 Sample Output: P04 - Your Name Enter the number of employees to process. Enter 0 (zero) to exit: 3 P04 - Your Name Employee: 1 Enter the pay rate ($5.25 - $30.00): 10.25 Enter four hours worked separated by a space (0 - 60): 35 45 55 30 Week Rate Hours 1.0 1.5 2.0 Total W1 10.25 35 358.75 0.00 0.00 358.75 W2 10.25 45 410.00 76.88 0.00 486.88 W3 10.25 55 410.00 153.75 102.50 666.25 W4 10.25 30 307.50 0.00 0.00 307.50 Employee Totals 165 1486.25 230.63 102.50 1819.38 Press Enter to process the next employee or the report totals: P04 - Your Name Employee: 2 Enter the pay rate ($5.25 - $30.00): 12.50 Enter four hours worked separated by a space (0 - 60): 45 55 40 50 Week Rate Hours 1.0 1.5 2.0 Total W1 12.50 45 500.00 93.75 0.00 593.75 W2 12.50 55 500.00 187.50 125.00 812.50 W3 12.50 40 500.00 0.00 0.00 500.00 W4 12.50 50 500.00 187.50 0.00 687.50 Employee Totals 190 2000.00 468.75 125.00 2593.75 Press Enter to process the next employee or the report totals: P04 - Your Name Employee: 3 Enter the pay rate ($5.25 - $30.00): 15 Enter four hours worked separated by a space (0 - 60): 60 39 41 51 Week Rate Hours 1.0 1.5 2.0 Total W1 15.00 60 600.00 225.00 300.00 1125.00 W2 15.00 39 585.00 0.00 0.00 585.00 W3 15.00 41 600.00 22.50 0.00 622.50 W4 15.00 51 600.00 225.00 30.00 855.00 Employee Totals 191 2385.00 472.50 330.00 3187.50 Press Enter to process the next employee or the report totals: Report Totals 546 5871.25 1171.88 557.50 7600.63 Number of Employees: 3 Average Gross: 2533.54 Sample Error Messages: P04 - Your Name Enter the number of employees to process. Enter 0 (zero) to exit: -1 Error: The number of employees to process must be 0 or greater. Try again. Enter the number of employees to process. Enter 0 (zero) to exit: 1 P04 - Your Name Employee: 1 Enter the pay rate ($5.25 - $30.00): 45 Error: The pay rate must be between $5.25 and $30.00. Enter the pay rate ($5.25 - $30.00): 4 Error: The pay rate must be between $5.25 and $30.00. Enter the pay rate ($5.25 - $30.00): 10 Enter four hours worked separated by a space (0 - 60): 0 0 0 0 Error: All four hours cannot be zero. Enter four hours worked separated by a space (0 - 60): -10 30 40 70 Error: Negative values are not valid. Error: Values may not exceed 60. Enter four hours worked separated by a space (0 - 60): 40 40 40 40 Pseudocode: void main() { declare constants declare variables (see below) initialize accumulators to zero get empCount (do-while) loopCount = 1; while (loopCount <= empCount) { get rate (do-while) get hours w1, w2, w3, w4 (do-while) calculate pay for 4 weeks (see if-else statements below) sum week totals (cross foot) sum emp totals (columns) accumulate report totals display headings display detail lines (4 weeks) display employee totals display continue prompt loopCount++ } calculate average display report totals display empCount and average return }// end of main Report Layout: Not all required variables are represented in layout. Week Rate Hours 1.0 1.5 2.0 Total W1 rate w1Hours w1Pay1 w1Pay2 w1Pay3 w1Total W2 rate w2Hours w2Pay1 w2Pay2 w2Pay3 w2Total W3 rate w3Hours w3Pay1 w3Pay2 w3Pay3 w3Total W4 rate w4Hours w4Pay1 w4Pay2 w4Pay3 w4Total Employee totals: empHours empPay1 empPay2 empPay3 empTotal Report totals: reportHours reportPay1 reportPay2 reportPay3 reportTotal empCount and average Calculate pay: //Week1 if (w1Hours < 41) { w1Pay1 = w1Hours * rate; w1Pay2 = 0; w1Pay3 = 0; } else { if (w1Hours < 51) { w1Pay1 = 40 * rate; w1Pay2 = (w1Hours - 40) * rate * RATE2; w1Pay3 = 0; } else { w1Pay1 = 40 * rate; w1Pay2 = 10 * rate * RATE2; w1Pay3 = (w1Hours - 50) * rate * RATE3; }//else }//else //Week2 //Week3 //Week4
Revised: 03/01/2011 - www.mesacc.edu/~marquez/cis162ab/p04_monthend_payroll.html