Payroll Modification

profileSeok123
spc7-8.cpp

// Chapter 7, Programming Challenge 8: Payroll #include <iostream> #include <iomanip> using namespace std; // Constant for the array size. const int ARRAY_SIZE = 7; // Function Prototypes void getEmployeeInfo(long [], int [], double [], double [], int); void displayWages(long [], double [], int); int main() { // Array of employee ID numbers long empId[ARRAY_SIZE] = { 5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489 }; // Array to hold the hours worked for each employee int hours[ARRAY_SIZE]; // Array to hold the hourly pay rate for each employee double payRate[ARRAY_SIZE]; // Array to hold the gross wages for each employee double wages[ARRAY_SIZE]; // Get the employee payroll information and store // it in the arrays. getEmployeeInfo(empId, hours, payRate, wages, ARRAY_SIZE); // Display the payroll information. displayWages(empId, wages, ARRAY_SIZE); return 0; } // ******************************************************** // The getEmployeeInfo function receives four parallel * // arrays as arguments. The 1st array contains employee * // IDs to be displayed in prompts. It asks for input and * // stores hours worked and pay rate information in the * // 2nd and 3rd arrays. This information is used to * // calculate gross pay, which it stores in the 4th array. * // ******************************************************** void getEmployeeInfo(long emp[], int hrs[], double rate[], double pay[], int size) { cout << "Enter the requested information " << "for each employee.\n"; // Get the information for each employee. for (int count = 0; count < size; count++) { cout << "\nEmployee #" << emp[count] << endl; // Get this employee's hours worked. cout << "\tHours worked: "; cin >> hrs[count]; // Validate hours worked. while (hrs < 0) { cout << "Hours worked must be 0 or more. " << "Please re-enter: "; cin >> hrs[count]; } // Get this employee's pay rate. cout << "\tPay rate: $"; cin >> rate[count]; // Validate the pay rate. while (rate[count] < 6.00) { cout << "Pay rate must be 6.00 or more. " << "Please re-enter: $"; cin >> rate[count]; } // Calculate this employee's gross pay. pay[count] = hrs[count] * rate[count]; } } // ******************************************************** // The displayWages function receives 2 parallel arrays. * // The first holds employee IDs and the second holds * // employee gross pay. The function displays this * // information for each employee. * // ******************************************************** void displayWages(long emp[], double pay[], int size) { // Set up the numeric output formatting. cout << fixed << showpoint << setprecision(2) << endl; // Display the header. cout << "----------------------------\n"; cout << "Employee Wages\n"; cout << "----------------------------\n\n"; // Display each employee's pay. for (int count = 0; count < size; count++) { cout << "Employee #" << emp[count] << " $"; cout << setw(7) << pay[count] << endl << endl; } }