1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
// This program uses an array of structures to hold payroll data. #include <iostream> #include <iomanip> using namespace std; class PayInfo { private: int hours; // Hours worked double payRate; // Hourly pay rate double grossPay; public: PayInfo() { hours = 0; payRate = 0; grossPay = 0; } void PayInfo::setHours(int hr) { hours = hr; } void PayInfo::setpayRate(double pr) { payRate = pr; } int PayInfo::getHours() { return hours; } double PayInfo::getPayRate() { return payRate; } double PayInfo::getGrossPay() { if (hours > 40) { grossPay = (payRate * 40 + (1.5 * payRate * (hours - 40))); } else grossPay = payRate * hours; return grossPay; } }; int main() { int hr; double pr; double grossPay; const int NUM_EMPS = 3; PayInfo workers[NUM_EMPS]; cout << "Enter the hours worked and hourly pay rates of " << NUM_EMPS << " employees. \n"; for (int index = 0; index < NUM_EMPS; index++) { cout << "\nHours worked by employee #" << (index + 1) << ": "; cin >> hr; workers[NUM_EMPS].setHours(hr); cout << "Hourly pay rate for this employee: $"; cin >> pr; workers[NUM_EMPS].setpayRate(pr); } cout << "\nHere is the gross pay for each employee:\n"; cout << fixed << showpoint << setprecision(2); for (int index = 0; index < NUM_EMPS; index++) { hr =workers[NUM_EMPS].getHours(); pr = workers[NUM_EMPS].getPayRate(); grossPay = workers[NUM_EMPS].getGrossPay(); grossPay = hr * pr; //workers[NUM_EMPS].getGrossPay(); cout << "Employee #" << (index + 1); cout << ": $" << setw(7) << workers[NUM_EMPS].getGrossPay() << endl; } return 0; }