Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program named question6a.cpp that will calculate and print pay slips. Us

ID: 3814026 • Letter: W

Question

Write a program named question6a.cpp that will calculate and print pay slips. User inputs are the name of the employee, the number of hours worked and the hourly pay rate. You have to declare three functions.

a) one for input;

b) one to calculate the employee’s pay; and

c) one to print the payslip.

The input function has to input the name of the employee, the number of hours worked and the hourly pay rate into the variables theEmployee, theHoursWorked and thePayRate. The variable employee is a string and the other two variables are of type float. As the values of theEmployee, theHoursWorked and thePayRate will be changed in this function, reference parameters need to be used. The calculation function will receive two parameters that represent the number of hours worked and the hourly pay rate, do the calculation and return the pay for the employee. An employee, who has worked more than 40 hours, is paid 1.5 times the hourly pay rate for each hour of overtime. As the parameters are not changed in the function, they should be value parameters. The function should return a float value which represents the pay. The output function has to display the name of the employee, the number of hours worked, the number of overtime hours and the hourly pay rate entered by the user as well as the employee’s pay. For example:

Pay slip for Harry Matsipe

Hours worked: 43.5 hours

Overtime hours: 3.5

Hourly pay rate: R125.35

Pay: R5672.09

The main function includes a for loop that allows the user to repeat the calculation of a pay slip for five employees. We give the main function below. You must submit the three functions you have developed as well as output for repeating the loop five times with the following input data:

Harry Matsipe 43.5 125.35

Ellen Malan 39.4 112.75

Joey Rashdien 40 120.45

Mpho Bopape 41.2 123.60

Veli Singh 39.7 135.30

Explanation / Answer

please refer below code

#include<iostream>
#include<string>
#include<sstream>
using namespace std;

void input_parameter(std::string& theEmployee,float& theHoursWorked,float& thePayRate)
{
std::string input_line,s1,s2;
//cout<<"Enter Name,the number of hours worked and hourly Pay rate"<<endl;

std::getline(cin,input_line); //reading input line
std::istringstream iss(input_line); //string separated by space
iss >> s1 >> s2 >> theHoursWorked >> thePayRate;
theEmployee = s1 + " " + s2; //concatenate two strings
}
float calculate_pay(float theHoursWorked,float thePayRate)
{
float pay;

if(theHoursWorked > 40.0)
{
pay = ((theHoursWorked-40.0) * thePayRate * 1.5) + (40.0 * thePayRate);
}
else
pay = theHoursWorked * thePayRate;

return pay;
}
void print_slip(string theEmployee,float theHoursWorked,float thePayRate,float pay)
{
cout<<endl;
cout<<"Pay slip for "<<theEmployee<<endl;
cout<<"Hours worked: "<<theHoursWorked<<" hours"<<endl;
cout<<"Overtime hours: "<<(theHoursWorked-40.0)<<endl;
cout<<"Hourly pay rate: R"<<thePayRate<<endl;
cout<<"Pay: R"<<pay<<endl<<endl;
}
int main()
{
string theEmployee;
float theHoursWorked,thePayRate,pay;

for(int i = 0; i < 5; i++)
{
input_parameter(theEmployee,theHoursWorked,thePayRate);
pay = calculate_pay(theHoursWorked,thePayRate);
print_slip(theEmployee,theHoursWorked,thePayRate,pay);
}
return 0;
}

please refer below output

Harry Matsipe 43.5 125.35

Pay slip for Harry Matsipe
Hours worked: 43.5 hours
Overtime hours: 3.5
Hourly pay rate: R125.35
Pay: R5672.09

Ellen Malan 39.4 112.75

Pay slip for Ellen Malan
Hours worked: 39.4 hours
Overtime hours: -0.599998
Hourly pay rate: R112.75
Pay: R4442.35

Joey Rashdien 40 120.45

Pay slip for Joey Rashdien
Hours worked: 40 hours
Overtime hours: 0
Hourly pay rate: R120.45
Pay: R4818

Mpho Bopape 41.2 123.60

Pay slip for Mpho Bopape
Hours worked: 41.2 hours
Overtime hours: 1.2
Hourly pay rate: R123.6
Pay: R5166.48

Veli Singh 39.7 135.30

Pay slip for Veli Singh
Hours worked: 39.7 hours
Overtime hours: -0.299999
Hourly pay rate: R135.3
Pay: R5371.41


Process returned 0 (0x0) execution time : 81.142 s
Press any key to continue.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote