C++ Function Call By Reference and By Value Write a program that calculates week
ID: 3758926 • 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<stdio.h>
#include<string.h>
using namespace std;
//This function gets employee information
void getEmployee(string &name, string &id, double &hoursWork, double &ratePerHour)
{
printf("Enter Employee Name: ");
cin>>name;
printf("Enter Employee id: ");
cin>>id;
printf("Enter Employee hoursWork: ");
cin>>hoursWork;
printf("Enter Employee ratePerHour: ");
cin>>ratePerHour;
//return 0;
}
//This function calculates and returns gross pay
double calculateGrossPay(double hoursWork, double ratePerHour)
{
double GrossPay;
if(hoursWork>40)
{
GrossPay=40*ratePerHour+(hoursWork-40)*ratePerHour*1.5;
}
else
{
GrossPay=hoursWork*ratePerHour;
}
return GrossPay;
}
// This function calculates and returns net pay
double calculateNetPay(double grossPay, int taxRate)
{
double NetPay=grossPay*(100-taxRate)/100;
return NetPay;
}
// This function prints name, id, and net pay
void printEmployeePayment(string name, string id, double netpay)
{
printf("Net Payment of Employee name %s and Employee id %s is %f ",name.c_str(),id.c_str(),netpay);
//cout >> " Net Payment of Employee name " + name + " and Employee id " + id + " is " + netpay;
//return 0;
}
int main()
{
string name,id;
char ip='Y';
int i;
double hoursWork,netpay,grossPay,ratePerHour;
int taxRate=5;
do
{
printf("Enter Details ");
getEmployee(name,id,hoursWork,ratePerHour);
grossPay=calculateGrossPay(hoursWork,ratePerHour);
netpay=calculateNetPay(grossPay, taxRate);
printEmployeePayment(name , id , netpay);
printf("Do you want to Enter Another Employee (Enter Y or N) ");
cin>>ip;
}
while(ip=='Y'||ip=='y');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.