C++ Function Call By Reference and By Value Write a program that calculates week
ID: 675409 • Letter: C
Question
C++ Function Call By Reference and By Value Write a program that calculates weekly payment. The program will ask the user full name, ID number (make one up), and hours worked. An hourly worker’s gross pay is basically his/her work hours that week multiplied by his/her regular hourly pay rate. However, after the first 40 work hours of the week, each additional work hour is paid at an overtime rate that is 1.5 times of the regular hourly rate. For example if the user’s hourly rate is $15 and worked for 48 hours, the additional 8 hours will be paid at $22.50/hour. Use 5% as tax deduction. The program will calculate and display the net payment. Use loop to allow users to enter multiple employees. Your program should include four functions as shown below: //This function gets employee information void getEmployee(string &name, string &id, double &hoursWork, double &ratePerHour); //This function calculates and returns gross pay double calculateGrossPay(double hoursWork, double ratePerHour); // This function calculates and returns net pay double calculateNetPay(double grossPay, int taxRate); // This function prints name, id, and net pay void printEmployeePayment(string name, string id, double netpay); Your main() should utilize the four functions above by calling them in your program to input, calculate and print the weekly payment
Explanation / Answer
#include <iostream>
#include<string>
using namespace std;
void getEmployee(string &name, string &id, double &hoursWork, double &ratePerHour);
double calculateGrossPay(double hoursWork, double ratePerHour);
void printEmployeePayment(string name, string id, double netpay);
double calculateNetPay(double grossPay, int taxRate);
int main() {
string name;
string id;
double hoursWork;
double ratePerHour;
int taxRate = 5; //tax rate is 5% - change the value as per your requirement
getEmployee(name, id, hoursWork, ratePerHour);
double grossPay = calculateGrossPay(hoursWork, ratePerHour);
double netPay = calculateNetPay(grossPay, taxRate);
printEmployeePayment(name, id, netPay);
//cout << id << ": " << name << ": " << ": " <<hoursWork << ": " << ratePerHour << endl;
return 0;
}
//This function gets employee information
void getEmployee(string &name, string &id, double &hoursWork, double &ratePerHour) {
cout << "Enter Employee ID: ";
cin >> id;
cout << " Enter Name: ";
cin >> name;
cout << " Enter Hours worked: ";
cin >> hoursWork;
cout << " Enter Rate per Hour: ";
cin >> ratePerHour;
}
//This function calculates and returns gross pay
double calculateGrossPay(double hoursWork, double ratePerHour) {
// after the first 40 work hours of the week, each additional work hour is paid at an overtime rate that is 1.5 times of the regular hourly rate
double pay = 0;
if(hoursWork > 40) {
pay = (40 * ratePerHour) + ((hoursWork-40) * 1.5 * ratePerHour);
} else
pay = hoursWork * ratePerHour;
return pay;
}
// This function calculates and returns net pay
double calculateNetPay(double grossPay, int taxRate) {
double tax = (grossPay * taxRate)/100.0;
//deducting tax
return (grossPay - tax);
}
// This function prints name, id, and net pay
void printEmployeePayment(string name, string id, double netpay) {
cout << "Employe ID: " << id << " Name: " << name << " Net Pay: " << ": " <<netpay << endl;
}
---------output---------------------------
Enter Employee ID: 1
Enter Name: John
Enter Hours worked: 41
Enter Rate per Hour: 1
Employe ID: 1 Name: John Net Pay: : 39.425
Enter Employee ID: 40
Enter Name: Kerry
Enter Hours worked: 40
Enter Rate per Hour: 1
Employe ID: 40 Name: Kerry Net Pay: : 38
--
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.