//********************************************************
//
// Assignment 7 - Structures and Strings
//
// Name: Seth Hin
//
// Class: C Programming, Spring 2026
//
// Date: March 29, 2026
//
// Description: Program which determines overtime, gross pay,
// state tax, federal tax, and net pay for a set of employees.
// It also calculates totals, averages, minimum, and maximum
// values for all floating point employee data.
//
//********************************************************
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//---------------- CONSTANTS ----------------//
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5
#define MA_TAX_RATE 0.05
#define NH_TAX_RATE 0.0
#define VT_TAX_RATE 0.06
#define CA_TAX_RATE 0.07
#define DEFAULT_TAX_RATE 0.08
#define TAX_STATE_SIZE 3
#define FED_TAX_RATE 0.25
#define FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
//---------------- STRUCTURES ----------------//
// structure to store employee name
struct name
{
char firstName[FIRST_NAME_SIZE];
char lastName[LAST_NAME_SIZE];
};
// structure to store employee information
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;
};
// structure to store totals
struct totals
{
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
// structure to store min and max values
struct min_max
{
float min_wageRate, min_hours, min_overtimeHrs, min_grossPay, min_stateTax, min_fedTax, min_netPay;
float max_wageRate, max_hours, max_overtimeHrs, max_grossPay, max_stateTax, max_fedTax, max_netPay;
};
//---------------- FUNCTION PROTOTYPES ----------------//
void getHours(struct employee[], int);
void calcOvertimeHrs(struct employee[], int);
void calcGrossPay(struct employee[], int);
void calcStateTax(struct employee[], int);
void calcFedTax(struct employee[], int);
void calcNetPay(struct employee[], int);
void printHeader(void);
void printEmp(struct employee[], int);
struct totals calcEmployeeTotals(struct employee[], struct totals, int);
struct min_max calcEmployeeMinMax(struct employee[], struct min_max, int);
void printEmpStatistics(struct totals, struct min_max, int);
int main()
{
// initialize employee data
struct employee employeeData[SIZE] = {
{ {"Connie", "Cobol"}, "MA", 98401, 10.60},
{ {"Mary", "Apl"}, "NH", 526488, 9.75 },
{ {"Frank", "Fortran"}, "VT", 765349, 10.50 },
{ {"Jeff", "Ada"}, "NY", 34645, 12.25 },
{ {"Anton", "Pascal"},"CA",127615, 8.35 }
};
// structure to hold totals
struct totals employeeTotals = {0};
// structure to hold min and max values
struct min_max employeeMinMax = {0};
// function calls
getHours(employeeData, SIZE);
calcOvertimeHrs(employeeData, SIZE);
calcGrossPay(employeeData, SIZE);
calcStateTax(employeeData, SIZE);
calcFedTax(employeeData, SIZE);
calcNetPay(employeeData, SIZE);
employeeTotals = calcEmployeeTotals(employeeData, employeeTotals, SIZE);
employeeMinMax = calcEmployeeMinMax(employeeData, employeeMinMax, SIZE);
printHeader();
printEmp(employeeData, SIZE);
printEmpStatistics(employeeTotals, employeeMinMax, SIZE);
return 0;
} // main
//**************************************************************
// Function: getHours
//
// Purpose: Reads the number of hours worked for each employee
// from user input and stores it in the structure.
//
// Parameters:
// employeeData - array of employee structures
// theSize - number of employees
//
// Returns: void
//**************************************************************
void getHours(struct employee employeeData[], int theSize)
{
int i; // loop index
for (i = 0; i < theSize; i++)
{
printf("\nEnter hours worked by emp # %06li: ", employeeData
[i
].
clockNumber); scanf("%f", &employeeData
[i
].
hours); }
} // getHours
//**************************************************************
// Function: calcOvertimeHrs
//
// Purpose: Calculates overtime hours for each employee.
//
// Parameters:
// employeeData - array of employee structures
// theSize - number of employees
//
// Returns: void
//**************************************************************
void calcOvertimeHrs(struct employee employeeData[], int theSize)
{
int i; // loop index
for (i = 0; i < theSize; i++)
{
if (employeeData[i].hours > STD_HOURS)
employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
else
employeeData[i].overtimeHrs = 0;
}
} // calcOvertimeHrs
//**************************************************************
// Function: calcGrossPay
//
// Purpose: Calculates gross pay including overtime.
//
// Parameters:
// employeeData - array of employee structures
// theSize - number of employees
//
// Returns: void
//**************************************************************
void calcGrossPay(struct employee employeeData[], int theSize)
{
int i; // loop index
float normalPay; // regular pay
float overtimePay; // overtime pay
for (i = 0; i < theSize; i++)
{
normalPay = (employeeData[i].hours - employeeData[i].overtimeHrs) * employeeData[i].wageRate;
overtimePay = employeeData[i].overtimeHrs * OT_RATE * employeeData[i].wageRate;
employeeData[i].grossPay = normalPay + overtimePay;
}
} // calcGrossPay
//**************************************************************
// Function: calcStateTax
//
// Purpose: Calculates state tax based on tax state.
//
// Parameters:
// employeeData - array of employee structures
// theSize - number of employees
//
// Returns: void
//**************************************************************
void calcStateTax(struct employee employeeData[], int theSize)
{
int i; // loop index
for (i = 0; i < theSize; i++)
{
if (strcmp(employeeData
[i
].
taxState, "MA") == 0) employeeData[i].stateTax = employeeData[i].grossPay * MA_TAX_RATE;
else if (strcmp(employeeData
[i
].
taxState, "NH") == 0) employeeData[i].stateTax = employeeData[i].grossPay * NH_TAX_RATE;
else if (strcmp(employeeData
[i
].
taxState, "VT") == 0) employeeData[i].stateTax = employeeData[i].grossPay * VT_TAX_RATE;
else if (strcmp(employeeData
[i
].
taxState, "CA") == 0) employeeData[i].stateTax = employeeData[i].grossPay * CA_TAX_RATE;
else
employeeData[i].stateTax = employeeData[i].grossPay * DEFAULT_TAX_RATE;
}
} // calcStateTax
//**************************************************************
// Function: calcFedTax
//
// Purpose: Calculates federal tax for each employee.
//
// Parameters:
// employeeData - array of employee structures
// theSize - number of employees
//
// Returns: void
//**************************************************************
void calcFedTax(struct employee employeeData[], int theSize)
{
int i; // loop index
for (i = 0; i < theSize; i++)
{
employeeData[i].fedTax = employeeData[i].grossPay * FED_TAX_RATE;
}
} // calcFedTax
//**************************************************************
// Function: calcNetPay
//
// Purpose: Calculates net pay after taxes.
//
// Parameters:
// employeeData - array of employee structures
// theSize - number of employees
//
// Returns: void
//**************************************************************
void calcNetPay(struct employee employeeData[], int theSize)
{
int i; // loop index
float totalTaxes; // sum of taxes
for (i = 0; i < theSize; i++)
{
totalTaxes = employeeData[i].stateTax + employeeData[i].fedTax;
employeeData[i].netPay = employeeData[i].grossPay - totalTaxes;
}
} // calcNetPay
//**************************************************************
// Function: printHeader
//
// Purpose: Prints report header.
//
// Parameters: none
//
// Returns: void
//**************************************************************
void printHeader(void)
{
printf("\n\n*** Pay Calculator ***\n"); printf("\n---------------------------------------------------------------------------------"); printf("\nName Tax Clock# Wage Hours OT Gross State Fed Net"); printf("\n State Pay Tax Tax Pay"); printf("\n---------------------------------------------------------------------------------"); }
//**************************************************************
// Function: printEmp
//
// Purpose: Prints employee data.
//
// Parameters:
// employeeData - array of employees
// theSize - number of employees
//
// Returns: void
//**************************************************************
void printEmp(struct employee employeeData[], int theSize)
{
int i; // loop index
char name[25]; // formatted name
for (i = 0; i < theSize; i++)
{
strcpy(name
, employeeData
[i
].
empName.
firstName); strcat(name
, employeeData
[i
].
empName.
lastName);
printf("\n%-20s %-2s %06li %6.2f %6.1f %5.1f %7.2f %6.2f %7.2f %8.2f", name, employeeData[i].taxState, employeeData[i].clockNumber,
employeeData[i].wageRate, employeeData[i].hours,
employeeData[i].overtimeHrs, employeeData[i].grossPay,
employeeData[i].stateTax, employeeData[i].fedTax,
employeeData[i].netPay);
}
} // printEmp
//**************************************************************
// Function: calcEmployeeTotals
//
// Purpose: Calculates totals of all numeric fields.
//
// Parameters:
// employeeData - array of employees
// employeeTotals - totals structure
// theSize - number of employees
//
// Returns: updated totals structure
//**************************************************************
struct totals calcEmployeeTotals(struct employee employeeData[],
struct totals employeeTotals,
int theSize)
{
int i; // loop index
for (i = 0; i < theSize; i++)
{
employeeTotals.total_wageRate += employeeData[i].wageRate;
employeeTotals.total_hours += employeeData[i].hours;
employeeTotals.total_overtimeHrs += employeeData[i].overtimeHrs;
employeeTotals.total_grossPay += employeeData[i].grossPay;
employeeTotals.total_stateTax += employeeData[i].stateTax;
employeeTotals.total_fedTax += employeeData[i].fedTax;
employeeTotals.total_netPay += employeeData[i].netPay;
}
return employeeTotals;
} // calcEmployeeTotals
//**************************************************************
// Function: calcEmployeeMinMax
//
// Purpose: Determines min and max values.
//
// Parameters:
// employeeData - array of employees
// employeeMinMax - min/max structure
// theSize - number of employees
//
// Returns: updated min/max structure
//**************************************************************
struct min_max calcEmployeeMinMax(struct employee employeeData[],
struct min_max employeeMinMax,
int theSize)
{
int i; // loop index
employeeMinMax.min_wageRate = employeeMinMax.max_wageRate = employeeData[0].wageRate;
employeeMinMax.min_hours = employeeMinMax.max_hours = employeeData[0].hours;
employeeMinMax.min_overtimeHrs = employeeMinMax.max_overtimeHrs = employeeData[0].overtimeHrs;
employeeMinMax.min_grossPay = employeeMinMax.max_grossPay = employeeData[0].grossPay;
employeeMinMax.min_stateTax = employeeMinMax.max_stateTax = employeeData[0].stateTax;
employeeMinMax.min_fedTax = employeeMinMax.max_fedTax = employeeData[0].fedTax;
employeeMinMax.min_netPay = employeeMinMax.max_netPay = employeeData[0].netPay;
for (i = 1; i < theSize; i++)
{
if (employeeData[i].hours < employeeMinMax.min_hours)
employeeMinMax.min_hours = employeeData[i].hours;
if (employeeData[i].hours > employeeMinMax.max_hours)
employeeMinMax.max_hours = employeeData[i].hours;
if (employeeData[i].overtimeHrs < employeeMinMax.min_overtimeHrs)
employeeMinMax.min_overtimeHrs = employeeData[i].overtimeHrs;
if (employeeData[i].overtimeHrs > employeeMinMax.max_overtimeHrs)
employeeMinMax.max_overtimeHrs = employeeData[i].overtimeHrs;
if (employeeData[i].grossPay < employeeMinMax.min_grossPay)
employeeMinMax.min_grossPay = employeeData[i].grossPay;
if (employeeData[i].grossPay > employeeMinMax.max_grossPay)
employeeMinMax.max_grossPay = employeeData[i].grossPay;
if (employeeData[i].stateTax < employeeMinMax.min_stateTax)
employeeMinMax.min_stateTax = employeeData[i].stateTax;
if (employeeData[i].stateTax > employeeMinMax.max_stateTax)
employeeMinMax.max_stateTax = employeeData[i].stateTax;
if (employeeData[i].fedTax < employeeMinMax.min_fedTax)
employeeMinMax.min_fedTax = employeeData[i].fedTax;
if (employeeData[i].fedTax > employeeMinMax.max_fedTax)
employeeMinMax.max_fedTax = employeeData[i].fedTax;
if (employeeData[i].netPay < employeeMinMax.min_netPay)
employeeMinMax.min_netPay = employeeData[i].netPay;
if (employeeData[i].netPay > employeeMinMax.max_netPay)
employeeMinMax.max_netPay = employeeData[i].netPay;
}
return employeeMinMax;
} // calcEmployeeMinMax
//**************************************************************
// Function: printEmpStatistics
//
// Purpose: Prints totals, averages, min, and max values.
//
// Parameters:
// employeeTotals - totals structure
// employeeMinMax - min/max structure
// theSize - number of employees
//
// Returns: void
//**************************************************************
void printEmpStatistics(struct totals employeeTotals,
struct min_max employeeMinMax,
int theSize)
{
printf("\n---------------------------------------------------------------------------------");
printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", employeeTotals.total_wageRate,
employeeTotals.total_hours,
employeeTotals.total_overtimeHrs,
employeeTotals.total_grossPay,
employeeTotals.total_stateTax,
employeeTotals.total_fedTax,
employeeTotals.total_netPay);
printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", employeeTotals.total_wageRate / theSize,
employeeTotals.total_hours / theSize,
employeeTotals.total_overtimeHrs / theSize,
employeeTotals.total_grossPay / theSize,
employeeTotals.total_stateTax / theSize,
employeeTotals.total_fedTax / theSize,
employeeTotals.total_netPay / theSize);
printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", employeeMinMax.min_wageRate,
employeeMinMax.min_hours,
employeeMinMax.min_overtimeHrs,
employeeMinMax.min_grossPay,
employeeMinMax.min_stateTax,
employeeMinMax.min_fedTax,
employeeMinMax.min_netPay);
printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f\n", employeeMinMax.max_wageRate,
employeeMinMax.max_hours,
employeeMinMax.max_overtimeHrs,
employeeMinMax.max_grossPay,
employeeMinMax.max_stateTax,
employeeMinMax.max_fedTax,
employeeMinMax.max_netPay);
} // printEmpStatistics