C++ Define a PayRoll class that has data members for an employee’s hourly pay ra
ID: 3808633 • Letter: C
Question
C++
Define a PayRoll class that has data members for an employee’s hourly pay rate (an integer , representing cents) and number of hours worked (also an integer ). The class provides two member functions, setRate and setHours that assign the value of their parameter to the appropriate data member. The class provides a third member function, getPay, that returns weekly gross pay (in cents), computed as follows: hours times rate for the first 35 hours plus hours times rate times one and a half for any hours past 35.
Explanation / Answer
Here is the class for you:
// Define a PayRoll class that has data members for an employee’s hourly pay rate
// (an integer , representing cents) and number of hours worked (also an integer ).
class PayRoll
{
int hourlyPayRate;
int workHours;
public:
// The class provides two member functions, setRate and setHours that assign
// the value of their parameter to the appropriate data member.
void setRate(int rate) { hourlyPayRate = rate; }
void setHours(int hours) { workHours = hours; }
// The class provides a third member function, getPay, that returns weekly gross
// pay (in cents), computed as follows:
// hours times rate for the first 35 hours plus hours times rate times
// one and a half for any hours past 35.
double getPay()
{
double pay = workHours * hourlyPayRate;
if(workHours > 35)
pay += 0.5 * hourlyPayRate * (workHours - 35);
return pay;
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.