// A program to calculate the salaries for 10 employees using functions and the 'for' loop
// File: ch4prg1.cpp
// The specifications would go here.
#include <iostream.h>
const int REGULAR_HOURS = 40; // Number of hours before overtime kicks in
const double OVERTIME_ADJUSTMENT = 1.5; // Overtime pay adjustment
const int NUM_TIMES = 10; // Number of employees to work with
double GetRateOfPay();
/*
Purpose: To get the rate of pay for an employee from a user
Goal: <rateOfPay>, a double, contains the rate of pay for an employee
Receives: Nothing
Returns <rateOfPay>
*/
void OutputSalary (double salary);
/*
Purpose: To output the salary of an employee
Goal: The screen displays salary
Receives: <salary>, a double
Returns NONE
*/
void main()
// Purpose: to calculate salaries for 10 employees
// Receives: NONE
// Returns: NONE
{
double rateOfPay;
double overtimeRateOfPay;
double regularSalary;
double overtimeSalary;
double fullSalary
double hoursWorked; // can be a fraction of an hour
for (int count = 0; count < NUM_TIMES; count++)
{ rateOfPay = GetRateOfPay();
cout << "Please enter the hours worked this week for this employee";
cin >> hoursWorked;
if (hoursWorked > REGULAR_HOURS)
{ regularSalary = REGULAR_HOURS * rateOfPay;
overtimeRateOfPay = rateOfPay * OVERTIME_ADJUSTMENT;
overtimeSalary = (hoursWorked - REGULAR_HOURS) *
overtimeRateOfPay;
fullSalary = regularSalary + overtimeSalary;
}
else
{ fullSalary = hoursWorked * rateOfPay;
}
OutputSalary(salary);
}
}
double GetRateOfPay()
{ double payRate;
cout << "Please enter an employee's rate of pay (Enter -1 to Stop)";
cin >> payRate;
return payRate;
}
void OutputSalary (double salary)
{ cout << "The employee's salary is: " << salary << endl;
}