// homework 6, problem 1 // Same as hw5, prob 1, but using an array to store the data // This program reads employees data from a file // (using input redirection) and then computes // their pay amounts #include using namespace std; #include const int MAX = 50; const int WEEKHRS = 40; int main() { int i, id, ids[MAX], hrs[MAX], count = 0; double rates[MAX], pay[MAX]; double totalpay = 0., avgpay; cin >> id; while (id != -1) { ids[count] = id; cin >> hrs[count]; cin >> rates[count]; count++; cin >> id; } for (i = 0; i < count ; i++) { if (hrs[i] <= WEEKHRS) pay[i] = rates[i] * hrs[i]; else pay[i] = rates[i] * WEEKHRS + 1.5*rates[i]*(hrs[i] - WEEKHRS); totalpay += pay[i]; } cout << "\n ID #\tPay\n"; cout << " ----\t---\n"; for (i = 0; i < count ; i++) { cout << " " << ids[i] << "\t" << setprecision(2) << setiosflags(ios::fixed) << pay[i] << endl; } avgpay = totalpay / count ; cout << endl; cout << " Total Pay : " << setw(8) << setiosflags(ios::right) << totalpay << endl; cout << "Average Pay : " << setw(8) << setiosflags(ios::right) << avgpay << endl << endl ; return 0; }