///********************************************************
//
// 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>
#include <string.h>
// constants
#define SIZE 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f
// function prototypes
struct name {
char firstName [10];
char lastName [10];
};
struct employee {
struct name empName;
char state[3];
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
float stateTax;
float fedTax;
float netPay;
};
int main() {
float getHours (long int clockNumber);
void printHeader (void);
void printEmp(struct employee emp);
void printSummary(struct employee empArr[], int size);
float calcOvertimeHours(float hours);
float calcGrossPay(float hours, float wageRate);
int i;
void calcTaxes(struct employee *emp);
// TODO: Add other function prototypes here as needed
struct employee emp[SIZE] = {
{{"Connie", "Cobol"}, "MA", 98401, 10.60},
{{"Mary", "Apl",}, "NH", 526488, 9.75},
{{"Frank", "Fortran"}, "VT", 765349, 10.5},
{{"Jeff", "Ada"}, "NY", 34645, 12.25},
{{"Anton", "Pascal"}, "CA", 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].overtimeHrs = calcOvertimeHours(emp[i].hours);
// TODO: Function call to calculate overtime hours
emp[i].grossPay = calcGrossPay(emp[i].hours, emp[i].wageRate);
//Calculate Taxes
calcTaxes(&emp[i]);
};
// 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]);
};
printSummary(emp, SIZE);
// 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 = 40.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;
} // calcOvertimeHours
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);
} // calcGrossPay
void calcTaxes(struct employee *emp) {
if (strcmp(emp
->state
, "MA") == 0) emp->stateTax = emp->grossPay * 0.05f;
else if (strcmp(emp
->state
, "NH") == 0) emp->stateTax = 0.0f;
else if (strcmp(emp
->state
, "VT") == 0) emp->stateTax = emp->grossPay * 0.06f;
else if (strcmp(emp
->state
, "NY") == 0) emp->stateTax = emp->grossPay * 0.08f;
else if (strcmp(emp
->state
, "CA") == 0) emp->stateTax = emp->grossPay * 0.07f;
else
emp->stateTax = 0.8f;
emp->fedTax = emp->grossPay * 0.25f;
emp->netPay = emp->grossPay - (emp->stateTax + emp->fedTax);
}; // Calc Taxes
//**************************************************************
// 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("\nName St Clock# Wage Hours OT Gross StTax FedTax NetPay \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("%-8s %-8s %-3s %06ld %6.2f %6.2f %6.2f %8.2f %7.2f %6.2f %8.2f\n", emp.empName.firstName, emp.empName.lastName, emp.state,
emp.clockNumber, emp.wageRate, emp.hours,
emp.overtimeHrs, emp.grossPay, emp.stateTax,
emp.fedTax, emp.netPay);
};
void printSummary(struct employee empArr[], int size) {
float totalWage = 0.0f;
float totalHours = 0.0f;
float totalOT = 0.0f;
float totalGross = 0.0f;
float totalStateTax = 0.0f;
float totalFedTax = 0.0f;
float totalNet = 0.0f;
for (int i = 0; i < size; i++) {
totalWage += empArr[i].wageRate;
totalHours += empArr[i].hours;
totalOT += empArr[i].overtimeHrs;
totalGross += empArr[i].grossPay;
totalStateTax += empArr[i].stateTax;
totalFedTax += empArr[i].fedTax;
totalNet += empArr[i].netPay;
}
printf("\n-------------------------------------------------------------------------------------------------\n"); printf("Total: %6.2f %6.2f %6.2f %8.2f %7.2f %6.2f %8.2f\n", totalWage, totalHours, totalOT, totalGross, totalStateTax, totalFedTax, totalNet);
printf("\n-------------------------------------------------------------------------------------------------\n"); }
// TODO: Add other functions here as needed
// ... remember your comment block headers for each function