//********************************************************
//
// Assignment 6 - Functions
//
// Name: Jesus Castillo
//
// Class: C Programming, Summer, 2025
//
// Date: 6/29/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;
};
float getHours(long int clockNumber);
float calcOvertimeHours(float hours);
float calcGrossPay(float hours, float wageRate);
void printHeader(void);
void printEmp(struct employee emp);
// TODO: Add other function prototypes here as needed
/* Variable Declarations */
int main() {
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;
// function prototypes
// process each employee
for (i = 0; i < SIZE; ++i)
{
// Read in hours for employee
employeeData[i].hours = getHours(employeeData[i].clockNumber);
// TODO: Function call to calculate overtime hours
employeeData[i].overtimeHrs = calcOvertimeHours(employeeData[i].hours);
// TODO: Function call to calculate gross pay
employeeData[i].grossPay = calcGrossPay(employeeData[i].hours, employeeData[i].wageRate);
}
// print the header info
printHeader();{
printf("\nClock# Wage Hours OT Gross\n"); printf("----------------------------------------\n"); }
// Print employee data
for (i = 0; i < SIZE; ++i) {
printEmp(employeeData[i]);
}
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
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
); // return hours back to the calling function
return hoursWorked;
} // getHours
float calcOvertimeHours(float hours) {
if (hours > STD_WORK_WEEK)
return hours - STD_WORK_WEEK;
else
return 0.0f;
}
float calcGrossPay(float hours, float wageRate) {
float overtime = calcOvertimeHours(hours);
if (hours > STD_WORK_WEEK) {
return (STD_WORK_WEEK * wageRate) + (overtime * wageRate * OVERTIME_RATE);
} else {
return hours * wageRate;
}
}// overtime pay
//**************************************************************
// 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: 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.1f %5.1f %8.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
}