//********************************************************
//
// Assignment 6 - Structures
//
// Name: <Mario Morkus>
//
// Class: C Programming, <Spring 2026>
//
// Date: <03/08/2026>
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// Call by reference design
//
//********************************************************
// Define and Includes
#include <stdio.h>
// Define Constants
#define SIZE 5 /* number of employees to process */
#define STD_HOURS 40.0 /* standard hours in a normal work week */
#define OT_RATE 1.5 /* overtime pay rate multiplier */
// Define a global structure to pass employee data between functions.
// Note that the structure type is global, but the variable of that
// type is declared locally in main and passed as needed.
struct employee
{
long int clockNumber; /* employee ID number */
float wageRate; /* hourly wage rate */
float hours; /* hours worked in a given week */
float overtimeHrs; /* overtime hours worked in a week */
float grossPay; /* gross pay for the week */
};
// Function prototypes
void getHours (struct employee employeeData[], int theSize);
void calcOT (struct employee employeeData[], int theSize);
void calcGross (struct employee employeeData[], int theSize);
void printHeader (void);
void printEmp (struct employee employeeData[], int theSize);
//**************************************************************
// Function: main
//
// Purpose: Entry point of the program. Initializes an array
// of employee structures with clock numbers and wage rates,
// then calls functions to collect hours, compute overtime
// and gross pay, and display the results in a table.
//
// Parameters: none
//
// Returns: 0 on successful completion
//
//**************************************************************
int main ()
{
// Initialize array of structures with clock numbers and wage rates.
// Hours, overtime, and gross pay default to 0.0.
struct employee employeeData[SIZE] = {
{ 98401, 10.60 },
{ 526488, 9.75 },
{ 765349, 10.50 },
{ 34645, 12.25 },
{ 127615, 8.35 }
};
// Prompt for and store hours worked for each employee
getHours (employeeData, SIZE);
// Calculate overtime hours for each employee
calcOT (employeeData, SIZE);
// Calculate gross pay for each employee
calcGross (employeeData, SIZE);
// Print the column header for the output table
printHeader ();
// Print all employee data in table format
printEmp (employeeData, SIZE);
return (0); /* success */
} /* main */
//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from the user -- the number of hours
// worked per employee -- and stores each result directly
// into the hours member of the corresponding array element.
// The array of structures is passed by reference so the
// calling function sees the updated hours values.
//
// Parameters:
//
// employeeData - array of structures containing employee data
// theSize - number of employees to process
//
// Returns: Nothing (void)
//
//**************************************************************
void getHours (struct employee employeeData[], int theSize)
{
int i; /* loop and array index */
// Prompt for and read hours worked for each employee
for (i = 0; i < theSize; ++i)
{
printf ("\nEnter hours worked by emp # %06li: ", employeeData[i].clockNumber);
scanf ("%f", &employeeData
[i
].
hours); } /* for */
} /* getHours */
//**************************************************************
// Function: calcOT
//
// Purpose: Calculates the overtime hours worked for each
// employee. Any hours beyond STD_HOURS (40.0) are counted
// as overtime. If the employee worked 40 hours or fewer,
// overtime is set to 0.0. Results are stored directly in
// the overtimeHrs member of each array element.
//
// Parameters:
//
// employeeData - array of structures containing employee data
// theSize - number of employees to process
//
// Returns: Nothing (void)
//
//**************************************************************
void calcOT (struct employee employeeData[], int theSize)
{
int i; /* loop and array index */
// Determine overtime hours for each employee
for (i = 0; i < theSize; ++i)
{
// Any hours beyond the standard work week are overtime
if (employeeData[i].hours > STD_HOURS)
{
employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
}
else
{
employeeData[i].overtimeHrs = 0.0; /* no overtime earned */
} /* if */
} /* for */
} /* calcOT */
//**************************************************************
// Function: calcGross
//
// Purpose: Calculates the gross pay for each employee using
// their wage rate, hours worked, and overtime hours.
// Normal pay covers hours up to STD_HOURS at the standard
// wage. Overtime pay covers any extra hours at OT_RATE
// times the standard wage. Results are stored directly in
// the grossPay member of each array element.
//
// Parameters:
//
// employeeData - array of structures containing employee data
// theSize - number of employees to process
//
// Returns: Nothing (void)
//
//**************************************************************
void calcGross (struct employee employeeData[], int theSize)
{
int i; /* loop and array index */
float normalPay; /* pay earned for non-overtime hours */
float overtimePay; /* additional pay earned for overtime hours */
// Calculate gross pay for each employee
for (i = 0; i < theSize; ++i)
{
// Normal pay: standard hours (or fewer) at the regular wage rate
normalPay = (employeeData[i].hours - employeeData[i].overtimeHrs)
* employeeData[i].wageRate;
// Overtime pay: overtime hours at time-and-a-half
overtimePay = employeeData[i].overtimeHrs
* employeeData[i].wageRate
* OT_RATE;
// Gross pay is the sum of normal and overtime pay
employeeData[i].grossPay = normalPay + overtimePay;
} /* for */
} /* calcGross */
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the table title and column header labels
// that appear above the employee data rows.
//
// Parameters: none
//
// Returns: Nothing (void)
//
//**************************************************************
void printHeader (void)
{
printf ("\n\n*** Pay Calculator ***\n");
// Print column labels and separator line
printf ("\n%-8s %-5s %-5s %-5s %-8s\n", "Clock#", "Wage", "Hours", "OT", "Gross");
printf ("--------------------------------------------\n");
} /* printHeader */
//**************************************************************
// Function: printEmp
//
// Purpose: Outputs a single formatted row to the screen for
// each employee showing clock number, wage rate, hours
// worked, overtime hours, and gross pay.
//
// Parameters:
//
// employeeData - array of structures containing employee data
// theSize - number of employees to process
//
// Returns: Nothing (void)
//
//**************************************************************
void printEmp (struct employee employeeData[], int theSize)
{
int i; /* loop and array index */
// Print one row per 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);
} /* for */
} /* printEmp */