-
Notifications
You must be signed in to change notification settings - Fork 0
/
10thQuestion.cpp
50 lines (40 loc) · 1.16 KB
/
10thQuestion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>
using namespace std;
class Payroll {
public:
Payroll(double hourlyRate = 0) : hourlyRate(hourlyRate), numberOfHours(0), totalPay(0) {}
void setHours(int hours) {
numberOfHours = hours;
calculatePay();
}
double getTotalPay() const {
return totalPay;
}
private:
void calculatePay() {
totalPay = hourlyRate * numberOfHours;
}
double hourlyRate;
int numberOfHours;
double totalPay;
};
int main() {
Payroll employees[7] = { Payroll(10), Payroll(12), Payroll(15), Payroll(11), Payroll(13), Payroll(14), Payroll(16) };
for (int i = 0; i < 7; ++i) {
int hours;
cout << "Enter number of hours worked for employee " << (i + 1) << ": ";
cin >> hours;
if (hours > 0 && hours <= 60) {
employees[i].setHours(hours);
}
else {
cout << "Invalid number of hours. Please enter a value between 1 and 60.\n";
i--;
}
}
for (int i = 0; i < 7; ++i) {
cout << "Total pay for employee " << (i + 1) << " is: " << employees[i].getTotalPay() << "\n";
}
return 0;
}