Write a C++ program to calculate the pay for an employee. The program inputs the
ID: 3846310 • Letter: W
Question
Write a C++ program to calculate the pay for an employee. The program inputs the pay rate and the number of hours worked from the user. The program echoes the input information and outputs the calculated pay. Include a void function, called GetData, which takes two arguments and inputs the pay rate and the number of hours worked. Include another value returned function, called CalcPay, which takes two arguments and returns the total pay for that employee. Include a final void function, called PrintPay, which takes three arguments and outputs the input information and the calculated total pay. The sample output for the program should looks like the following:Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class Employee
{
public:
double payRate;
double noOfHours;
void GetData(double rate,double hours)
{
CalcPay(rate,hours);
}
void CalcPay(double rate,double hours)
{
double totalPay=rate*hours;
PrintPay(rate,hours,totalPay);
}
void PrintPay(double rate,double hours,double totalPay)
{
cout<<"For an employee who worked with " <<hours<< " hours with a pay rate $" << rate << " per hour";
cout<<" The total pay is "<< totalPay;
}
};
int main()
{
double payRate;
double noOfHours;
int choice;
Employee obj;
do
{
cout<<" Please Enter rate per hour ";
cin>>payRate;
cout<<" Please Enter hours worked ";
cin>>noOfHours;
obj.GetData(payRate,noOfHours);
cout<<" Press any key to continue ... ";
cin>>choice;
}while(choice!=-1);
}
Output:
Please Enter rate per hour 15.66
Please Enter hours worked 200.5
For an employee who worked with 200.5 hours with a pay rate $15.66 per hour
The total pay is 3139.83
Press any key to continue ...3
Please Enter rate per hour 20.5
Please Enter hours worked 200
For an employee who worked with 200 hours with a pay rate $20.5 per hour
The total pay is 4100
Press any key to continue ...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.