//********************************************************
//
// Assignment 6 - Structures
//
// Name: <Amir Gharouadi>
//
// 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 Value design
//
//********************************************************
#include <stdio.h>
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5
struct employee
{
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
};
/* function prototypes */
float getHours(long int clockNumber);
float calcOvertime(float hours);
float calcGross(float wageRate, float hours, float overtimeHrs);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
int main(void)
{
struct employee employeeData[SIZE] = {
{98401, 10.60, 0.0, 0.0, 0.0},
{526488, 9.75, 0.0, 0.0, 0.0},
{765349, 10.50, 0.0, 0.0, 0.0},
{34645, 12.25, 0.0, 0.0, 0.0},
{127615, 8.35, 0.0, 0.0, 0.0}
};
int i;
for (i = 0; i < SIZE; i++)
{
employeeData[i].hours = getHours(employeeData[i].clockNumber);
employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
employeeData[i].grossPay = calcGross(employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs);
}
printHeader();
for (i = 0; i < SIZE; i++)
{
printEmp(employeeData[i].clockNumber,
employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay);
}
return 0;
}
//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and returns it 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;
printf("Enter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
);
return hoursWorked;
}
//**************************************************************
// Function: calcOvertime
//
// Purpose: Determines overtime hours worked.
//
// Parameters: hours - total hours worked
//
// Returns: overtime hours
//**************************************************************
float calcOvertime(float hours)
{
if (hours > STD_HOURS)
{
return hours - STD_HOURS;
}
else
{
return 0.0;
}
}
//**************************************************************
// Function: calcGross
//
// Purpose: Determines gross pay including overtime.
//
// Parameters:
// wageRate - employee hourly wage
// hours - total hours worked
// overtimeHrs - overtime hours worked
//
// Returns: gross pay
//**************************************************************
float calcGross(float wageRate, float hours, float overtimeHrs)
{
float regularHours;
float normalPay;
float overtimePay;
regularHours = hours - overtimeHrs;
normalPay = regularHours * wageRate;
overtimePay = overtimeHrs * wageRate * OT_RATE;
return normalPay + overtimePay;
}
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//**************************************************************
void printHeader(void)
{
printf("\n--------------------------------------------------------------------------\n"); printf(" Clock# Wage Hours OT Gross\n"); printf("--------------------------------------------------------------------------\n"); }
//**************************************************************
// 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)
{
printf(" %06li %5.2f %5.1f %5.1f %7.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
}