//********************************************************
//
// Assignment 5 - Functions
//
// Name: Timothy Stockton
//
// Class: C Programming, Summer 2025
//
// Date: June 25th, 2025
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// All functions called by reference
//
//********************************************************
#include <stdio.h>
// constants
#define SIZE 5 // number of employees to process
#define OVERTIME_RATE 1.5f // time and half overtime setting
#define STD_WORK_WEEK 40.0f // normal work week hours before overtime
// function prototypes
void getHours (long int clockNumber[], float hours[], int theSize);
void calcOvertime (float wageRate[], float hours[], float overtimeHrs[],
float overtimePay[], float normalPay[], int theSize,
float overtimeRate, float standardWeek);
void calcGrossPay (float overtimePay[], float normalPay[], float grossPay[],
int theSize);
void printHeader (void);
void printEmps (long int clockNumber[], float wageRate[], float hours[],
float overtimeHrs[], float grossPay[], int theSize);
int main()
{
// Variable Declarations
long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
float grossPay[SIZE]; // gross pay, holds calculated totals
float hours[SIZE]; // hours worked in a given week
float normalPay[SIZE]; // normal pay
float overtimeHrs[SIZE]; // overtime hours
float overtimePay[SIZE]; // overtime pay
float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
// Read in the hours worked for each employee
getHours (clockNumber, hours, SIZE);
// Calculate overtime hours and pay (as well as normal pay)
calcOvertime (wageRate, hours, overtimeHrs, overtimePay, normalPay,
SIZE, OVERTIME_RATE, STD_WORK_WEEK);
// Calculate gross pay
calcGrossPay (overtimePay, normalPay, grossPay, SIZE);
// Print the initial table header
printHeader ();
// Function call to output results to the screen
printEmps (clockNumber, wageRate, hours,
overtimeHrs, grossPay, SIZE);
return (0);
} // main
//***************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee, and stores the results in an array that is
// passed back to the calling function by reference.
//
// Parameters:
//
// clockNumber - Array of employee clock numbers for each employee
// hours - Array of hours worked by each employee
// theSize - Number of employees to process
//
// Returns: Nothing (call by reference)
//
//**************************************************************
void getHours (long int clockNumber[], float hours[], int theSize)
{
int i; // loop and array index
// Read in hours for each employee
for (i= 0; i < theSize; ++i)
{
printf("\nEnter hours worked by emp # %06li: ", clockNumber
[i
]); }
} // getHours
//***************************************************************
// Function: calcOvertime
//
// Purpose: Calculates the normal pay and overtime pay of all employees
// based on the hours worked, wage rate, overtime rate, and standard
// week hours. Stores the results in an array that is
// passed back to the calling function by reference.
//
// Parameters:
//
// wageRate - Array of wages for each employee
// hours - Array of hours worked by each employee
// overtimeHrs - Array of overtime hours worked by each employee
// overtimePay - Array of overtime pay for each employee
// normalPay - Array of normal pay for each employee
// theSize - Number of employees to process
// overtimeRate - The multiplier to wages for overtime hours
// standardWeek - Number of hours in a standard work week, no overtime
//
// Returns: Nothing (call by reference)
//
//**************************************************************
void calcOvertime (float wageRate[], float hours[], float overtimeHrs[],
float overtimePay[], float normalPay[], int theSize,
float overtimeRate, float standardWeek)
{
int i; // loop and array index
// Process each employee one at a time
for (i = 0; i < theSize; i++)
{
// Calculate overtime and gross pay for employee
if (hours[i] > standardWeek)
{
overtimeHrs[i] = hours[i] - standardWeek;
overtimePay[i] = overtimeHrs[i] * (wageRate[i] * overtimeRate);
normalPay[i] = standardWeek * wageRate[i];
}
else // no OT
{
overtimeHrs[i] = 0;
overtimePay[i] = 0;
normalPay[i] = hours[i] * wageRate[i];
}
} // end for
} // calcOvertime
//***************************************************************
// Function: calcGrossPay
//
// Purpose: Calculates the gross pay fr each employee, the total pay for the week
// including normal and overtime pay. Stores the results in an array that is
// passed back to the calling function by reference.
//
// Parameters:
//
// overtimePay - Array of overtime pay for each employee
// normalPay - Array of normal pay for each employee
// grossPay - Array of combined gross pay for each employee
// theSize - Number of employees to process
//
// Returns: Nothing (call by reference)
//
//**************************************************************
void calcGrossPay (float overtimePay[], float normalPay[],
float grossPay[], int theSize)
{
int i; // loop and array index
// Process each employee one at a time
for (i = 0; i < theSize; i++)
{
// Calculate Gross Pay
grossPay[i] = normalPay[i] + overtimePay[i];
} // end for
} // calcGrossPay
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printHeader (void)
{
printf ("\n\n*** Pay Calculator ***\n");
// print the table header
printf("\nClock# Wage Hours OT Gross\n"); printf("------------------------------------------------\n");
} // printHeader
//**************************************************************
// Function: printEmps
//
// Purpose: Prints out all the employee information in a
// nice and orderly table format.
//
// Parameters:
//
// clockNumber - Array of employee clock numbers
// wageRate - Array of employee wages per hour
// hours - Array of number of hours worked by an employee
// overtimeHrs - Array of overtime hours for each employee
// grossPay - Array of gross pay calculations for each employee
// theSize - Number of employees to process
//
// Returns: Nothing (call by reference)
//
//**************************************************************
void printEmps (long int clockNumber[], float wageRate[], float hours[],
float overtimeHrs[], float grossPay[], int theSize)
{
int i; // loop and array index
// access and print each employee
for (i = 0; i < theSize; ++i)
{
printf("%06li %5.2f %5.1f %5.1f %8.2f\n", clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
}
} // printEmps