//********************************************************
//
// Assignment 9 - Linked Lists
//
// Name: Jesus Castillo
//
// Class: C Programming, Summer, 2025
//
// Date: 7/27/2025
//
// Description: // Assignment 9 - Dynamically Allocated Linked Lists.
//
//
// 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
#define TAX_STATE_SIZE 3
#define FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
// function prototypes
struct name {
char firstName[FIRST_NAME_SIZE];
char lastName [LAST_NAME_SIZE];
};
struct employee {
struct name empName;
char taxState [TAX_STATE_SIZE];
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
float stateTax;
float fedTax;
float netPay;
};
struct totals {
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
struct min_max {
float min_wageRate;
float min_hours;
float min_overtimeHrs;
float min_grossPay;
float min_stateTax;
float min_fedTax;
float min_netPay;
float max_wageRate;
float max_hours;
float max_overtimeHrs;
float max_grossPay;
float max_stateTax;
float max_fedTax;
float max_netPay;
float stateTax;
};
float getHours (long int clockNumber);
void printHeader (void);
void printEm(void);
void printEmp(struct employee emp);
void calcTaxes(struct employee *emp);
void printSummary(struct employee empArr[], int size);
float calcOvertimeHours(float hours);
float calcGrossPay(float hours, float wageRate);
void calcEmployeeTotals (struct employee * emp_ptr, struct totals * emp_totals_ptr, int theSize);
void calcEmployeeMinMax (struct employee * emp_ptr, struct min_max * emp_minMax_ptr, int theSize);
void printEmpStatistics (struct totals * emp_totals_ptr, struct min_max * emp_minMax_ptr, int theSize);
int main() {
int i;
struct employee myEmp; // structure variable to hold employee
struct employee * empPtr = &myEmp; // pointer to structure of that type
empPtr->clockNumber = 98401;
empPtr->wageRate = 10.60;
empPtr->hours = 51.0;
// TODO: Add other function prototypes here as needed
struct employee employeeData[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}
};
struct totals employeeTotals = {0,0,0,0,0,0,0};
struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
struct totals * emp_totals_ptr = &employeeTotals;
struct min_max * emp_minMax_ptr = &employeeMinMax;
struct employee * emp_ptr; // declare a pointer to the array of employee structures
emp_ptr = employeeData; // set the pointer to point to the array of employees
/* Variable Declarations */
// 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 gross pay
employeeData[i].grossPay = calcGrossPay(employeeData[i].hours, employeeData[i].wageRate);
// TODO: Function call to calculate overtime hours
employeeData[i].overtimeHrs = calcOvertimeHours(employeeData[i].hours);
calcTaxes(&employeeData[i]);
}
// print the header info
printHeader();
// print out each employee
for (i = 0; i < SIZE; ++i) {
// Print all the employees - call by value
printEmp(employeeData[i]);
// for
} // main
printSummary(employeeData, SIZE);
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
->taxState
, "MA") == 0) emp->stateTax = emp->grossPay * 0.05f;
else if (strcmp(emp
->taxState
, "NH") == 0) emp->stateTax = 0.0f;
else if (strcmp(emp
->taxState
, "VT") == 0) emp->stateTax = emp->grossPay * 0.06f;
else if (strcmp(emp
->taxState
, "NY") == 0) emp->stateTax = emp->grossPay * 0.08f;
else if (strcmp(emp
->taxState
, "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 %-8s %06ld %6.2f %6.2f %6.2f %8.2f %7.2f %6.2f %8.2f\n", emp.empName.firstName, emp.empName.lastName, emp.taxState,
emp.clockNumber, emp.wageRate, emp.hours,
emp.overtimeHrs, emp.grossPay, emp.stateTax,
emp.fedTax, emp.netPay);
}
// TODO: Add other functions here as needed
// ... remember your comment block headers for each function
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;
struct employee *empPtr = empArr;
// Total Wage, Hours, OT, Groos, State tax, Fed Tax, Net
float minWage = empArr[0].wageRate;
float maxWage = empArr[0].wageRate;
float minHours = empArr[0].hours;
float maxHours = empArr[0].hours;
float minOT = empArr[0].overtimeHrs;
float maxOT = empArr[0].overtimeHrs;
float minGross = empArr[0].grossPay;
float maxGross = empArr[0].grossPay;
float minState = empArr[0].stateTax;
float maxState = empArr[0].stateTax;
float minFed = empArr[0].fedTax;
float maxFed = empArr[0].fedTax;
float minNet = empArr[0].netPay;
float maxNet = empArr[0].netPay;
//Min and Max of Wage, Hours, OT, Groos, State tax, Fed Tax, Net
for (int i = 0; i < size; i++) {
totalWage += (empPtr + i)-> wageRate;
totalHours += empArr[i].hours;
totalHours += (empPtr + i)-> hours;
totalOT += (empPtr + i)-> overtimeHrs;
totalGross += (empPtr + i)->grossPay;
totalStateTax += (empPtr + i)->stateTax;
totalFedTax += (empPtr + i)->fedTax;
totalNet += (empPtr + i)->netPay;
// Calc total of Taxes of Wage, Hours, OT, Groos, State tax, Fed Tax, Net
if (empArr[i].wageRate < minWage)
minWage = empArr[i].wageRate;
if (empArr[i].wageRate > maxWage)
maxWage = empArr[i].wageRate;
if (empArr[i].hours < minHours)
minHours = empArr[i].hours;
if (empArr[i].hours > maxHours)
maxHours = empArr[i].hours;
if (empArr[i].overtimeHrs < minOT)
minOT = empArr[i].overtimeHrs;
if (empArr[i].overtimeHrs > maxOT)
maxOT = empArr[i].overtimeHrs;
if ((empPtr + i)->grossPay < minGross)
minGross = (empPtr + i)->grossPay;
if ((empPtr + i)->grossPay > maxGross)
maxGross = (empPtr + i)->grossPay;
if (empArr[i].stateTax < minState)
minState = empArr[i].stateTax;
if (empArr[i].stateTax > maxState)
maxState = empArr[i].stateTax;
if (empArr[i].fedTax < minFed)
minNet = empArr[i].netPay;
if (empArr[i].fedTax < minFed)
minFed = empArr[i].fedTax;
if (empArr[i].netPay < minNet)
minNet = empArr[i].netPay;
if (empArr[i].netPay > maxNet)
maxNet = empArr[i].netPay;
// Calc min and max Net Wage, Hours, OT, Groos, State tax, Fed Tax, Net
}
printf("\n-------------------------------------------------------------------------------------------------\n"); printf("Total: %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n", totalWage, totalHours, totalOT, totalGross, totalStateTax, totalFedTax, totalNet);
printf("Averages: %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n", totalWage / size, totalHours / size, totalOT / size, totalGross / size,
totalStateTax / size, totalFedTax / size, totalNet / size);
printf("Minimum: %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n", minWage, minHours, minOT, minGross, minState, minFed, minNet);
printf("Maximum: %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n", maxWage, maxHours, maxOT, maxGross, maxState, maxFed, maxNet);
printf("\n-------------------------------------------------------------------------------------------------\n"); }