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

Please write the answer for this in C++. Also, please write this in an organize

ID: 3920780 • Letter: P

Question

Please write the answer for this in C++. Also, please write this in an organize way. Thank You!

Question 21 10 pts (CO 1) Write an Employee class that has data members for hourly pay rate and number of hours worked. The default constructor should set the hours worked and pay rate to zero. The class must have an accessor method for both the hours worked and rate of pay. The class must have mutator method for both the hours worked and rate of pay. Finally, the class should have a calculatePay method that returns the weekly pay based on the hours worked times the hourly pay rate.

Explanation / Answer

PROGRAM

#include<iostream>

using namespace std;

class Employee

{

private: double hpay;

int hours;

public: Employee() // default constructor

{

// initially set 0

hpay=0.0;

hours=0;

}

// accessor methods

double getPay();

int getHours();

// mutator methods

void setPay(double hpay);

void setHours(int hours);

// calculate payment in week

double calculatePay(int days);

  

};

// implement mutator method setPay()

void Employee::setPay(double hpay)

{

this->hpay=hpay; // assign hpay value

}

// implement mutator mehtod setHours()

void Employee::setHours(int hours)

{

this->hours=hours; // assign hours

}

// implement accessor method getPay()

double Employee::getPay()

{

return hpay; // return hpay value

}

// implement accessor method getHours()

int Employee::getHours()

{

return hours; // return hours value

}

// implement calculatePay() method with 7 days

double Employee::calculatePay(int days)

{

double total; // declare double variable total

if(days==7) // check condition 7 days in week

{

total=hpay*hours; // calculate total payment

}

return total; // return total payment

}

int main()

{

Employee emp; // create emp Object of Employee

emp.setPay(50.54); // set payment per hour

emp.setHours(350); // set total hours in week

cout<<" Hourly Payment: "<<emp.getPay()<<endl; // display hourly payment

cout<<" Total Hours in week: "<<emp.getHours()<<endl; // display total hours in week

double tot=emp.calculatePay(7); // calling calculatePay() method and set 7 days in week

cout<<" Total Weekly Payment: "<<tot<<endl; // display total payment in week

return 0;

}

OUTPUT


Hourly Payment: 50.54

Total Hours in week: 350

Total Weekly Payment: 17689