//********************************************************
//
// Assignment 7 - Structures and Strings
//
// Name: Anthony Principe
//
// Class: C Programming, Fall 2025
//
// Date: 11/2/2025
//
// 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.
//
// Call by Reference design
//
//********************************************************
// necessary header files
#include <stdio.h>
#include <string.h>
#include <ctype.h>
// define 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 NAME_SIZE 20
#define TAX_STATE_SIZE 3
#define FED_TAX_RATE 0.25
#define FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
// Define a structure type to store an employee name
struct name {
char firstName[FIRST_NAME_SIZE];
char lastName[LAST_NAME_SIZE];
};
// Define a structure type to pass employee data between functions
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;
};
// totals
struct totals {
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
// min/max
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);
struct totals calcEmployeeTotals(struct employee employeeData[],
struct totals employeeTotals, int theSize);
struct min_max calcEmployeeMinMax(struct employee employeeData[],
struct min_max employeeMinMax, int theSize);
void printHeader(void);
void printEmp(struct employee employeeData[], int theSize);
void printEmpStatistics(struct totals employeeTotals,
struct min_max employeeMinMax, int theSize);
//********************************************************
// Used the template to fill in tax and totals logic and tested input hours.
int main() {
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 }
};
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};
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;
}
//********************************************************
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); }
}
//********************************************************
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---------------------------------------------------------------------------------"); }
//********************************************************
void printEmp(struct employee employeeData[], int theSize) {
int i;
char name[FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
for(i = 0; i < theSize; i++) {
strcpy(name
, employeeData
[i
].
empName.
firstName); strcat(name
, employeeData
[i
].
empName.
lastName);
printf("\n%-19s %-3s %06li %7.2f %5.1f %5.1f %7.2f %7.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);
}
}
//********************************************************
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;
}
}
//********************************************************
void calcGrossPay(struct employee employeeData[], int theSize) {
int i;
float theNormalPay;
float theOvertimePay;
for(i = 0; i < theSize; i++) {
theNormalPay = employeeData[i].wageRate *
(employeeData[i].hours - employeeData[i].overtimeHrs);
theOvertimePay = employeeData[i].overtimeHrs *
(OT_RATE * employeeData[i].wageRate);
employeeData[i].grossPay = theNormalPay + theOvertimePay;
}
}
//********************************************************
void calcStateTax(struct employee employeeData[], int theSize) {
int i;
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;
}
}
//********************************************************
void calcFedTax(struct employee employeeData[], int theSize) {
int i;
for(i = 0; i < theSize; i++) {
employeeData[i].fedTax = employeeData[i].grossPay * FED_TAX_RATE;
}
}
//********************************************************
void calcNetPay(struct employee employeeData[], int theSize) {
int i;
for(i = 0; i < theSize; i++) {
employeeData[i].netPay =
employeeData[i].grossPay - (employeeData[i].stateTax + employeeData[i].fedTax);
}
}
//********************************************************
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;
}
//********************************************************
struct min_max calcEmployeeMinMax(struct employee employeeData[],
struct min_max employeeMinMax, int theSize) {
int i;
employeeMinMax.min_wageRate = employeeData[0].wageRate;
employeeMinMax.min_hours = employeeData[0].hours;
employeeMinMax.min_overtimeHrs = employeeData[0].overtimeHrs;
employeeMinMax.min_grossPay = employeeData[0].grossPay;
employeeMinMax.min_stateTax = employeeData[0].stateTax;
employeeMinMax.min_fedTax = employeeData[0].fedTax;
employeeMinMax.min_netPay = employeeData[0].netPay;
employeeMinMax.max_wageRate = employeeData[0].wageRate;
employeeMinMax.max_hours = employeeData[0].hours;
employeeMinMax.max_overtimeHrs = employeeData[0].overtimeHrs;
employeeMinMax.max_grossPay = employeeData[0].grossPay;
employeeMinMax.max_stateTax = employeeData[0].stateTax;
employeeMinMax.max_fedTax = employeeData[0].fedTax;
employeeMinMax.max_netPay = employeeData[0].netPay;
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;
}
//********************************************************
void printEmpStatistics(struct totals employeeTotals,
struct min_max employeeMinMax, int theSize) {
printf("\n---------------------------------------------------------------------------------");
printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %7.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 %7.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 %7.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 %7.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 );
}