//********************************************************
//
// Assignment 6 - Structures
//
// Name: Timothy Stockton
//
// Class: C Programming, Summer 2025
//
// Date: July 3rd, 2025
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// Functions are 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
// global structure to pass employee data between functions
struct employee
{
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float normalPay;
float overtimePay;
float grossPay;
};
// function prototypes
void getHours (struct employee employeeData[], int theSize);
void calcOvertime (struct employee employeeData[], int theSize,
float overtimeRate, float standardWeek);
void calcGrossPay (struct employee employeeData[], int theSize);
void printHeader (void);
void printEmps (struct employee employeeData[], int theSize);
int main()
{
// Variable Declarations
// array of employee structures, initialized with clockNumber and wageRate
struct employee employeeData[SIZE] = {
{98401, 10.60},
{526488, 9.75},
{765349, 10.50},
{34645, 12.25},
{127615, 8.35}
};
// Read in the hours worked for each employee
getHours (employeeData, SIZE);
// Calculate overtime hours and pay (as well as normal pay)
calcOvertime (employeeData, SIZE, OVERTIME_RATE, STD_WORK_WEEK);
// Calculate gross pay
calcGrossPay (employeeData, SIZE);
// Print the initial table header
printHeader ();
// Function call to output results to the screen
printEmps (employeeData, SIZE);
return (0);
} // main
//***************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee, and stores the results in the referenced array
// of employee structures.
//
// Parameters:
//
// employeeData - Array of employee structures
// theSize - Number of employees to process
//
// Returns: Nothing (call by reference)
//
//**************************************************************
void getHours (struct employee employeeData[], 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: ", employeeData
[i
].
clockNumber); scanf ("%f", &employeeData
[i
].
hours); }
} // 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 the referenced array
// of employee structures.
//
// Parameters:
//
// employeeData - Array of employee structures
// 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 (struct employee employeeData[], 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 (employeeData[i].hours > standardWeek)
{
employeeData[i].overtimeHrs = employeeData[i].hours - standardWeek;
employeeData[i].overtimePay = employeeData[i].overtimeHrs *
(employeeData[i].wageRate * overtimeRate);
employeeData[i].normalPay = standardWeek * employeeData[i].wageRate;
}
else // no OT
{
employeeData[i].overtimeHrs = 0;
employeeData[i].overtimePay = 0;
employeeData[i].normalPay = employeeData[i].hours * employeeData[i].wageRate;
}
} // 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 the referenced array
// of employee structures.
//
// Parameters:
//
// employeeData - Array of employee structures
// theSize - Number of employees to process
//
// Returns: Nothing (call by reference)
//
//**************************************************************
void calcGrossPay (struct employee employeeData[], int theSize)
{
int i; // loop and array index
// Process each employee one at a time
for (i = 0; i < theSize; i++)
{
// Calculate Gross Pay
employeeData[i].grossPay = employeeData[i].normalPay + employeeData[i].overtimePay;
} // 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:
//
// employeeData - Array of employee structures
// theSize - Number of employees to process
//
// Returns: Nothing (call by reference)
//
//**************************************************************
void printEmps (struct employee employeeData[], 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", employeeData[i].clockNumber, employeeData[i].wageRate,
employeeData[i].hours, employeeData[i].overtimeHrs,
employeeData[i].grossPay);
}
} // printEmps