c++ Payroll. Write a class name Payroll, with the class declaration in a file ca
ID: 669237 • Letter: C
Question
c++
Payroll. Write a class name Payroll, with the class declaration in a file called Payroll.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 calculate the 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
Edit & Run
Here is the header file.
Here is the implementation.
Program output:
Enter the number of hours worked:
10
Enter the number of hours worked:
20
Enter the number of hours worked:
30
Enter the number of hours worked:
40
Enter the number of hours worked:
50
Enter the number of hours worked:
60
Enter the number of hours worked:
5
Gross pay: 1.65516e-313
Gross pay: 1.65516e-313
Gross pay: 1.65516e-313
Gross pay: 1.65516e-313
Gross pay: 1.65516e-313
Gross pay: 1.65516e-313
Gross pay: 1.65516e-313
Press any key to continue . . .
// This is Payroll main // #include <iostream> #include "Payroll.h" using namespace std; void displaypayroll( Payroll * const); int main() { double Prate, Hwork, Totalp; const int WORKER = 7; int count; // Array of 7 worker's Payroll Payday[WORKER]; // Get worker hours for(count = 0; count < WORKER; ++count) { Prate = 11.11; cout << "Enter the number of hours worked: " << endl; cin >> Hwork; if (Hwork < 0) { cout <<"NO NEGATIVE HOURS ARE ALLOWED "; count--; } if (Hwork > 60) { cout <<"Valid hours are from 0 - 60 "; count--; } Totalp = Prate * Hwork; Payday[count].setRate(Prate); Payday[count].setHours(Hwork); Payday[count].setTpay(Totalp); } for(count = 0; count < WORKER; ++count) { displaypayroll( & Payday[WORKER]); } return 0; } void displaypayroll(Payroll * const x) { cout << "Gross pay: " << x->getTpay() << endl; } Edit & Run
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.