Problem) ( In c plus plus language) 1) Design a PayRoll class that has data memb
ID: 3730751 • Letter: P
Question
Problem)
( In c plus plus language)
1) Design a PayRoll class that has data members for an employee’s hourly pay rate and number of hours worked.
2) Write a program with an array of eleven PayRoll objects.
3) The program should read the number of hours each employee worked and their hourly pay rate (before tax) from a file and call class function to store this information in the appropriate objects.
4) It should then call class function, once for each object, to return the employee’s net pay after 20% tax deduction, so this information can be displayed.
Explanation / Answer
#include <iostream>
using namespace std;
class PayRoll {
public:
double hours;
double rate;
PayRoll() {
}
PayRoll(double h, double r) {
hours = h;
rate = r;
}
};
int main() {
// creating object
PayRoll arr[11];
double h, r;
cout<<"Enter the details of 11 employee: "<<endl;;
for(int i=0; i<11; i++) {
cout<<"Enter hours worked for employee "<<(i+1)<<": ";
cin>>h;
cout<<"Enter pay rate for employee "<<(i+1)<<": ";
cin>>r;
arr[i].hours = h;
arr[i].rate = r;
}
// displaying pay
for(int i=0; i<11; i++) {
double pay = arr[i].hours*arr[i].rate;
pay = pay - pay*0.2;
cout<<"Pay of employee "<<(i+1)<<": "<<pay<<endl;;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.