Design a PayRoll class that has data members for an employee’s hourly pay rate, number of hours worked of type double. The default constructor will set the hours worked and pay rate to zero. The class must have a mutator function to set the pay rate for each employee and hours worked. The class should include accessors for both the hours worked and the rate of pay. The class should lastly have a getGross function that will return a double calculated by multiplying the hours worked by the rate of pay. Write a program with an array of seven PayRoll objects. The program should ask the user for the rate of pay for each employee and the number of hours each employee has worked. Be sure to include an employee claiming to work more then 60 hours per week. Print out, the array number of the employee, the hours worked, the rate of pay, and the gross pay, of all the employee's each on their own line. Set the precision for printing the doubles to two decimal places. Input Validation: Do not accept values greater than 60 for the number of hours worked, simply have the set function set number of hours worked to 60, the maximum allowed.
OUTPUT SHOULD BE Creating·7·Payroll·objects.↵ Enter·the·#·0·employee's·rate·of·pay·per·hour:12.22↵ Enter·the·#·0·employee's·hours·worked·for·the·week:22↵ Enter·the·#·1·employee's·rate·of·pay·per·hour:99.99↵ Enter·the·#·1·employee's·hours·worked·for·the·week:36↵ Enter·the·#·2·employee's·rate·of·pay·per·hour:45.67↵ Enter·the·#·2·employee's·hours·worked·for·the·week:20↵ Enter·the·#·3·employee's·rate·of·pay·per·hour:56.78↵ Enter·the·#·3·employee's·hours·worked·for·the·week:0↵ Enter·the·#·4·employee's·rate·of·pay·per·hour:40.45↵ Enter·the·#·4·employee's·hours·worked·for·the·week:5↵ Enter·the·#·5·employee's·rate·of·pay·per·hour:30.35↵ Enter·the·#·5·employee's·hours·worked·for·the·week:80↵ Enter·the·#·6·employee's·rate·of·pay·per·hour:30.33↵ Enter·the·#·6·employee's·hours·worked·for·the·week:45↵ ↵ ↵ Employee·#·0·worked·22.00·hours·at·$12.22·for·a·gross·pay·of·$268.84↵ Employee·#·1·worked·36.00·hours·at·$99.99·for·a·gross·pay·of·$3599.64↵ Employee·#·2·worked·20.00·hours·at·$45.67·for·a·gross·pay·of·$913.40↵ Employee·#·3·worked·0.00·hours·at·$56.78·for·a·gross·pay·of·$0.00↵ Employee·#·4·worked·5.00·hours·at·$40.45·for·a·gross·pay·of·$202.25↵ Employee·#·5·worked·60.00·hours·at·$30.35·for·a·gross·pay·of·$1821.00↵ Employee·#·6·worked·45.00·hours·at·$30.33·for·a·gross·pay·of·$1364.85↵
C++ only please
Screenshot of program code:-
Screenshot of output:-
Program code to copy:-
#include <iostream>
#include <iomanip>
using namespace std;
//PayRoll class
class PayRoll
{
private:
// Private data members
double hourlyPayRate;
double hoursWorked;
public:
// Member functions prototype
PayRoll();
void setHourlyPayRate(double rate);
void setHoursWorked(double hours);
double getHourlyPayRate();
double getHoursWorked();
double getGross();
};
// default constructor sets the hours worked and pay rate to
zero
PayRoll::PayRoll()
{
hourlyPayRate = 0;
hoursWorked = 0;
}
// mutator function to set the pay rate for each employee
void PayRoll::setHourlyPayRate(double rate)
{
hourlyPayRate = rate;
}
// mutator function to set the hours worked for each
employee
void PayRoll::setHoursWorked(double hours)
{
hoursWorked = hours;
}
// accessors function returns the rate of pay
double PayRoll::getHourlyPayRate()
{
return hourlyPayRate;
}
// accessors function returns the hours worked
double PayRoll::getHoursWorked()
{
return hoursWorked;
}
// function returns a gross pay calculated by multiplying the
hours worked by the rate of pay
double PayRoll::getGross()
{
return hourlyPayRate*hoursWorked;
}
int main()
{
// Declare array of seven PayRoll objects
PayRoll payroll[7];
// Declare varible used to hold hours worked and pay
rate
double rate, hours;
cout << "Creating 7 Payroll objects." <<
endl;
for(int i=0; i<7; i++)
{
// prompt & read the rate of
pay from user
cout << "Enter the #"
<< i << " employee's rate of pay per hour: ";
cin >> rate;
// prompt & read the hours
worked from user
cout << "Enter the #"
<< i << " employee's hours worked for the week:
";
cin >> hours;
// set the value of pay rate to
data member of object
payroll[i].setHourlyPayRate(rate);
// set the value of hours worked to
data member of object
if(hours>60)
payroll[i].setHoursWorked(60);
else
payroll[i].setHoursWorked(hours);
}
// Displying the array number of the employee, the
hours worked, the rate of pay, and
// the gross pay, of all the employee's.
cout << fixed << setprecision(2) <<
endl << endl;
for(int i=0; i<7; i++)
{
cout << "Employee #" <<
i << " worked "
<<
payroll[i].getHoursWorked() << " hours at $"
<<
payroll[i].getHourlyPayRate() << " for a gross pay of
$"
<<
payroll[i].getGross() << endl;
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.