//********************************************************
//
// Assignment 6 - Structures
//
// Name: <Isaac Boahndao>
//
// Class: C Programming, <Spring Semester and 2025>
//
// Date: <03_08_25>
//
// 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
//
//********************************************************
#include <stdio.h> // Standard input-output header
// Define Constants
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5
// Define a structure to hold employee data
struct employee {
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
};
// Function Prototypes
float getHours(long int clockNumber);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay);
void calculateOvertime(struct employee *emp);
void calculateGrossPay(struct employee *emp);
int main() {
// Initialize employee data with clock number and wage rate
struct employee employeeData[SIZE] = {
{98401, 10.60, 0, 0, 0},
{526488, 9.75, 0, 0, 0},
{765349, 10.50, 0, 0, 0},
{34645, 12.25, 0, 0, 0},
{127615, 8.35, 0, 0, 0}
};
int i; // Loop index
// Loop through employees to get hours, calculate overtime & gross pay
for (i = 0; i < SIZE; ++i) {
employeeData[i].hours = getHours(employeeData[i].clockNumber);
calculateOvertime(&employeeData[i]);
calculateGrossPay(&employeeData[i]);
}
// Print the column headers
printHeader();
// Print employee details
for (i = 0; i < SIZE; ++i) {
printEmp(employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours, employeeData[i].overtimeHrs, employeeData[i].grossPay);
}
return 0; // Program executed successfully
}
//**************************************************************
// Function: getHours
// Purpose: Gets user input for hours worked per employee
// Parameters: clockNumber - Unique employee ID
// Returns: hoursWorked - Hours worked in a given week
//**************************************************************
float getHours(long int clockNumber) {
float hoursWorked;
printf("Enter hours worked by emp #%06li: ", clockNumber
); scanf("%f", &hoursWorked
); return hoursWorked;
}
//**************************************************************
// Function: calculateOvertime
// Purpose: Calculates overtime hours worked
// Parameters: emp - Pointer to an employee structure
// Returns: void (modifies structure directly)
//**************************************************************
void calculateOvertime(struct employee *emp) {
if (emp->hours > STD_HOURS) {
emp->overtimeHrs = emp->hours - STD_HOURS;
} else {
emp->overtimeHrs = 0.0;
}
}
//**************************************************************
// Function: calculateGrossPay
// Purpose: Calculates gross pay for an employee
// Parameters: emp - Pointer to an employee structure
// Returns: void (modifies structure directly)
//**************************************************************
void calculateGrossPay(struct employee *emp) {
float regularPay, overtimePay;
if (emp->hours > STD_HOURS) {
regularPay = STD_HOURS * emp->wageRate;
overtimePay = emp->overtimeHrs * emp->wageRate * OT_RATE;
} else {
regularPay = emp->hours * emp->wageRate;
overtimePay = 0.0;
}
emp->grossPay = regularPay + overtimePay;
}
//**************************************************************
// Function: printHeader
// Purpose: Prints the table header
// Parameters: none
// Returns: void
//**************************************************************
void printHeader(void) {
printf("\n*** Pay Calculator ***\n\n"); printf("Clock# Wage Hours OT Gross\n"); printf("----------------------------------\n"); }
//**************************************************************
// Function: printEmp
// Purpose: Prints employee details in a tabular format
// Parameters:
// - clockNumber: Unique employee ID
// - wageRate: Hourly wage rate
// - hours: Hours worked in the week
// - overtimeHrs: Overtime hours worked
// - grossPay: Gross pay for the week
// Returns: void
//**************************************************************
void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay) {
printf("%06li %5.2f %5.1f %4.1f %8.2f\n", clockNumber
, wageRate
, hours
, overtimeHrs
, grossPay
); }