// FILE: Payroll.cpp // COMPUTES AND PRINTS GROSS PAY AND NET PAY GIVEN AN HOURLY // RATE AND NUMBER OF HOURS WORKED. DEDUCTS UNION DUES OF $15 // IF GROSS SALARY EXCEEDS $100; OTHERWISE, DEDUCTS NO DUES. #include // needed for cin and cout #include "money.h" // needed for money data type // Functions used ... // DISPLAYS USER INSTRUCTIONS void instruct_user (const money, // IN: max earnings (dollars) before paying Union dues const money, // IN: Union dues (dollars) const double, // IN: max number of hours without overtime pay const double); // IN: overtime rate // FIND THE GROSS SALARY money compute_gross (double, // IN: number of hours worked money, // IN: hourly pay rate (dollars) const double, // IN: max number of hours without overtime pay const double); // IN: overtime rate // FIND THE NET SALARY money compute_net (money, // IN: gross pay (dollars) const money, // IN: max earnings (dollars) before paying Union dues const money); // IN: Union dues (dollars) int main () { // Local data ... const money max_no_dues = 100.00; // max earnings before dues (dollars) const money dues = 15.00; // dues amount (dollars) const double max_no_overtime = 40.0; // max hours before overtime const double overtime_rate = 1.5; // overtime rate double hours; // input: hours worked double rate; // input: hourly pay rate (dollars) money gross; // output: gross pay (dollars) money net; // output: net pay (dollars) // Display user instructions. instruct_user (max_no_dues, dues, max_no_overtime, overtime_rate); // Enter hours and rate. cout << "Hours worked: "; cin >> hours; cout << "Hourly rate: "; cin >> rate; // Compute gross salary. gross = compute_gross (hours, rate, max_no_overtime, overtime_rate); // Compute net salary. net = compute_net (gross, max_no_dues, dues); // Print gross and net. cout << "Gross salary is " << gross << endl; cout << "Net salary is " << net << endl; return 0; } // DISPLAYS USER INSTRUCTIONS void instruct_user (const money max_no_dues, // IN: max earnings (dollars) before paying dues const money dues, // IN: dues amount (dollars) const double max_no_overtime, // IN: max number of hours without overtime pay const double overtime_rate) // IN: overtime rate { cout << "This program computes gross and net salary." << endl; cout << "A dues amount of " << dues << " is deducted for" << endl; cout << "an employee who earns more than " << max_no_dues << endl << endl; cout << "Overtime is paid at the rate of " << overtime_rate << endl; cout << "times the regular rate for hours worked over " << max_no_overtime << endl << endl; cout << "Enter hours worked and hourly rate" << endl; cout << "on separate lines after the prompts." << endl; cout << "Press after typing each number." << endl << endl; } // end instruct_user // FIND THE GROSS SALARY money compute_gross (double hours, // IN: number of hours worked money rate, // IN: hourly pay rate (dollars) const double max_no_overtime, // IN: max number of hours without overtime pay const double overtime_rate) // IN: overtime rate { // Local data ... money gross; // RESULT: gross pay (dollars) money regular_pay; // pay for first 40 hours money overtime_pay; // pay for hours in excess of 40 // Compute gross pay. if (hours > max_no_overtime) { regular_pay = max_no_overtime * rate; overtime_pay = (hours - max_no_overtime) * overtime_rate * rate; gross = regular_pay + overtime_pay; } else gross = hours * rate; return gross; } // end compute_gross // FIND THE NET SALARY money compute_net (money gross, // IN: gross salary (dollars) const money max_no_dues, // IN: max salary for no deduction (dollars) const money dues) // IN: dues amount (dollars) { // Local data ... money net; // RESULT: net pay (dollars) // Compute net pay. if (gross > max_no_dues) net = gross - dues; // deduct dues amount else net = gross; return net; } // end compute_net