Write a C++ program which uses appropriate functions and parameters passing that
ID: 3746094 • Letter: W
Question
Write a C++ program which uses appropriate functions and parameters passing that will perform the following tasks.
Exam 1 Program: You need a program to maintain information about your employees' payroll. Assume that you have the following employees: Name Hours Worked Hourly RateFederal Tax State Tax Rate James, Kobe Bryant, Lebron Jordan, Larry Bird, Michael 42.7 32.65 36.1 55.25 $38.14 $49.35 $44.95 $54.33 Rate 19.2% 20.4% 19.6% 22.7% 75% 8.75% 7.8% 9.25% Write a C++ program which uses appropriate functions and parameter passing that will perform the following tasks Task 1: Allow the user to enter in the data for each employee. (The user will not enter the $ or % symbols.) Task 2: For each employee, calculate the gross pay, the federal tax owed, the state tax owed, and the net pay. The formulas to use are as follows: hours worked hourly rate (overtime hours (hours over 40) should be paid at time and a half) gross pay federal tax owed gross pay *federal tax rate 100 state tax owed gross pay "state tax rate/100 net pay gross pay-federal tax owed-state tax owed Task 3: Print out the name for each employee followed by the results of your four calculations from Task 2 Task 4: Calculate and print the total gross pay, the total federal tax owed, the total state tax owed, and the total net pay for all four of the employees. Task 5: Calculate and print the total of the overtime pay along with the number of employees that worked overtime. (2 employees in the data worked overtime)Explanation / Answer
#include <iostream>
using namespace std;
//Creating a class with name employee
class employee{
//Declaring all variables
char emp_name[20];
float hoursWorked;
float hourlyRate;
float fedTaxRate;
float stateTaxRate;
float grossPay;
float fedTax;
float stateTax;
float netPay;
public:
//These are the functions of class employee
void get_details();
void find_gross_pay();
void find_fed_tax();
void find_state_tax();
void find_net_pay();
void show_emp_details();
};
// Taking details as input from user
void employee :: get_details(){
cout<<" Enter employee name:";
cin>>emp_name;
cout << " Enter number of hours worked:";
cin >> hoursWorked;
cout << " Enter hourly rate:";
cin >> hourlyRate;
cout << " Enter federal tax rate:";
cin >> fedTaxRate;
cout << " Enter state tax rate:";
cin >> stateTaxRate;
cout >> " ------------------------------------ ";
}
//calculating the gross pay
void employee :: find_gross_pay(){
grossPay = hoursWorked*hourlyRate;
}
//calculating the federal tax amount
void employee :: find_fed_tax(){
fedTax = grossPay*(fedTaxRate/100.0);
}
//calculating the state tax amount
void employee :: find_state_tax(){
stateTax = grossPay*(stateTaxRate/100.0);
}
//calculating the net payable amount
void employee :: find_net_pay(){
netPay = grossPay - fedTax - stateTax;
}
//displaying the employee details after calculating
void employee :: show_emp_details(){
cout<<" Pay Details of : "<<emp_name;
cout<<" Gross pay : $ "<<grossPay;
cout<<" Federal Tax : $ "<<fedTax;
cout<<" State Tax : $ "<<stateTax;
cout<<" Net Salary : $ "<<netPay;
cout<<" ";
}
int main(){
//class employee with 10 members
employee emp[10];
int i,num;
cout<<" Enter number of employee details: ";
cin>>num;
//getting details of employee
for(i=0;i<num;i++){
emp[i].get_details();
}
//calculating the gross pay, fed tax, state tax and net pay
for(i=0;i<num;i++){
emp[i].find_gross_pay();
emp[i].find_fed_tax();
emp[i].find_state_tax();
emp[i].find_net_pay();
}
//displaying the results
for(i=0;i<num;i++){
emp[i].show_emp_details();
}
}
Output:
Enter number of employee details : 4
Enter employee name: James
Enter number of hours worked: 42.7
Enter hourly rate: 38.14
Enter federal tax rate: 19.2
Enter state tax rate: 7.5
------------------------------------
Enter employee name: Bryant
Enter number of hours worked: 32.65
Enter hourly rate: 49.35
Enter federal tax rate: 20.4
Enter state tax rate: 8.75
------------------------------------
Enter employee name: Jordan
Enter number of hours worked: 36.1
Enter hourly rate: 44.95
Enter federal tax rate: 19.6
Enter state tax rate: 7.8
------------------------------------
Enter employee name: Bird
Enter number of hours worked: 55.25
Enter hourly rate: 54.33
Enter federal tax rate: 22.7
Enter state tax rate: 9.25
------------------------------------
Pay Details of : James
Gross pay : $ 1628.58
Federal Tax : $ 312.687
State Tax : $ 122.143
Net Salary : $ 1193.75
Pay Details of : Bryant
Gross pay : $ 1611.28
Federal Tax : $ 328.701
State Tax : $ 140.987
Net Salary : $ 1141.59
Pay Details of : Jordan
Gross pay : $ 1622.69
Federal Tax : $ 318.048
State Tax : $ 126.57
Net Salary : $ 1178.08
Pay Details of : Bird
Gross pay : $ 3001.73
Federal Tax : $ 681.393
State Tax : $ 277.66
Net Salary : $ 2042.68
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.