//********************************************************
//
// Assignment 5 - Functions
//
// Name: Rose Samedi
//
// Class: C Programming, Fall 2025
//
// Date: 10/20/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.5
#define STD_WORK_WEEK 40.0
// function prototypes
float getHours (long int clockNumber);
void printHeader (void);
void printEmp (long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
float calculateOvertime(float hours);
float calculateGrossPay(float wageRate, float hours, float overtimeHrs);
int main()
{
/* Variable Declarations */
long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
float grossPay[SIZE]; // gross pay
float hours[SIZE]; // hours worked in a given week
int i; // loop and array index
float overtimeHrs[SIZE]; // overtime hours
float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
// process each employee
for (i = 0; i < SIZE; ++i)
{
// Read in hours for employee
hours[i] = getHours (clockNumber[i]);
// Function call to calculate overtime hours
overtimeHrs[i] = calculateOvertime(hours[i]);
// Function call to calculate gross pay
grossPay[i] = calculateGrossPay(wageRate[i], hours[i], overtimeHrs[i]);
}
// print the header info
printHeader();
// print out each employee
for (i = 0; i < SIZE; ++i)
{
// Print all the employees - call by value
printEmp (clockNumber[i], wageRate[i], hours[i],
overtimeHrs[i], grossPay[i]);
} // for
return (0);
} // main
//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and stores the result
//**************************************************************
float getHours (long int clockNumber)
{
float hours;
printf("Enter hours worked for employee %06ld: ", clockNumber
); return hours;
}
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the header for the employee payroll table
//**************************************************************
void printHeader (void)
{
printf("\n*** Pay Calculator ***\n\n"); printf("Clock #\t| Wage\t| Hours\t| OT\t| Gross\n"); printf("--------|-------|-------|-------|--------\n"); }
//**************************************************************
// Function: printEmp
//
// Purpose: Prints a single line of employee information
//**************************************************************
void printEmp (long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
printf("%06ld\t| %5.2f\t|%5.1f\t|%5.1f\t|%7.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
}
//**************************************************************
// Function: calculateOvertime
//
// Purpose: Calculates overtime hours based on standard work week
//**************************************************************
float calculateOvertime(float hours)
{
if (hours > STD_WORK_WEEK)
{
return hours - STD_WORK_WEEK;
}
else
{
return 0.0f;
}
}
//**************************************************************
// Function: calculateGrossPay
//
// Purpose: Calculates gross pay including overtime wages
//**************************************************************
float calculateGrossPay(float wageRate, float hours, float overtimeHrs)
{
float regularPay;
float overtimePay;
if (overtimeHrs > 0)
{
regularPay = STD_WORK_WEEK * wageRate;
overtimePay = overtimeHrs * (wageRate * OVERTIME_RATE);
return regularPay + overtimePay;
}
else
{
return hours * wageRate;
}
}