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

This is a C++ Question and I have asked this question before but got the same an

ID: 3771477 • Letter: T

Question

This is a C++ Question and I have asked this question before but got the same answer that is already on here (CHEGG) Original work would be appreciated since I pay for this service.

This has been asked before but it timed out when the user enters a negative value for the hours worked. Please help me by writing a good code that is different from the one that is already here on Chegg.

Payroll. Write a class name Payroll, with the class declaration in a file calledPayroll.h and the implementation in a file called Payroll.cpp.

The class will have data members for an employee’s hourly pay rate, number of hours worked and total pay for the week. All of the data members will be doubles. The class only needs one constructor which can be a default constructor that sets all data members to zero. Then add the mutators and accessor for the class.

The program will have an array of 7 Payroll objects. The program will prompt the user for number of hours each employee has worked and will then display the amount of gross pay each has earned.

Before asking the user for the hours, the program should set the pay rate for each employee without user input. Validation: Do not accept values greater than 60 for the number of hours worked.

Explanation / Answer

/*
* Payroll.cpp
*
* Created on: 13-Dec-2015
*      Author: Ravi
*/

#include "Payroll.h"

#include <iostream>
#include <string>

using namespace std;

Payroll::Payroll() {
   // TODO Auto-generated constructor stub
   payRate = 0;
   hoursWorkd = 0;
   totalpay = 0;

}

Payroll::~Payroll() {
   // TODO Auto-generated destructor stub
}

double Payroll::getHourlyPayRate() {
       return payRate;
   }

void Payroll:: setHourlyPayRate(double hpayRate) {
       payRate = hpayRate;
   }


double Payroll::getNoOfHoursWorked() {
   return hoursWorkd;
}
void Payroll:: setNoOfHoursWorked(double nhoursWorkd) {
   hoursWorkd = nhoursWorkd;
}

double Payroll:: getTotalPayPerWeek() {
   return hoursWorkd * payRate;
}
void Payroll:: setTotalPayPerWeek(double ntotalpay) {
   totalpay = ntotalpay;
}

int main() {
   Payroll emps[7];
   double hoursworked = -1;
   for(int i = 0; i < 7; i++) {
       hoursworked = -1;
       emps[i] = Payroll();
       //setting hourly pay rate
       emps[i].setHourlyPayRate( (i+1) * 1.5);

       while(hoursworked < 0) {
           cout << "Employee#" << (i+1) <<": Enter no of hours worked : " <<endl;
           cin >>hoursworked;
       }

       emps[i].setNoOfHoursWorked(hoursworked);

   }
   for(int i = 0; i < 7; i++)
   cout << " Emp#" << (i+1) << " Hourly pay Rate : " << emps[i].getHourlyPayRate() << " No of hours worked : " << emps[i].getNoOfHoursWorked()
                   << " Total pay per week: " << emps[i].getTotalPayPerWeek() << endl;
   return 0;
}

----output---------

Employee#1: Enter no of hours worked :
10
Employee#2: Enter no of hours worked :
20
Employee#3: Enter no of hours worked :
30
Employee#4: Enter no of hours worked :
40
Employee#5: Enter no of hours worked :
10
Employee#6: Enter no of hours worked :
20
Employee#7: Enter no of hours worked :
30
Emp#1 Hourly pay Rate : 1.5 No of hours worked : 10 Total pay per week: 15
Emp#2 Hourly pay Rate : 3 No of hours worked : 20 Total pay per week: 60
Emp#3 Hourly pay Rate : 4.5 No of hours worked : 30 Total pay per week: 135
Emp#4 Hourly pay Rate : 6 No of hours worked : 40 Total pay per week: 240
Emp#5 Hourly pay Rate : 7.5 No of hours worked : 10 Total pay per week: 75
Emp#6 Hourly pay Rate : 9 No of hours worked : 20 Total pay per week: 180
Emp#7 Hourly pay Rate : 10.5 No of hours worked : 30 Total pay per week: 315

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote