header
//*********************************************************
// GrossPay2.cpp
//
// Calculate and display the gross pay given the hourly
// wage and the number of hours worked.
//
// D. Searls
// Asbury College
// Aug 2003
//*********************************************************

#include <iostream>
#include <iomanip>

using namespace std;

const double MAXHOURS = 40.0;
const double OT_MULTIPLIER = 1.5;

double regularPay(double hours, double rate);
double overtimePay(double hours, double rate);
double grossPay(double hours, double rate);

int main()
{
    string empID;
    double hoursWorked;
    double hourlyWage;

    // Get Employee Data

    cout << "Enter employee ID: ";
    cin >> empID;
    cout << "Enter hourly wage: ";
    cin >> hourlyWage;
    cout << "Enter hours worked: ";
    cin >> hoursWorked;
    cout << endl << endl;
    
    // Display Employee ID and gross pay

    cout << fixed << setprecision(2);
    cout << setw(10) << left << "Emp ID";
    cout << setw(7)  << right << "Hours";
    cout << setw(7)  << "Wage";
    cout << setw(10) << "Regular";
    cout << setw(10) << "Overtime";
    cout << setw(10) << "Gross" << endl;
    
    cout << "----------  -----  -----  --------  --------  --------" << endl;
    
    cout << setw(10) << left << empID;
    cout << setw(7)  << right << hoursWorked;
    cout << setw(7)  << hourlyWage;
    cout << setw(10) << regularPay(hoursWorked, hourlyWage);
    cout << setw(10) << overtimePay(hoursWorked, hourlyWage);
    cout << setw(10) << grossPay(hoursWorked, hourlyWage);
    cout << endl << endl;

    return 0;
}

//-----------------------------------------------
// regularPay
//
// Preconditions: hours >= 0, rate >= 0
//
// Given the hours worked and the hourly rate of
// pay, the worker's regular pay for the week is
// calculated and returned.
//
// In Parameters: hours, rate
//-----------------------------------------------
double regularPay(double hours, double rate)
{
    double regPay;
    
    if (hours <= MAXHOURS)
    {
        regPay = hours * rate;
    }
    else
    {
        regPay = MAXHOURS * rate;
    }
    
    return regPay;
}

//-----------------------------------------------
// overtimePay
//
// Preconditions: hours >= 0, rate >= 0
//
// Given the hours worked and the hourly rate of
// pay, the worker's overtime pay for the week is
// calculated and returned.
//
// In Parameters: hours, rate
//-----------------------------------------------
double overtimePay(double hours, double rate)
{
    double otPay;
    
    if (hours <= MAXHOURS)
    {
        otPay = 0.0;
    }
    else
    {
        otPay = (hours - MAXHOURS) * OT_MULTIPLIER * rate;
    }
    
    return otPay;
}

//-----------------------------------------------
// grossPay
//
// Preconditions: hours >= 0, rate >= 0
//
// Given the hours worked and the hourly rate of
// pay, the worker's gross pay for the week is
// calculated and returned.
//
// In Parameters: hours, rate
//-----------------------------------------------
double grossPay(double hours, double rate)
{
    return regularPay(hours, rate) + overtimePay(hours, rate);
}