#include <stdio.h>
#include <string.h>
#include <ctype.h>
#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
struct name
{
char firstName[FIRST_NAME_SIZE];
char lastName[LAST_NAME_SIZE];
};
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;
};
struct totals
{
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
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;
};
void getHours(struct employee *emp_ptr, int theSize);
void printEmp(struct employee *emp_ptr, int theSize);
void calcEmployeeTotals(struct employee *emp_ptr, struct totals *emp_totals_ptr, int theSize);
void calcEmployeeMinMax(struct employee *emp_ptr, struct min_max *emp_MinMax_ptr, int theSize);
void printHeader(void);
void calcOvertimeHrs(struct employee *emp_ptr, int theSize);
void calcGrossPay(struct employee *emp_ptr, int theSize);
void calcStateTax(struct employee *emp_ptr, int theSize);
void calcFedTax(struct employee *emp_ptr, int theSize);
void calcNetPay(struct employee *emp_ptr, int theSize);
void printEmpStatistics(struct totals *emp_totals_ptr, struct min_max *emp_MinMax_ptr, int theSize);
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 employee *emp_ptr = employeeData;
struct totals employeeTotals = {0,0,0,0,0,0,0};
struct totals *emp_totals_ptr = &employeeTotals;
struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
struct min_max *emp_minMax_ptr = &employeeMinMax;
getHours(employeeData, SIZE);
calcOvertimeHrs(employeeData, SIZE);
calcGrossPay(employeeData, SIZE);
calcStateTax(employeeData, SIZE);
calcFedTax(employeeData, SIZE);
calcNetPay(employeeData, SIZE);
calcEmployeeTotals(employeeData, &employeeTotals, SIZE);
calcEmployeeMinMax(employeeData, &employeeMinMax, SIZE);
printHeader();
printEmp(employeeData, SIZE);
printEmpStatistics(&employeeTotals, &employeeMinMax, SIZE);
return 0;
}
void getHours(struct employee *emp_ptr, int theSize)
{
for (int i = 0; i < theSize; ++i)
{
printf("\nEnter hours worked by emp # %06li: ", emp_ptr
->clockNumber
); scanf("%f", &emp_ptr
->hours
); ++emp_ptr;
}
}
void printHeader(void)
{
printf("\n\n*** Pay Calculator ***\n"); printf("\n--------------------------------------------------------------"); printf("-------------------"); printf("\nName Tax Clock# Wage Hours OT Gross "); printf("\n--------------------------------------------------------------"); printf("-------------------"); }
void printEmp(struct employee *emp_ptr, int theSize)
{
for (int i = 0; i < theSize; ++i)
{
char name[FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
strcpy(name
, emp_ptr
->empName.
firstName); strcat(name
, emp_ptr
->empName.
lastName);
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);
++emp_ptr;
}
}
void calcOvertimeHrs(struct employee *emp_ptr, int theSize)
{
for (int i = 0; i < theSize; ++i)
{
if (emp_ptr->hours > STD_HOURS)
emp_ptr->overtimeHrs = emp_ptr->hours - STD_HOURS;
else
emp_ptr->overtimeHrs = 0;
++emp_ptr;
}
}
void calcGrossPay(struct employee *emp_ptr, int theSize)
{
for (int i = 0; i < theSize; ++i)
{
float normalPay = emp_ptr->wageRate * (emp_ptr->hours - emp_ptr->overtimeHrs);
float overtimePay = emp_ptr->overtimeHrs * (OT_RATE * emp_ptr->wageRate);
emp_ptr->grossPay = normalPay + overtimePay;
++emp_ptr;
}
}
void calcStateTax(struct employee *emp_ptr, int theSize)
{
for (int i = 0; i < theSize; ++i)
{
emp_ptr
->taxState
[0] = toupper(emp_ptr
->taxState
[0]); emp_ptr
->taxState
[1] = toupper(emp_ptr
->taxState
[1]);
if (strcmp(emp_ptr
->taxState
, "MA") == 0) emp_ptr->stateTax = emp_ptr->grossPay * MA_TAX_RATE;
else if (strcmp(emp_ptr
->taxState
, "VT") == 0) emp_ptr->stateTax = emp_ptr->grossPay * VT_TAX_RATE;
else if (strcmp(emp_ptr
->taxState
, "NH") == 0) emp_ptr->stateTax = emp_ptr->grossPay * NH_TAX_RATE;
else if (strcmp(emp_ptr
->taxState
, "CA") == 0) emp_ptr->stateTax = emp_ptr->grossPay * CA_TAX_RATE;
else
emp_ptr->stateTax = emp_ptr->grossPay * DEFAULT_TAX_RATE;
++emp_ptr;
}
}
void calcFedTax(struct employee *emp_ptr, int theSize)
{
for (int i = 0; i < theSize; ++i)
{
emp_ptr->fedTax = emp_ptr->grossPay * FED_TAX_RATE;
++emp_ptr;
}
}
void calcNetPay(struct employee *emp_ptr, int theSize)
{
for (int i = 0; i < theSize; ++i)
{
emp_ptr->netPay = emp_ptr->grossPay - (emp_ptr->stateTax + emp_ptr->fedTax);
++emp_ptr;
}
}
void calcEmployeeTotals(struct employee *emp_ptr, struct totals *emp_totals_ptr, int theSize)
{
for (int i = 0; i < theSize; ++i)
{
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;
++emp_ptr;
}
}
void calcEmployeeMinMax(struct employee *emp_ptr, struct min_max *emp_minMax_ptr, int theSize)
{
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;
++emp_ptr;
for (int i = 1; i < theSize; ++i)
{
if (emp_ptr->wageRate < emp_minMax_ptr->min_wageRate)
emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
if (emp_ptr->wageRate > emp_minMax_ptr->max_wageRate)
emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
if (emp_ptr->hours < emp_minMax_ptr->min_hours)
emp_minMax_ptr->min_hours = emp_ptr->hours;
if (emp_ptr->hours > emp_minMax_ptr->max_hours)
emp_minMax_ptr->max_hours = emp_ptr->hours;
if (emp_ptr->overtimeHrs < emp_minMax_ptr->min_overtimeHrs)
emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
if (emp_ptr->overtimeHrs > emp_minMax_ptr->max_overtimeHrs)
emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
if (emp_ptr->grossPay < emp_minMax_ptr->min_grossPay)
emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
if (emp_ptr->grossPay > emp_minMax_ptr->max_grossPay)
emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
if (emp_ptr->stateTax < emp_minMax_ptr->min_stateTax)
emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
if (emp_ptr->stateTax > emp_minMax_ptr->max_stateTax)
emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
if (emp_ptr->fedTax < emp_minMax_ptr->min_fedTax)
emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
if (emp_ptr->fedTax > emp_minMax_ptr->max_fedTax)
emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
if (emp_ptr->netPay < emp_minMax_ptr->min_netPay)
emp_minMax_ptr->min_netPay = emp_ptr->netPay;
if (emp_ptr->netPay > emp_minMax_ptr->max_netPay)
emp_minMax_ptr->max_netPay = emp_ptr->netPay;
++emp_ptr;
}
}
void printEmpStatistics(struct totals *emp_totals_ptr, struct min_max *emp_minMax_ptr, int theSize)
{
printf("\n--------------------------------------------------------------"); printf("-------------------");
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);
if (theSize > 0)
{
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);
}
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);
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);
}