//********************************************************
//
// Assignment 6 - Structures
//
// Name: <replace with your name>
//
// Class: C Programming, <replace with Semester and Year>
//
// Date: <replace with the current date>
//
// Description: Program which determines overtime and 
// gross pay for a set of employees with outputs sent 
// to standard output (the screen).
//
// Call by Value design
//
//********************************************************
 
// Define and Includes
 
#include <stdio.h>
 
// Define Constants
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5
 
// Define a global structure to pass employee data between functions
// Note that the structure type is global, but you don't want a variable
// of that type to be global. Best to declare a variable of that type
// in a function like main or another function and pass as needed.
 
struct employee
{
    long int clockNumber;
    float wageRate;
    float hours;
    float overtimeHrs;
    float grossPay;
};
 
// define prototypes here for each function except main
float getHours (long int clockNumber);
float calcOvertimeHrs (float hours);
float calcGrossPay (float wageRate, float hours, float overtimeHrs);
void printHeader (void);
void printEmp (long int clockNumber, float wageRate, float hours,
               float overtimeHrs, float grossPay);
 
int main ()
{
    // Set up a local variable to store the employee information
    struct employee employeeData[SIZE] = {
        { 98401, 10.60 },
        { 526488, 9.75 },
        { 765349, 10.50 }, // initialize clock and wage values
        { 34645, 12.25 },
        { 127615, 8.35 }
    };
 
    int i;  // loop and array index
 
    // Call functions as needed to read and calculate information
    for (i = 0; i < SIZE; ++i) 
    { 
       // Prompt for the number of hours worked by the employee
       employeeData[i].hours = getHours (employeeData[i].clockNumber); 
 
       // Calculate overtime hours
       employeeData[i].overtimeHrs = calcOvertimeHrs(employeeData[i].hours);
 
       // Calculate gross pay
       employeeData[i].grossPay = calcGrossPay(employeeData[i].wageRate, employeeData[i].hours, employeeData[i].overtimeHrs);
    }
 
    // Print the header for the output table
    printHeader();
 
    // Print the employee data
    for (i = 0; i < SIZE; ++i)
    {
        printEmp(employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
                 employeeData[i].overtimeHrs, employeeData[i].grossPay);
    }
 
    return 0;
}
 
// Function Definitions
 
/*******************************************************
 * getHours: Prompts user to input hours worked
 * Input: clockNumber of employee
 * Output: returns hours worked
 *******************************************************/
float getHours (long int clockNumber)
{
    float hours;
    printf("Enter hours worked for clock# %06li: ", clockNumber
);     return hours;
}
 
/*******************************************************
 * calcOvertimeHrs: Calculates overtime hours
 * Input: total hours worked
 * Output: returns overtime hours
 *******************************************************/
float calcOvertimeHrs (float hours)
{
    if (hours > STD_HOURS)
    {
        return hours - STD_HOURS;
    }
    else
    {
        return 0.0;
    }
}
 
/*******************************************************
 * calcGrossPay: Calculates gross pay including overtime
 * Input: wageRate, hours, overtimeHrs
 * Output: returns gross pay
 *******************************************************/
float calcGrossPay (float wageRate, float hours, float overtimeHrs)
{
    float regularPay;
    float overtimePay;
 
    if (overtimeHrs > 0)
    {
        regularPay = STD_HOURS * wageRate;
        overtimePay = overtimeHrs * (wageRate * OT_RATE);
        return regularPay + overtimePay;
    }
    else
    {
        return hours * wageRate;
    }
}
 
/*******************************************************
 * printHeader: Prints the formatted table header
 * Input: None
 * Output: Prints header to standard output
 *******************************************************/
void printHeader (void)
{
    printf("\n*** Pay Calculator ***\n");     printf("--------------------------------------------------\n");     printf("Clock#    Wage     Hours   OT Hours   Gross Pay\n");     printf("--------------------------------------------------\n"); }
 
/*******************************************************
 * printEmp: Prints one line of employee data
 * Input: clockNumber, wageRate, hours, overtimeHrs, grossPay
 * Output: Prints formatted employee data to standard output
 *******************************************************/
void printEmp (long int clockNumber, float wageRate, float hours,
               float overtimeHrs, float grossPay)
{
    printf("%06li  $%6.2f  %5.1f   %8.1f   $%8.2f\n",            clockNumber, wageRate, hours, overtimeHrs, grossPay);
}