///********************************************************
//
// Assignment 6 - Functions
//
// Name: Jesus Castillo
//
// Class: C Programming, Summer, 2025
//
// Date: 7/19/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.5f
#define STD_WORK_WEEK 40.0f
// function prototypes
struct employee {
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
};
int main() {
float getHours (long int clockNumber);
void printHeader (void);
void printEm(void);
void printEmp(struct employee emp);
float calcOvertimeHours(float hours);
float calcGrossPay(float hours, float wageRate);
int i;
// TODO: Add other function prototypes here as needed
struct employee emp[SIZE] = {
{98401, 10.60},
{526488, 9.75},
{765349, 10.50},
{34645, 12.25},
{127615, 8.35}
};
/* Variable Declarations */
// process each employee
for (i = 0; i < SIZE; ++i) {
// Read in hours for employee
emp[i].hours = getHours(emp[i].clockNumber);
// TODO: Function call to calculate gross pay
emp[i].grossPay = calcGrossPay(emp[i].hours, emp[i].wageRate);
// TODO: Function call to calculate overtime hours
emp[i].overtimeHrs = calcOvertimeHours(emp[i].hours);
};
// print the header info
printHeader();
// print out each employee
for (i = 0; i < SIZE; ++i) {
// Print all the employees - call by value
printEmp(emp[i]);
// for
} // main
return (0);
}
//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and stores the result in a local variable
// that is passed back 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; // hours worked in a given week
// Read in hours for employee
if (clockNumber == 98401)
hoursWorked = 51.0;
else if (clockNumber == 526488)
hoursWorked = 42.5;
else if (clockNumber == 765349)
hoursWorked = 37.0;
else if (clockNumber == 34645)
hoursWorked = 45.0;
else if (clockNumber == 127615)
hoursWorked = 0;
else
hoursWorked = 0.0;
printf("Enter hours worked by emp #%06ld: %.2f\n", clockNumber
, hoursWorked
);
return hoursWorked;
} // getHours
float calcOvertimeHours(float hours) {
return (hours > STD_WORK_WEEK) ? (hours - STD_WORK_WEEK) : 0.0f;
}
float calcGrossPay(float hours, float wageRate) {
float overtime = calcOvertimeHours(hours);
float regularHours = (hours > STD_WORK_WEEK) ? STD_WORK_WEEK : hours;
return (regularHours * wageRate) + (overtime * wageRate * OVERTIME_RATE);
}
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printHeader (void)
{
printf("\n---------------------------------------------"); printf ("\n\n*** Pay Calculator ***\n");
// print the table header
printf("\nClock# Wage Hours OT Gross\n"); printf("----------------------------------------------\n");
} // printHeader
//*************************************************************
// 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(struct employee emp) {
printf("%06ld %5.2f %5.2f %5.2f %5.2f\n", emp.clockNumber, emp.wageRate, emp.hours,
emp.overtimeHrs, emp.grossPay);
}
// TODO: Add other functions here as needed
// ... remember your comment block headers for each function