//********************************************************
//
// Assignment 7 - Structures and Strings
//
// Name: Carlos Dominguez
//
// Class: C Programming, Spring 2026
//
// Date:03/29/2026
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// This assignment also adds the employee name, their tax state,
// and calculates the state tax, federal tax, and net pay. It
// also calculates totals, averages, minimum, and maximum values.
//
//********************************************************
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//-------------------------------
// Constant Definitions
//-------------------------------
#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 FED_TAX_RATE 0.25
#define FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
#define TAX_STATE_SIZE 3
//-------------------------------
// Structure Definitions
//-------------------------------
// Stores first and last name separately
struct name
{
char firstName[FIRST_NAME_SIZE];
char lastName[LAST_NAME_SIZE];
};
// Stores all employee-related 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;
};
// Stores running totals for all floating-point fields
struct totals
{
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
// Stores min and max values for all floating-point fields
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;
};
//-------------------------------
// Function Prototypes
//-------------------------------
void getHours(struct employee employeeData[], int theSize);
void calcOvertimeHrs(struct employee employeeData[], int theSize);
void calcGrossPay(struct employee employeeData[], int theSize);
void calcStateTax(struct employee employeeData[], int theSize);
void calcFedTax(struct employee employeeData[], int theSize);
void calcNetPay(struct employee employeeData[], int theSize);
void printHeader(void);
void printEmp(struct employee employeeData[], int theSize);
void printEmpStatistics(struct totals employeeTotals,
struct min_max employeeMinMax,
int theSize);
struct totals calcEmployeeTotals(struct employee employeeData[],
struct totals employeeTotals,
int theSize);
struct min_max calcEmployeeMinMax(struct employee employeeData[],
struct min_max employeeMinMax,
int theSize);
//********************************************************
// main
//********************************************************
int main()
{
// Initialize employee data (names, tax state, clock#, wage)
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}
};
// Initialize totals and min/max structures
struct totals employeeTotals = {0,0,0,0,0,0,0};
struct min_max employeeMinMax = {0};
// Collect and compute all employee data
getHours(employeeData, SIZE);
calcOvertimeHrs(employeeData, SIZE);
calcGrossPay(employeeData, SIZE);
calcStateTax(employeeData, SIZE);
calcFedTax(employeeData, SIZE);
calcNetPay(employeeData, SIZE);
// Compute totals and min/max values
employeeTotals = calcEmployeeTotals(employeeData, employeeTotals, SIZE);
employeeMinMax = calcEmployeeMinMax(employeeData, employeeMinMax, SIZE);
// Display results
printHeader();
printEmp(employeeData, SIZE);
printEmpStatistics(employeeTotals, employeeMinMax, SIZE);
return 0;
}
//********************************************************
// getHours
// Purpose: Reads hours worked for each employee
//********************************************************
void getHours(struct employee employeeData[], int theSize)
{
int i;
for (i = 0; i < theSize; ++i)
{
printf("\nEnter hours worked by emp # %06li: ", employeeData[i].clockNumber);
scanf("%f", &employeeData
[i
].
hours); }
}
//********************************************************
// calcOvertimeHrs
// Purpose: Determines overtime hours (> 40)
//********************************************************
void calcOvertimeHrs(struct employee employeeData[], int theSize)
{
int i;
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;
}
}
//********************************************************
// calcGrossPay
// Purpose: Computes gross pay including overtime
//********************************************************
void calcGrossPay(struct employee employeeData[], int theSize)
{
int i;
float normalPay, overtimePay;
for (i = 0; i < theSize; ++i)
{
normalPay = employeeData[i].wageRate *
(employeeData[i].hours - employeeData[i].overtimeHrs);
overtimePay = employeeData[i].overtimeHrs *
(employeeData[i].wageRate * OT_RATE);
employeeData[i].grossPay = normalPay + overtimePay;
}
}
//********************************************************
// calcStateTax
// Purpose: Computes state tax based on employee's taxState
//********************************************************
void calcStateTax(struct employee employeeData[], int theSize)
{
int i;
for (i = 0; i < theSize; ++i)
{
// Normalize state code to uppercase
employeeData
[i
].
taxState[0] = toupper(employeeData
[i
].
taxState[0]); employeeData
[i
].
taxState[1] = toupper(employeeData
[i
].
taxState[1]);
// Apply correct state tax rate
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;
}
}
//********************************************************
// calcFedTax
// Purpose: Computes federal tax (flat rate)
//********************************************************
void calcFedTax(struct employee employeeData[], int theSize)
{
int i;
for (i = 0; i < theSize; ++i)
{
employeeData[i].fedTax = employeeData[i].grossPay * FED_TAX_RATE;
}
}
//********************************************************
// calcNetPay
// Purpose: Computes take-home pay after taxes
//********************************************************
void calcNetPay(struct employee employeeData[], int theSize)
{
int i;
float totalTaxes;
for (i = 0; i < theSize; ++i)
{
totalTaxes = employeeData[i].stateTax + employeeData[i].fedTax;
employeeData[i].netPay = employeeData[i].grossPay - totalTaxes;
}
}
//********************************************************
// printHeader
// Purpose: Prints formatted table header
//********************************************************
void printHeader(void)
{
printf("\n\n*** Pay Calculator ***\n"); printf("\n--------------------------------------------------------------"); printf("-------------------"); printf("\nName Tax Clock# Wage Hours OT Gross "); printf("\n--------------------------------------------------------------"); printf("-------------------"); }
//********************************************************
// printEmp
// Purpose: Prints each employee's computed payroll data
//********************************************************
void printEmp(struct employee employeeData[], int theSize)
{
int i;
char fullName[FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
for (i = 0; i < theSize; ++i)
{
// Build full name string
strcpy(fullName
, employeeData
[i
].
empName.
firstName); strcat(fullName
, employeeData
[i
].
empName.
lastName);
printf("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f", fullName,
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);
}
}
//********************************************************
// printEmpStatistics
// Purpose: Prints totals, averages, min, and max values
//********************************************************
void printEmpStatistics(struct totals employeeTotals,
struct min_max employeeMinMax,
int theSize)
{
printf("\n--------------------------------------------------------------"); printf("-------------------");
// Totals
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);
// Averages
if (theSize > 0)
{
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);
}
// Minimum values
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);
// Maximum values
printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", employeeMinMax.max_wageRate,
employeeMinMax.max_hours,
employeeMinMax.max_overtimeHrs,
employeeMinMax.max_grossPay,
employeeMinMax.max_stateTax,
employeeMinMax.max_fedTax,
employeeMinMax.max_netPay);
}
//********************************************************
// calcEmployeeTotals
// Purpose: Accumulates totals for all float fields
//********************************************************
struct totals calcEmployeeTotals(struct employee employeeData[],
struct totals employeeTotals,
int theSize)
{
int i;
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;
}
//********************************************************
// calcEmployeeMinMax
// Purpose: Determines min and max values for all fields
//********************************************************
struct min_max calcEmployeeMinMax(struct employee employeeData[],
struct min_max employeeMinMax,
int theSize)
{
int i;
// Initialize min and max with first employee
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;
// Compare remaining employees
for (i = 1; i < theSize; ++i)
{
if (employeeData[i].wageRate < employeeMinMax.min_wageRate)
employeeMinMax.min_wageRate = employeeData[i].wageRate;
if (employeeData[i].wageRate > employeeMinMax.max_wageRate)
employeeMinMax.max_wageRate = employeeData[i].wageRate;
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;
}