Question

C++ Program The Ward Bus Manufacturing Company has recently hired you to help them convert their...

C++ Program

The Ward Bus Manufacturing Company has recently hired you to help them convert their manual payroll system to a computer-based system. Write a program to produce a 1-week payroll report for only one employee to serve as a prototype (model) for the administration to review. Input for the system will be the employee’s 4-digit ID number, the employee’s name, hours worked that week, and the employee’s hourly pay rate. Output should consist of the employee’s ID number, the employee’s name, the hours worked that week, the hourly rate, the gross pay, Federal withholding deduction based on a 16% tax rate, State withholding deduction based on a 6.5% tax rate, and net pay. Use named constants when appropriate.

a. Use main( ) as the driver function. Allow the user to run the program as many times as desired.

b. Write 5 functions that main( ) calls to accomplish the task:

1. getData( ): Prompts the user for an employee’s 4-digit ID #, the employee’s name, the hours worked that week, and hourly pay rate. Criteria for data validation:

a. Employee ID must be an integer between 5000 and 9999, inclusive. Do not allow user to enter an ID number out of this range.

b. Hours worked must be greater than zero and less than 120. Do not allow user to enter the amount of hours worked outside of this range.

c. Hourly Rate must be greater than zero. Do not allow the user to enter a zero or a negative pay rate.

2. computeGrossPay( ): Computes gross pay earned by employee. An employee working more than 40 hours per week is compensated at time-and-a-half for every hour over 40.

3. computeDeductions( ): Computes the Federal and State withholding deductions using the rates listed above.

4. computeNetPay( ): Calculates the net pay for the employee.

5. displayResults( ): Displays the employee’s ID#, the employee’s name, the hours worked, the hourly pay rate, gross pay, Federal withholding amount, State withholding amount, and Net Pay.

Sample Input/Output:

Please enter the employee's 4-digit ID # and press <Enter>

6468

Please enter the employee’s name:

Lisa Hall

Please enter the amount of hours worked this week and press <Enter>

35

Please enter the hourly pay rate for this employee and press <Enter>

10.50

Employee ID: 6468

Employee Name: Lisa Hall

Hours Worked: 35.00 hours

Hourly Rate: $ 10.50

Gross Pay: $ 367.50

Deductions:

Federal Withholding: $ 58.80

State Withholding: $ 23.89

NET PAY: $ 284.81

Would you like to calculate the net pay of another employee? Y or N y

Please enter the employee's 4-digit ID # and press <Enter>

5634

Please enter the employee's name: Lucy Smith

Please enter the amount of hours worked this week and press <Enter>

8978

ERROR: INVALID AMOUNT OF HOURS WORKED!

Please enter the amount of hours worked this week and press <Enter>

4566

ERROR: INVALID AMOUNT OF HOURS WORKED!

Please enter the amount of hours worked this week and press <Enter>

42

Please enter the hourly pay rate for this employee and press <Enter>

-9

ERROR: INVALID Pay Rate!

Please enter the hourly pay rate for this employee and press <Enter>

12.50

Employee: 5634

Employee Name: Lucy Smith

Hours Worked: 42.00 hours

Hourly Rate: $ 12.50

Gross Pay: $ 537.50

Deductions:

Federal Withholding: $ 86.00

State Withholding: $ 34.94

NET PAY: $ 416.56

Would you like to calculate the net pay of another employee? Y or N

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

const int MIN_EMPLOYEE_ID = 5000;
const int MAX_EMPLOYEE_ID = 9999;
const int MAX_HOURS = 120;

// employee’s 4-digit ID number
int employee_id;
// the employee’s name
std::string employee_name;
// hours worked that week
double hours_worked;
// the employee’s hourly pay rate
double hourly_pay_rate;
// calculated net pay
double netPay;

/*
1. getData( ): Prompts the user for an employee’s 4-digit ID #,
the employee’s name, the hours worked that week, and hourly pay rate.
Criteria for data validation
*/
void getData()
{
// character for reading name
char ch;

// loop until correct id is read
do{
    std::cout<<"Please enter the employee's 4-digit ID # and press <Enter>"<<std::endl;
    std::cin>>employee_id;
    if(employee_id >= MIN_EMPLOYEE_ID && employee_id <= MAX_EMPLOYEE_ID)
      break;
    else
      std::cout<<"ERROR: INVALID 4-DIGIT ID!"<<std::endl;
}while(true);

// read name character by character until \n is found
// because C++ cin doesn't read space, it uses space as separator
getchar();
std::cout<<"Please enter the employee’s name:"<<std::endl;
while(true){
    ch = getchar();
    if(ch == '\n')
      break;
    employee_name.push_back(ch);
}

// loop until correct hours is read
do{
    std::cout<<"Please enter the amount of hours worked this week and press <Enter>"<<std::endl;
    std::cin>>hours_worked;
    if(hours_worked > 0 && hours_worked <= MAX_HOURS)
      break;
    else
      std::cout<<"ERROR: INVALID AMOUNT OF HOURS WORKED!"<<std::endl;
}while(true);

// loop until correct pay rate is read
do{
    std::cout<<"Please enter the hourly pay rate for this employee and press <Enter>"<<std::endl;
    std::cin>>hourly_pay_rate;
    if(hourly_pay_rate > 0)
      break;
    else
      std::cout<<"ERROR: INVALID Pay Rate!"<<std::endl;
}while(true);

}

// returns gross pay
// gross pay = hours_worked * pay_rate
double computeGrossPay()
{
return (hours_worked * hourly_pay_rate);
}

// Computes the Federal and State withholding deductions using the rates listed above.
void computeDeductions()
{
// gross pay requires to compute deductions
double grossPay = computeGrossPay();
double federal = (grossPay / 100) * 16;
double state = (grossPay / 100) * 6.5;
// to compute net pay gross-pay, and deductions must need
// so calculating net pay in deductions
// you can copy above lines in computeNetPay() function if don't want to compute here
netPay = grossPay - federal - state;
// display deductions
std::cout<<"Deductions:"<<std::endl;
std::cout<<"Federal Withholding: $ "<<federal<<std::endl;
std::cout<<"State Withholding: $ "<<state<<std::endl;
}

// return computed netpay by function computeDeductions()
double computeNetPay()
{
return netPay;
}

// display each data of employee
void displayResults()
{
std::cout<<"Employee ID: "<<employee_id<<std::endl;
std::cout<<"Employee Name: "<<employee_name<<std::endl;
std::cout<<"Hours Worked: "<<hours_worked<<" hours"<<std::endl;
std::cout<<"Hourly Rate: $ "<<hourly_pay_rate<<std::endl;
std::cout<<"Gross Pay: $ "<<computeGrossPay()<<std::endl;
computeDeductions();
std::cout<<"NET PAY: $ "<<netPay<<std::endl;
}

// main driver program
int main()
{
char choice = 'y';
// loop until choice is y/Y
do{
    // get employee data
    getData();
    // display computed data
    displayResults();
    // if again want to compute then read choice as y/Y
    std::cout<<"Would you like to calculate the net pay of another employee? Y or N: ";
    std::cin>>choice;
    // if choice is y/Y
    if(choice == 'y' || choice == 'Y'){
      // clear out previous computed employee result and continue
      employee_id = 0;
      employee_name.clear();
      hours_worked = 0;
      hourly_pay_rate = 0;
      netPay = 0;
    }else{
      // if choice is anything then exit
      break;
    }
}while(true);

return 0;
}


/*
output:-

~/HomeworkLib$ g++ bus_manufacturing_company.cpp
~/HomeworkLib$ ./a.out
Please enter the employee's 4-digit ID # and press <Enter>
6468
Please enter the employee’s name:
Lisa Hall
Please enter the amount of hours worked this week and press <Enter>
35
Please enter the hourly pay rate for this employee and press <Enter>
10.50
Employee ID: 6468
Employee Name: Lisa Hall
Hours Worked: 35 hours
Hourly Rate: $ 10.5
Gross Pay: $ 367.5
Deductions:
Federal Withholding: $ 58.8
State Withholding: $ 23.8875
NET PAY: $ 284.812
Would you like to calculate the net pay of another employee? Y or N: y
Please enter the employee's 4-digit ID # and press <Enter>
5634
Please enter the employee’s name:
Lucy Smith
Please enter the amount of hours worked this week and press <Enter>
8978
ERROR: INVALID AMOUNT OF HOURS WORKED!
Please enter the amount of hours worked this week and press <Enter>
42
Please enter the hourly pay rate for this employee and press <Enter>
-9
ERROR: INVALID Pay Rate!
Please enter the hourly pay rate for this employee and press <Enter>
12.50
Employee ID: 5634
Employee Name: Lucy Smith
Hours Worked: 42 hours
Hourly Rate: $ 12.5
Gross Pay: $ 525
Deductions:
Federal Withholding: $ 84
State Withholding: $ 34.125
NET PAY: $ 406.875
Would you like to calculate the net pay of another employee? Y or N: n


*/

~/HomeworkLib$ g++ bus_manufacturing_company.cpp -/HomeworkLib$ /a.out Please enter the employees 4-digit ID # and press <Enter> 6468 Pl

Add a comment
Know the answer?
Add Answer to:
C++ Program The Ward Bus Manufacturing Company has recently hired you to help them convert their...
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
  • java Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll...

    java Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: • An empty string is given for the employee’s name. • An invalid value is given for the employee’s ID number. If you implemented this field as a string, then an empty string would be invalid. If you implemented this field as a numeric variable, then a negative number or...

  • You are to write a program that will process employees and their pay. For each employee...

    You are to write a program that will process employees and their pay. For each employee the program will read in an employee’s name and hourly pay rate. It should also read in the number of hours worked each day for 5 days and calculate his or her total number of hours worked. You must read the hours using a loop. The program should output the employee’s name, gross pay, total withholding amount and net pay. Withholding is made up...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • Design a Payroll class with the following fields:

    IN JAVADesign a Payroll class with the following fields:• name: a String containing the employee's name• idNumber: an int representing the employee's ID number• rate: a double containing the employee's hourly pay rate• hours: an int representing the number of hours this employee has workedThe class should also have the following methods:• Constructor: takes the employee's name and ID number as arguments• Accessors: allow access to all of the fields of the Payroll class• Mutators: let the user assign values...

  • C++ Linked Lists You have been hired by Employees. Inc to write an employee management system....

    C++ Linked Lists You have been hired by Employees. Inc to write an employee management system. The following are your specifications: Write a program that uses the following linked lists: bullet empId: a linked list of seven long integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 bullet hours: a linked list of seven integers to hold the number of hours worked by each employee bullet payRate:...

  • Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...

    Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The owners of the Annan Supermarket would like to have a program that computes the weekly gross pay of their employees. The user will enter an employee’s first name, last name, the hourly rate of pay, and the number of hours worked for the week. In addition, Annan Supermarkets would like the program to compute the employee’s net pay and overtime pay. Overtime hours, any...

  • Calculate Payroll Breakin Away Company has three employees-a consultant, a computer programmer, and an administrator. The...

    Calculate Payroll Breakin Away Company has three employees-a consultant, a computer programmer, and an administrator. The following payroll information is available for each employee: Consultant Computer Programmer Administrator Regular earnings rate $2,910 per week $36 per hour $46 per hour Overtime earnings rate Not applicable 1.5 times hourly rate 2 times hourly rate Number of withholding allowances 3 2 1 For the current pay period, the computer programmer worked 60 hours and the administrator worked 50 hours. The federal income...

  • Program is to be written In C++, The output should look like the screen shot. It...

    Program is to be written In C++, The output should look like the screen shot. It should allow the user to continue to ask the user to enter all employee ID's until done and then prompt the user to enter the hours and pay rate for each employee ID. Please help:( Can you please run the program to make sure the output is just like the screenshot please? It needs to have the output that is in the screenshot provided,...

  • Calculate Payroll Breakin Away Company has three employees-a consultant, a computer programmer, and an administrator. The...

    Calculate Payroll Breakin Away Company has three employees-a consultant, a computer programmer, and an administrator. The following payroll information is available for each employee: Consultant Computer Programmer Administrator Regular earnings rate Overtime earnings rate $3,110 per week Not applicable $28 per hour 1.5 times hourly rate $48 per hour 2 times hourly rate Number of withholding allowances For the current pay period, the computer programmer worked 60 hours and the administrator worked 50 hours. The federal income tax withheld for...

  • Breakin Away Company has three employees-a consultant, a computer programmer, and an administrator. The following payroll...

    Breakin Away Company has three employees-a consultant, a computer programmer, and an administrator. The following payroll information is available for each employee: Consultant Computer Programmer Administrator Regular earnings rate $2,110 per week $28 per hour $50 per hour Overtime earnings rate Not applicable 1.5 times hourly rate 2 times hourly rate Number of withholding allowances 3 2 1 For the current pay period, the computer programmer worked 60 hours and the administrator worked 50 hours. The federal income tax withheld...

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
ADVERTISEMENT