//********************************************************
//
// Assignment 8 - Pointers
//
// Name: Heather Grothe
//
// Class: C Programming, Spring 2026
//
// Date: April 2, 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.
//
// Pointer 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;
};
// this structure type defines the totals of all floating point items
struct totals
{
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
// this structure type defines the min and max values of all floating
// point items so they can be display in our final report
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;
};
// define prototypes here for each function except main
float getHours (long int clockNumber);
float calcOvertimeHrs (float hours);
float calcGrossPay (float wageRate, float hours, float overtimeHrs);
void printHeader (void);
void printEmp (struct employee * emp_ptr);
float calcStateTax (float grossPay, char taxState[]);
float calcFedTax (float grossPay);
float calcNetPay (float grossPay, float stateTax, float fedTax);
void calcEmployeeTotals (struct employee * emp_ptr,
struct totals * emp_totals_ptr);
void calcEmployeeMinMax (struct employee * emp_ptr,
struct min_max * emp_minMax_ptr,
int arrayIndex);
void printEmpStatistics (struct totals * emp_totals_ptr,
struct min_max * emp_minMax_ptr,
int theSize);
int main ()
{
int i; // loop and array index
// Set up a local variable to store the employee information
// Initialize the name, tax state, clock number, and wage rate
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 }
};
// pointer to the array of employee structures
struct employee * emp_ptr;
// set the pointer to point to the array of employees
emp_ptr = employeeData;
// set up structure to store totals and initialize all to zero
struct totals employeeTotals = {0,0,0,0,0,0,0};
// pointer to the employeeTotals structure
struct totals * emp_totals_ptr = &employeeTotals;
// set up structure to store min and max values and initialize all to zero
struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
// pointer to the employeeMinMax structure
struct min_max * emp_minMax_ptr = &employeeMinMax;
// Call functions as needed to read and calculate information
for (i = 0; i < SIZE; ++i)
{
// Prompt for the number of hours worked by the employee
(emp_ptr + i)->hours = getHours ((emp_ptr + i)->clockNumber);
// Calculate the overtime hours
(emp_ptr + i)->overtimeHrs = calcOvertimeHrs ((emp_ptr + i)->hours);
// Calculate the weekly gross pay
(emp_ptr + i)->grossPay = calcGrossPay ((emp_ptr + i)->wageRate,
(emp_ptr + i)->hours,
(emp_ptr + i)->overtimeHrs);
// Calculate the state tax
(emp_ptr + i)->stateTax = calcStateTax ((emp_ptr + i)->grossPay,
(emp_ptr + i)->taxState);
// Calculate the federal tax
(emp_ptr + i)->fedTax = calcFedTax ((emp_ptr + i)->grossPay);
// Calculate the net pay after taxes
(emp_ptr + i)->netPay = calcNetPay ((emp_ptr + i)->grossPay,
(emp_ptr + i)->stateTax,
(emp_ptr + i)->fedTax);
// Keep a running sum of the employee totals
calcEmployeeTotals ((emp_ptr + i), emp_totals_ptr);
// Keep a running update of the employee minimum and maximum values
calcEmployeeMinMax ((emp_ptr + i), emp_minMax_ptr, i);
} // for
// Print the column headers
printHeader();
// print out final information on each employee
for (i = 0; i < SIZE; ++i)
{
printEmp (emp_ptr + i);
} // for
// print the totals and averages for all float items
printEmpStatistics (emp_totals_ptr, emp_minMax_ptr, SIZE);
return (0); // success
} // main
//**************************************************************
// 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: theHoursWorked - hours worked in a given week
//
//**************************************************************
float getHours (long int clockNumber)
{
float theHoursWorked; // hours worked in a given week
// Read in hours for employee
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf ("%f", &theHoursWorked
);
// return hours back to the calling function
return (theHoursWorked);
} // getHours
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printHeader (void)
{
printf ("\n\n*** Pay Calculator ***\n");
// print the table header
printf("\n--------------------------------------------------------------"); printf("-------------------"); printf("\nName Tax Clock# Wage Hours OT Gross State Fed Net"); printf("\n State Pay Tax Tax Pay"); printf("\n--------------------------------------------------------------"); printf("-------------------");
} // printHeader
//*************************************************************
// Function: printEmp
//
// Purpose: Prints out all the information for an employee
// in a nice and orderly table format.
//
// Parameters:
//
// emp_ptr - pointer to one employee structure
//
// Returns: void
//
//**************************************************************
void printEmp (struct employee * emp_ptr)
{
// Used to format the employee name
char name [FIRST_NAME_SIZE + LAST_NAME_SIZE + 2];
strcpy (name
, emp_ptr
->empName.
firstName); strcat (name
, emp_ptr
->empName.
lastName);
// Print out a single employee
printf("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f", name, emp_ptr->taxState, emp_ptr->clockNumber, emp_ptr->wageRate, emp_ptr->hours,
emp_ptr->overtimeHrs, emp_ptr->grossPay, emp_ptr->stateTax, emp_ptr->fedTax, emp_ptr->netPay);
} // printEmp
//*************************************************************
// Function: printEmpStatistics
//
// Purpose: Prints out the totals and averages of all
// floating point value items for all employees
// that have been processed.
//
// Parameters:
//
// emp_totals_ptr - pointer to a structure containing a running total
// of all employee floating point items
// emp_minMax_ptr - pointer to a structure containing all the minimum
// and maximum values of all employee
// floating point items
// theSize - the total number of employees processed, used
// to check for zero or negative divide condition.
//
// Returns: void
//
//**************************************************************
void printEmpStatistics (struct totals * emp_totals_ptr,
struct min_max * emp_minMax_ptr,
int theSize)
{
// print a separator line
printf("\n--------------------------------------------------------------"); printf("-------------------");
// print the totals for all the floating point fields
printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", emp_totals_ptr->total_wageRate,
emp_totals_ptr->total_hours,
emp_totals_ptr->total_overtimeHrs,
emp_totals_ptr->total_grossPay,
emp_totals_ptr->total_stateTax,
emp_totals_ptr->total_fedTax,
emp_totals_ptr->total_netPay);
// make sure you don't divide by zero or a negative number
if (theSize > 0)
{
// print the averages for all the floating point fields
printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", emp_totals_ptr->total_wageRate/theSize,
emp_totals_ptr->total_hours/theSize,
emp_totals_ptr->total_overtimeHrs/theSize,
emp_totals_ptr->total_grossPay/theSize,
emp_totals_ptr->total_stateTax/theSize,
emp_totals_ptr->total_fedTax/theSize,
emp_totals_ptr->total_netPay/theSize);
} // if
// print the min values
printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", emp_minMax_ptr->min_wageRate,
emp_minMax_ptr->min_hours,
emp_minMax_ptr->min_overtimeHrs,
emp_minMax_ptr->min_grossPay,
emp_minMax_ptr->min_stateTax,
emp_minMax_ptr->min_fedTax,
emp_minMax_ptr->min_netPay);
// print the max values
printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", emp_minMax_ptr->max_wageRate,
emp_minMax_ptr->max_hours,
emp_minMax_ptr->max_overtimeHrs,
emp_minMax_ptr->max_grossPay,
emp_minMax_ptr->max_stateTax,
emp_minMax_ptr->max_fedTax,
emp_minMax_ptr->max_netPay);
} // printEmpStatistics
//*************************************************************
// Function: calcOvertimeHrs
//
// Purpose: Calculates the overtime hours worked by an employee
// in a given week.
//
// Parameters:
//
// hours - Hours worked in a given week
//
// Returns: theOvertimeHrs - overtime hours worked by an employee
// in a given week
//
//**************************************************************
float calcOvertimeHrs (float hours)
{
float theOvertimeHrs; // calculated overtime hours for employee
// Any overtime ?
if (hours >= STD_HOURS)
{
theOvertimeHrs = hours - STD_HOURS;
}//if
else
{
theOvertimeHrs = 0;
}//else
// return overtime hours back to the calling function
return (theOvertimeHrs);
} // calcOvertimeHrs
//*************************************************************
// Function: calcGrossPay
//
// Purpose: Calculates the gross pay based on the the normal pay
// and any overtime pay for a given week.
//
// Parameters:
//
// wageRate - the hourly wage rate
// hours - the hours worked in a given week
// overtimeHrs - hours worked above normal hours
//
// Returns: theGrossPay - total weekly gross pay for an employee
//
//**************************************************************
float calcGrossPay (float wageRate, float hours, float overtimeHrs)
{
float theGrossPay; // gross pay earned in a given week
float theNormalPay; // normal pay without any overtime hours
float theOvertimePay; // overtime pay
// calculate normal pay and any overtime pay
theNormalPay = wageRate * (hours - overtimeHrs);
theOvertimePay = overtimeHrs * (OT_RATE * wageRate);
// calculate gross pay for employee as normalPay + any overtime pay
theGrossPay = theNormalPay + theOvertimePay;
// return the calculated gross pay value back
return (theGrossPay);
} // calcGrossPay
//*************************************************************
// Function: calcStateTax
//
// Purpose: Calculates the State Tax owed based on gross pay
//
// Parameters:
//
// grossPay - the grossPay for a given week
// taxState - the physical state where the employee works
//
// Returns: theStateTax - calculated state tax owed
//
//**************************************************************
float calcStateTax (float grossPay, char taxState[])
{
float theStateTax; // calculated state tax
theStateTax = grossPay;
// Make sure tax state is all uppercase
{
taxState
[0] = toupper(taxState
[0]); }//if
{
taxState
[1] = toupper(taxState
[1]); }//if
// calculate state tax based on where employee resides
if (strcmp(taxState
, "MA") == 0) {
theStateTax *= MA_TAX_RATE;
}//if
else if (strcmp(taxState
, "NH") == 0) {
theStateTax *= NH_TAX_RATE;
}//else if
else if (strcmp(taxState
, "VT") == 0) {
theStateTax *= VT_TAX_RATE;
}//else if
else if (strcmp(taxState
, "CA") == 0) {
theStateTax *= CA_TAX_RATE;
}//else if
else
{
theStateTax *= DEFAULT_TAX_RATE;
}//else
// return the calculated state tax back
return (theStateTax);
} // calcStateTax
//*************************************************************
// Function: calcFedTax
//
// Purpose: Calculates the Federal Tax owed based on the gross
// pay
//
// Parameters:
//
// grossPay - the grossPay for a given week
//
// Returns: theFedTax - calculated federal tax owed
//
//**************************************************************
float calcFedTax (float grossPay)
{
float theFedTax; // The calculated Federal Tax
// Fed Tax is the same for all regardless of state
theFedTax = grossPay * FED_TAX_RATE;
// return the calculated federal tax back
return (theFedTax);
} // calcFedTax
//*************************************************************
// Function: calcNetPay
//
// Purpose: Calculates the net pay as the gross pay minus any
// state and federal taxes owed. Essentially, your
// "take home" pay.
//
// Parameters:
//
// grossPay - the grossPay for a given week
// stateTax - the state taxes owed
// fedTax - the fed taxes owed
//
// Returns: theNetPay - calculated take home pay (minus taxes)
//
//**************************************************************
float calcNetPay (float grossPay, float stateTax, float fedTax)
{
float theNetPay; // total take home pay (minus taxes)
float theTotalTaxes; // total taxes owed
// calculate the total state and federal taxes
theTotalTaxes = stateTax + fedTax;
// calculate the net pay
theNetPay = grossPay - theTotalTaxes;
// return the calculated net pay back
return (theNetPay);
} // calcNetPay
//*************************************************************
// Function: calcEmployeeTotals
//
// Purpose: Accepts a pointer to one employee structure and
// adds the float values to a running total.
//
// Parameters:
//
// emp_ptr - pointer to current employee structure
// emp_totals_ptr - pointer to structure containing running totals
//
// Returns: void
//
//**************************************************************
void calcEmployeeTotals (struct employee * emp_ptr,
struct totals * emp_totals_ptr)
{
// add current employee data to our running totals
emp_totals_ptr->total_wageRate += emp_ptr->wageRate;
emp_totals_ptr->total_hours += emp_ptr->hours;
emp_totals_ptr->total_overtimeHrs += emp_ptr->overtimeHrs;
emp_totals_ptr->total_grossPay += emp_ptr->grossPay;
emp_totals_ptr->total_stateTax += emp_ptr->stateTax;
emp_totals_ptr->total_fedTax += emp_ptr->fedTax;
emp_totals_ptr->total_netPay += emp_ptr->netPay;
} // calcEmployeeTotals
//*************************************************************
// Function: calcEmployeeMinMax
//
// Purpose: Accepts a pointer to one employee structure and
// updates the running min and max values.
//
// Parameters:
//
// emp_ptr - pointer to current employee structure
// emp_minMax_ptr - pointer to structure containing min and max values
// arrayIndex - current employee array index
//
// Returns: void
//
//**************************************************************
void calcEmployeeMinMax (struct employee * emp_ptr,
struct min_max * emp_minMax_ptr,
int arrayIndex)
{
// if this is the first set of data items, set
// them to the min and max
if (arrayIndex == 0)
{
emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
emp_minMax_ptr->min_hours = emp_ptr->hours;
emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
emp_minMax_ptr->min_netPay = emp_ptr->netPay;
emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
emp_minMax_ptr->max_hours = emp_ptr->hours;
emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
emp_minMax_ptr->max_netPay = emp_ptr->netPay;
}// if
else if (arrayIndex >=1) // process if other array elements
{
// check if current Wage Rate is the new min and/or max
if (emp_ptr->wageRate < emp_minMax_ptr->min_wageRate)
{
emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
}//if
if (emp_ptr->wageRate > emp_minMax_ptr->max_wageRate)
{
emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
}//if
if (emp_ptr->hours < emp_minMax_ptr->min_hours)
{
emp_minMax_ptr->min_hours = emp_ptr->hours;
}//if
if (emp_ptr->hours > emp_minMax_ptr->max_hours)
{
emp_minMax_ptr->max_hours = emp_ptr->hours;
}//if
if (emp_ptr->overtimeHrs < emp_minMax_ptr->min_overtimeHrs)
{
emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
}//if
if (emp_ptr->overtimeHrs > emp_minMax_ptr->max_overtimeHrs)
{
emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
}//if
if (emp_ptr->grossPay < emp_minMax_ptr->min_grossPay)
{
emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
}//if
if (emp_ptr->grossPay > emp_minMax_ptr->max_grossPay)
{
emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
}//if
if (emp_ptr->stateTax < emp_minMax_ptr->min_stateTax)
{
emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
}//if
if (emp_ptr->stateTax > emp_minMax_ptr->max_stateTax)
{
emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
}//if
if (emp_ptr->fedTax < emp_minMax_ptr->min_fedTax)
{
emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
}//if
if (emp_ptr->fedTax > emp_minMax_ptr->max_fedTax)
{
emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
}//if
if (emp_ptr->netPay < emp_minMax_ptr->min_netPay)
{
emp_minMax_ptr->min_netPay = emp_ptr->netPay;
}//if
if (emp_ptr->netPay > emp_minMax_ptr->max_netPay)
{
emp_minMax_ptr->max_netPay = emp_ptr->netPay;
}//if
}//else if
} // calcEmployeeMinMax