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

Design a PayRoll class that has data members for an employee\'s hourly pay rate

ID: 3694528 • Letter: D

Question

Design a PayRoll class that has data members for an employee's hourly pay rate and number of hours worked. Write a program with an array of seven PayRoll objects. The program should read the number of hours each employee worked and their hourly pay rate from a file and call class functions to store this information in the appropriate objects. It should then call a class function, once for each object, to return the employee's gross pay, so this information can be displayed. Sample data to test this program can be found in the payroll.dat file. Create a file called payroll.dat file that contains the following data.

Explanation / Answer

#include<iostream>
#include <fstream>
using namespace std;
class PayRoll
{
private:
double rate;
double hours;
public:
void setrate(double rate1);
void sethours(double hours1);
double getrate();
double gethours();
double getpay();
};
void PayRoll::setrate(double rate1)
{
rate = rate1;
}
void PayRoll::sethours(double hours1)
{
hours = hours1;
}
double PayRoll::getrate()
{
return rate;
}
double PayRoll::gethours()
{
return hours;
}
double PayRoll::getpay()
{
return hours*rate;
}
int main()
{
PayRoll p1[7];
ifstream infile;
double temp;
infile.open("payroll.dat");
for(int i=0; i<7; i++)
{
infile>>temp;
p1[i].sethours(temp);
infile>>temp;
p1[i].setrate(temp);
cout<<"The total pay for this employee is "<<p1[i].getpay()<<endl;
}
return 0;
}