//********************************************************
//
// Assignment 8 - Employee Pay Calculator with Pointers
//
// Name: Felix Henriquez
//
// Class: C Programming, Fall 2025
//
// Date: November 9, 2025
//
// Description: Extended employee pay calculator using pointers to structures,
// character strings, and tax calculations to determine
// state tax, federal tax, and net pay with summary stats.
//
//********************************************************
#include <stdio.h>
#include <string.h>
// Constants for array sizes and business rules
#define MAX_EMPLOYEES 5
#define FIRST_NAME_SIZE 11 // 10 characters + null terminator
#define LAST_NAME_SIZE 11 // 10 characters + null terminator
#define TAX_STATE_SIZE 3 // 2 characters + null terminator
#define STANDARD_WORK_WEEK 40.0
#define OVERTIME_RATE 1.5
#define FED_TAX_RATE 0.25
// Structure for employee name
struct name
{
char firstName[FIRST_NAME_SIZE];
char lastName[LAST_NAME_SIZE];
};
// Structure for employee data
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 for summary statistics
struct summaryStats
{
float totalWage; // Sum of all wage rates
float totalHours; // Sum of all hours worked
float totalOvertimeHrs; // Sum of all overtime hours
float totalGrossPay; // Sum of all gross pay amounts
float totalStateTax; // Sum of all state tax amounts
float totalFedTax; // Sum of all federal tax amounts
float totalNetPay; // Sum of all net pay amounts
float avgWage; // Average wage rate across employees
float avgHours; // Average hours worked
float avgOvertimeHrs; // Average overtime hours
float avgGrossPay; // Average gross pay
float avgStateTax; // Average state tax
float avgFedTax; // Average federal tax
float avgNetPay; // Average net pay
float minWage; // Minimum wage rate
float minHours; // Minimum hours worked
float minOvertimeHrs; // Minimum overtime hours
float minGrossPay; // Minimum gross pay
float minStateTax; // Minimum state tax
float minFedTax; // Minimum federal tax
float minNetPay; // Minimum net pay
float maxWage; // Maximum wage rate
float maxHours; // Maximum hours worked
float maxOvertimeHrs; // Maximum overtime hours
float maxGrossPay; // Maximum gross pay
float maxStateTax; // Maximum state tax
float maxFedTax; // Maximum federal tax
float maxNetPay; // Maximum net pay
};
/*****************************************************************************
* Function: findMin
*
* Purpose: Returns the minimum of two float values
*
* Parameters: a - first value to compare
* b - second value to compare
*
* Returns: The smaller of the two values
*****************************************************************************/
float findMin(float a, float b) {
return (a < b) ? a : b;
}
/*****************************************************************************
* Function: findMax
*
* Purpose: Returns the maximum of two float values
*
* Parameters: a - first value to compare
* b - second value to compare
*
* Returns: The larger of the two values
*****************************************************************************/
float findMax(float a, float b) {
return (a > b) ? a : b;
}
/*****************************************************************************
* Function: getStateTaxRate
*
* Purpose: Determines the state tax rate based on the state code
*
* Parameters: state - pointer to two-character state code string
*
* Returns: State tax rate as a float percentage
*****************************************************************************/
float getStateTaxRate(const char *state) {
if (strcmp(state
, "MA") == 0) return 0.05; // Massachusetts: 5% if (strcmp(state
, "NH") == 0) return 0.00; // New Hampshire: 0% if (strcmp(state
, "VT") == 0) return 0.06; // Vermont: 6% if (strcmp(state
, "CA") == 0) return 0.07; // California: 7% return 0.08; // All other states: 8%
}
/*****************************************************************************
* Function: initializeEmployees
*
* Purpose: Initializes the employee array with predefined data using pointers
*
* Parameters: emp_ptr - pointer to array of employee structures to initialize
*
* Returns: void
*****************************************************************************/
void initializeEmployees(struct employee *emp_ptr) {
int i; // loop counter
// Initialize employee data with predefined values using pointer arithmetic
strcpy(emp_ptr
->empName.
firstName, "Connie"); strcpy(emp_ptr
->empName.
lastName, "Cobol"); strcpy(emp_ptr
->taxState
, "MA"); emp_ptr->clockNumber = 98401;
emp_ptr->wageRate = 10.60;
strcpy((emp_ptr
+ 1)->empName.
firstName, "Mary"); strcpy((emp_ptr
+ 1)->empName.
lastName, "Apl"); strcpy((emp_ptr
+ 1)->taxState
, "NH"); (emp_ptr + 1)->clockNumber = 526488;
(emp_ptr + 1)->wageRate = 9.75;
strcpy((emp_ptr
+ 2)->empName.
firstName, "Frank"); strcpy((emp_ptr
+ 2)->empName.
lastName, "Fortran"); strcpy((emp_ptr
+ 2)->taxState
, "VT"); (emp_ptr + 2)->clockNumber = 765349;
(emp_ptr + 2)->wageRate = 10.50;
strcpy((emp_ptr
+ 3)->empName.
firstName, "Jeff"); strcpy((emp_ptr
+ 3)->empName.
lastName, "Ada"); strcpy((emp_ptr
+ 3)->taxState
, "NY"); (emp_ptr + 3)->clockNumber = 34645;
(emp_ptr + 3)->wageRate = 12.25;
strcpy((emp_ptr
+ 4)->empName.
firstName, "Anton"); strcpy((emp_ptr
+ 4)->empName.
lastName, "Pascal"); strcpy((emp_ptr
+ 4)->taxState
, "CA"); (emp_ptr + 4)->clockNumber = 127615;
(emp_ptr + 4)->wageRate = 8.35;
// Initialize calculated fields to zero using pointer arithmetic
for(i = 0; i < MAX_EMPLOYEES; i++) {
(emp_ptr + i)->hours = 0;
(emp_ptr + i)->overtimeHrs = 0;
(emp_ptr + i)->grossPay = 0;
(emp_ptr + i)->stateTax = 0;
(emp_ptr + i)->fedTax = 0;
(emp_ptr + i)->netPay = 0;
}
}
/*****************************************************************************
* Function: getEmployeeHours
*
* Purpose: Reads hours worked for each employee from standard input using pointers
*
* Parameters: emp_ptr - pointer to array of employee structures
*
* Returns: void
*****************************************************************************/
void getEmployeeHours(struct employee *emp_ptr) {
int i; // loop counter
// Read hours for each employee using pointer arithmetic
for(i = 0; i < MAX_EMPLOYEES; i++) {
scanf("%f", &(emp_ptr
+ i
)->hours
); }
}
/*****************************************************************************
* Function: computeOvertime
*
* Purpose: Calculates overtime hours for each employee using pointers
*
* Parameters: emp_ptr - pointer to array of employee structures
*
* Returns: void
*****************************************************************************/
void computeOvertime(struct employee *emp_ptr) {
int i; // loop counter
for(i = 0; i < MAX_EMPLOYEES; i++) {
if((emp_ptr + i)->hours > STANDARD_WORK_WEEK) {
(emp_ptr + i)->overtimeHrs = (emp_ptr + i)->hours - STANDARD_WORK_WEEK; // Calculate overtime
} else {
(emp_ptr + i)->overtimeHrs = 0.0; // No overtime
}
}
}
/*****************************************************************************
* Function: computeGrossPay
*
* Purpose: Calculates gross pay including overtime at time-and-a-half using pointers
*
* Parameters: emp_ptr - pointer to array of employee structures
*
* Returns: void
*****************************************************************************/
void computeGrossPay(struct employee *emp_ptr) {
int i; // loop counter
float regularHours; // hours up to 40
float basePay; // pay for regular hours
float overtimePay; // pay for overtime hours
for(i = 0; i < MAX_EMPLOYEES; i++) {
regularHours = (emp_ptr + i)->hours;
if(regularHours > STANDARD_WORK_WEEK) {
regularHours = STANDARD_WORK_WEEK; // Cap at 40 hours
}
basePay = regularHours * (emp_ptr + i)->wageRate; // Regular pay
overtimePay = (emp_ptr + i)->overtimeHrs * (emp_ptr + i)->wageRate * OVERTIME_RATE; // Overtime pay
(emp_ptr + i)->grossPay = basePay + overtimePay; // Total gross pay
}
}
/*****************************************************************************
* Function: computeTaxesAndNetPay
*
* Purpose: Calculates state tax, federal tax, and net pay for each employee using pointers
*
* Parameters: emp_ptr - pointer to array of employee structures
*
* Returns: void
*****************************************************************************/
void computeTaxesAndNetPay(struct employee *emp_ptr) {
int i; // loop counter
float stateRate; // state-specific tax rate
for(i = 0; i < MAX_EMPLOYEES; i++) {
stateRate = getStateTaxRate((emp_ptr + i)->taxState); // Get state rate
(emp_ptr + i)->stateTax = (emp_ptr + i)->grossPay * stateRate; // Calculate state tax
(emp_ptr + i)->fedTax = (emp_ptr + i)->grossPay * FED_TAX_RATE; // Calculate federal tax
(emp_ptr + i)->netPay = (emp_ptr + i)->grossPay - (emp_ptr + i)->stateTax - (emp_ptr + i)->fedTax; // Calculate net pay
}
}
/*****************************************************************************
* Function: calculateSummaryStats
*
* Purpose: Calculates comprehensive summary statistics for all employees using pointers
*
* Parameters: emp_ptr - pointer to array of employee structures
* stats_ptr - pointer to summaryStats structure to store results
*
* Returns: void
*****************************************************************************/
void calculateSummaryStats(struct employee *emp_ptr, struct summaryStats *stats_ptr) {
int i; // loop counter
// Initialize totals to zero
stats_ptr->totalWage = 0;
stats_ptr->totalHours = 0;
stats_ptr->totalOvertimeHrs = 0;
stats_ptr->totalGrossPay = 0;
stats_ptr->totalStateTax = 0;
stats_ptr->totalFedTax = 0;
stats_ptr->totalNetPay = 0;
// Initialize min/max with first employee's data
stats_ptr->minWage = emp_ptr->wageRate;
stats_ptr->minHours = emp_ptr->hours;
stats_ptr->minOvertimeHrs = emp_ptr->overtimeHrs;
stats_ptr->minGrossPay = emp_ptr->grossPay;
stats_ptr->minStateTax = emp_ptr->stateTax;
stats_ptr->minFedTax = emp_ptr->fedTax;
stats_ptr->minNetPay = emp_ptr->netPay;
stats_ptr->maxWage = emp_ptr->wageRate;
stats_ptr->maxHours = emp_ptr->hours;
stats_ptr->maxOvertimeHrs = emp_ptr->overtimeHrs;
stats_ptr->maxGrossPay = emp_ptr->grossPay;
stats_ptr->maxStateTax = emp_ptr->stateTax;
stats_ptr->maxFedTax = emp_ptr->fedTax;
stats_ptr->maxNetPay = emp_ptr->netPay;
// Process all employees using pointer arithmetic
for(i = 0; i < MAX_EMPLOYEES; i++) {
// Calculate totals
stats_ptr->totalWage += (emp_ptr + i)->wageRate;
stats_ptr->totalHours += (emp_ptr + i)->hours;
stats_ptr->totalOvertimeHrs += (emp_ptr + i)->overtimeHrs;
stats_ptr->totalGrossPay += (emp_ptr + i)->grossPay;
stats_ptr->totalStateTax += (emp_ptr + i)->stateTax;
stats_ptr->totalFedTax += (emp_ptr + i)->fedTax;
stats_ptr->totalNetPay += (emp_ptr + i)->netPay;
// Find minimum values
stats_ptr->minWage = findMin(stats_ptr->minWage, (emp_ptr + i)->wageRate);
stats_ptr->minHours = findMin(stats_ptr->minHours, (emp_ptr + i)->hours);
stats_ptr->minOvertimeHrs = findMin(stats_ptr->minOvertimeHrs, (emp_ptr + i)->overtimeHrs);
stats_ptr->minGrossPay = findMin(stats_ptr->minGrossPay, (emp_ptr + i)->grossPay);
stats_ptr->minStateTax = findMin(stats_ptr->minStateTax, (emp_ptr + i)->stateTax);
stats_ptr->minFedTax = findMin(stats_ptr->minFedTax, (emp_ptr + i)->fedTax);
stats_ptr->minNetPay = findMin(stats_ptr->minNetPay, (emp_ptr + i)->netPay);
// Find maximum values
stats_ptr->maxWage = findMax(stats_ptr->maxWage, (emp_ptr + i)->wageRate);
stats_ptr->maxHours = findMax(stats_ptr->maxHours, (emp_ptr + i)->hours);
stats_ptr->maxOvertimeHrs = findMax(stats_ptr->maxOvertimeHrs, (emp_ptr + i)->overtimeHrs);
stats_ptr->maxGrossPay = findMax(stats_ptr->maxGrossPay, (emp_ptr + i)->grossPay);
stats_ptr->maxStateTax = findMax(stats_ptr->maxStateTax, (emp_ptr + i)->stateTax);
stats_ptr->maxFedTax = findMax(stats_ptr->maxFedTax, (emp_ptr + i)->fedTax);
stats_ptr->maxNetPay = findMax(stats_ptr->maxNetPay, (emp_ptr + i)->netPay);
}
// Calculate averages
stats_ptr->avgWage = stats_ptr->totalWage / MAX_EMPLOYEES;
stats_ptr->avgHours = stats_ptr->totalHours / MAX_EMPLOYEES;
stats_ptr->avgOvertimeHrs = stats_ptr->totalOvertimeHrs / MAX_EMPLOYEES;
stats_ptr->avgGrossPay = stats_ptr->totalGrossPay / MAX_EMPLOYEES;
stats_ptr->avgStateTax = stats_ptr->totalStateTax / MAX_EMPLOYEES;
stats_ptr->avgFedTax = stats_ptr->totalFedTax / MAX_EMPLOYEES;
stats_ptr->avgNetPay = stats_ptr->totalNetPay / MAX_EMPLOYEES;
}
/*****************************************************************************
* Function: displayReport
*
* Purpose: Displays the complete payroll report with summary statistics using pointers
*
* Parameters: emp_ptr - pointer to array of employee structures
*
* Returns: void
*****************************************************************************/
void displayReport(struct employee *emp_ptr) {
struct summaryStats stats; // structure for summary statistics
int i; // loop counter
char fullName[25]; // buffer for full name
calculateSummaryStats(emp_ptr, &stats); // Calculate statistics
// Display report header
printf("\n*** Pay Calculator ***\n"); printf("---------------------------------------------------------------------------------\n"); printf("Name Tax Clock# Wage Hours OT Gross State Fed Net\n"); printf(" State Pay Tax Tax Pay\n"); printf("---------------------------------------------------------------------------------\n");
// Display employee data using pointer arithmetic
for(i = 0; i < MAX_EMPLOYEES; i++) {
sprintf(fullName
, "%s %s", (emp_ptr
+ i
)->empName.
firstName, (emp_ptr
+ i
)->empName.
lastName); // Create full name
printf("%-18s %-3s %06ld %5.2f %5.1f %4.1f %7.2f %5.2f %6.2f %7.2f\n", fullName,
(emp_ptr + i)->taxState,
(emp_ptr + i)->clockNumber,
(emp_ptr + i)->wageRate,
(emp_ptr + i)->hours,
(emp_ptr + i)->overtimeHrs,
(emp_ptr + i)->grossPay,
(emp_ptr + i)->stateTax,
(emp_ptr + i)->fedTax,
(emp_ptr + i)->netPay);
}
// Display summary statistics
printf("---------------------------------------------------------------------------------\n"); printf("Totals: %5.2f %5.1f %4.1f %7.2f %5.2f %6.2f %7.2f\n", stats.totalWage, stats.totalHours, stats.totalOvertimeHrs,
stats.totalGrossPay, stats.totalStateTax, stats.totalFedTax, stats.totalNetPay);
printf("Averages: %5.2f %5.1f %4.1f %7.2f %5.2f %6.2f %7.2f\n", stats.avgWage, stats.avgHours, stats.avgOvertimeHrs,
stats.avgGrossPay, stats.avgStateTax, stats.avgFedTax, stats.avgNetPay);
printf("Minimum: %5.2f %5.1f %4.1f %7.2f %5.2f %6.2f %7.2f\n", stats.minWage, stats.minHours, stats.minOvertimeHrs,
stats.minGrossPay, stats.minStateTax, stats.minFedTax, stats.minNetPay);
printf("Maximum: %5.2f %5.1f %4.1f %7.2f %5.2f %6.2f %7.2f\n", stats.maxWage, stats.maxHours, stats.maxOvertimeHrs,
stats.maxGrossPay, stats.maxStateTax, stats.maxFedTax, stats.maxNetPay);
}
/*****************************************************************************
* Function: main
*
* Purpose: Program entry point - orchestrates the payroll calculation process using pointers
*
* Parameters: none
*
* Returns: int - program exit status
*****************************************************************************/
int main() {
struct employee employees[MAX_EMPLOYEES]; // employee data array
struct employee *emp_ptr = employees; // pointer to employee array
// Execute payroll processing steps using pointers
initializeEmployees(emp_ptr); // Initialize employee data
getEmployeeHours(emp_ptr); // Read hours worked
computeOvertime(emp_ptr); // Calculate overtime
computeGrossPay(emp_ptr); // Calculate gross pay
computeTaxesAndNetPay(emp_ptr); // Calculate taxes and net pay
displayReport(emp_ptr); // Display final report
return 0; // Program success
}