//********************************************************
//
// Assignment 5 - Functions
//
// Name: Fisher Brown
//
// Class: C Programming, Spring 2025
//
// Date: March 2, 2025
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// All functions are called by value
//
//********************************************************
#include <stdio.h>
// constants
#define SIZE 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f
// function prototypes
float getHours(long int clockNumber);
float calcOvertime(float hoursWorked);
float calcGross(float wageRate, float hoursWorked, float overtimeHours);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
int main()
{
/* Variable Declarations */
long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615}; // array of employee IDs
float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35}; // array of employee wage rates
float hours[SIZE]; // array of hours worked for each employee
float overtimeHrs[SIZE]; // array of overtime hours for each employee
float grossPay[SIZE]; // array of gross pay for each employee
int i; // loop counter
// process each employee
for (i = 0; i < SIZE; ++i)
{
// Read in hours for employee
hours[i] = getHours(clockNumber[i]);
// Calculate overtime hours
overtimeHrs[i] = calcOvertime(hours[i]);
// Calculate gross pay
grossPay[i] = calcGross(wageRate[i], hours[i], overtimeHrs[i]);
}
// print the header info
printHeader();
// print out each employee's information
for (i = 0; i < SIZE; ++i)
{
printEmp(clockNumber[i], wageRate[i], hours[i],
overtimeHrs[i], grossPay[i]);
}
return (0);
} // main
//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and stores the result in a local variable
// that is passed back to the calling function.
//
// Parameters: clockNumber - The unique employee ID
//
// Returns: hoursWorked - hours worked in a given week
//
//**************************************************************
float getHours(long int clockNumber)
{
float hoursWorked; // local variable to store hours worked in a week
// Prompt and read hours worked for the employee
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
);
return hoursWorked;
} // getHours
//**************************************************************
// Function: calcOvertime
//
// Purpose: Calculates the overtime hours worked.
//
// Parameters:
// hoursWorked - total hours worked by employee
//
// Returns: overtimeHours - hours over 40 worked
//**************************************************************
float calcOvertime(float hoursWorked)
{
float overtimeHours; // local variable to store calculated overtime hours
if (hoursWorked > STD_WORK_WEEK)
overtimeHours = hoursWorked - STD_WORK_WEEK;
else
overtimeHours = 0.0f;
return overtimeHours;
} // calcOvertime
//**************************************************************
// Function: calcGross
//
// Purpose: Calculates the gross pay for an employee.
//
// Parameters:
// wageRate - hourly wage
// hoursWorked - total hours worked
// overtimeHours - hours over 40 worked
//
// Returns: grossPay - total pay for the week
//**************************************************************
float calcGross(float wageRate, float hoursWorked, float overtimeHours)
{
float regularHours; // local variable to store regular (non-overtime) hours
float grossPay; // local variable to store calculated gross pay
regularHours = hoursWorked - overtimeHours;
grossPay = (regularHours * wageRate) + (overtimeHours * wageRate * OVERTIME_RATE);
return grossPay;
} // calcGross
//**************************************************************
// 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: printEmp
//
// Purpose: Prints out all the information for an employee
// in a nice and orderly table format.
//
// Parameters:
//
// clockNumber - unique employee ID
// wageRate - hourly wage rate
// hours - Hours worked for the week
// overtimeHrs - overtime hours worked in a week
// grossPay - gross pay for the week
//
// Returns: void
//
//**************************************************************
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
// print the employee's information
printf("%06li %6.2f %6.1f %6.1f %9.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
} // printEmp