//********************************************************
//
// Assignment 8 - Structures and Strings and Pointers
//
// Name: <replace with your name>
//
// Class: C Programming, <replace with Semester and Year>
//
// Date: <replace with the current date>
//
// 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.
//
// Array and Structure references are to be replaced with
// pointer references to speed up the processing of this code.
//
// Call by Reference design (using pointers)
//
//********************************************************
#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 FED_TAX_RATE 0.25
#define FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
#define TAX_STATE_SIZE 3
// Define structures
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;
};
// Define function prototypes
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, 51.0},
{{"Mary", "Apl"}, "NH", 526488, 9.75, 42.5},
{{"Frank", "Fortran"}, "VT", 765349, 10.50, 37.0},
{{"Jeff", "Ada"}, "NY", 34645, 12.25, 45.0},
{{"Anton", "Pascal"}, "CA", 127615, 8.35, 40.0}
};
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};
struct employee *emp_ptr = employeeData;
struct totals *emp_totals_ptr = &employeeTotals;
struct min_max *emp_minMax_ptr = &employeeMinMax;
getHours(emp_ptr, SIZE);
calcOvertimeHrs(emp_ptr, SIZE);
calcGrossPay(emp_ptr, SIZE);
calcStateTax(emp_ptr, SIZE);
calcFedTax(emp_ptr, SIZE);
calcNetPay(emp_ptr, SIZE);
calcEmployeeTotals(emp_ptr, emp_totals_ptr, SIZE);
calcEmployeeMinMax(emp_ptr, emp_minMax_ptr, SIZE);
printHeader();
printEmp(emp_ptr, SIZE);
printEmpStatistics(emp_totals_ptr, emp_minMax_ptr, SIZE);
return 0;
}
// Function Definitions
void getHours(struct employee *emp_ptr, int theSize) {
for (int i = 0; i < theSize; ++i, ++emp_ptr) {
// The hours are already initialized in the structure, so no user input is needed
}
}
void printHeader(void) {
printf("\n\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"); }
void printEmp(struct employee *emp_ptr, int theSize) {
char name[FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
for (int i = 0; i < theSize; ++i) {
snprintf(name
, sizeof(name
), "%s %s", emp_ptr
->empName.
firstName, emp_ptr
->empName.
lastName);
printf("%-20.20s %-2.2s %06li %5.2f %5.1f %5.1f %8.2f %7.2f %7.2f %8.2f\n", 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;
}
printf("---------------------------------------------------------------------------------\n"); }
void calcOvertimeHrs(struct employee *emp_ptr, int theSize) {
for (int i = 0; i < theSize; ++i, ++emp_ptr) {
emp_ptr->overtimeHrs = (emp_ptr->hours > STD_HOURS) ? emp_ptr->hours - STD_HOURS : 0;
}
}
void calcGrossPay(struct employee *emp_ptr, int theSize) {
for (int i = 0; i < theSize; ++i, ++emp_ptr) {
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;
}
}
void calcStateTax(struct employee *emp_ptr, int theSize) {
for (int i = 0; i < theSize; ++i, ++emp_ptr) {
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;
}
}
void calcFedTax(struct employee *emp_ptr, int theSize) {
for (int i = 0; i < theSize; ++i, ++emp_ptr) {
emp_ptr->fedTax = emp_ptr->grossPay * FED_TAX_RATE;
}
}
void calcNetPay(struct employee *emp_ptr, int theSize) {
for (int i = 0; i < theSize; ++i, ++emp_ptr) {
emp_ptr->netPay = emp_ptr->grossPay - (emp_ptr->stateTax + emp_ptr->fedTax);
}
}
void calcEmployeeTotals(struct employee *emp_ptr, struct totals *emp_totals_ptr, int theSize) {
for (int i = 0; i < theSize; ++i, ++emp_ptr) {
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;
}
}
void calcEmployeeMinMax(struct employee *emp_ptr, struct min_max *emp_minMax_ptr, int theSize) {
emp_minMax_ptr->min_wageRate = emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
emp_minMax_ptr->min_hours = emp_minMax_ptr->max_hours = emp_ptr->hours;
emp_minMax_ptr->min_overtimeHrs = emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
emp_minMax_ptr->min_grossPay = emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
emp_minMax_ptr->min_stateTax = emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
emp_minMax_ptr->min_fedTax = emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
emp_minMax_ptr->min_netPay = emp_minMax_ptr->max_netPay = emp_ptr->netPay;
for (int i = 1; i < theSize; ++i, ++emp_ptr) {
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;
}
}
void printEmpStatistics(struct totals *emp_totals_ptr, struct min_max *emp_minMax_ptr, int theSize) {
printf("Totals: %.2f %.1f %.1f %.2f %.2f %.2f %.2f\n", 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("Averages: %.2f %.1f %.1f %.2f %.2f %.2f %.2f\n", 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("Minimum: %.2f %.1f %.1f %.2f %.2f %.2f %.2f\n", 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("Maximum: %.2f %.1f %.1f %.2f %.2f %.2f %.2f\n", 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);
}
Ly8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgovLwovLyBBc3NpZ25tZW50IDggLSBTdHJ1Y3R1cmVzIGFuZCBTdHJpbmdzIGFuZCBQb2ludGVycwovLwovLyBOYW1lOiA8cmVwbGFjZSB3aXRoIHlvdXIgbmFtZT4KLy8KLy8gQ2xhc3M6IEMgUHJvZ3JhbW1pbmcsIDxyZXBsYWNlIHdpdGggU2VtZXN0ZXIgYW5kIFllYXI+Ci8vCi8vIERhdGU6IDxyZXBsYWNlIHdpdGggdGhlIGN1cnJlbnQgZGF0ZT4KLy8KLy8gRGVzY3JpcHRpb246IFByb2dyYW0gd2hpY2ggZGV0ZXJtaW5lcyBvdmVydGltZSBhbmQgCi8vIGdyb3NzIHBheSBmb3IgYSBzZXQgb2YgZW1wbG95ZWVzIHdpdGggb3V0cHV0cyBzZW50IAovLyB0byBzdGFuZGFyZCBvdXRwdXQgKHRoZSBzY3JlZW4pLgovLwovLyBUaGlzIGFzc2lnbm1lbnQgYWxzbyBhZGRzIHRoZSBlbXBsb3llZSBuYW1lLCB0aGVpciB0YXggc3RhdG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ICAgICAgICAgICAgICAgICAgICAgICAgJS4yZiAlLjFmICUuMWYgJS4yZiAlLjJmICUuMmYgJS4yZlxuIiwKICAgICAgICAgICAgICAgZW1wX3RvdGFsc19wdHItPnRvdGFsX3dhZ2VSYXRlIC8gdGhlU2l6ZSwKICAgICAgICAgICAgICAgZW1wX3RvdGFsc19wdHItPnRvdGFsX2hvdXJzIC8gdGhlU2l6ZSwKICAgICAgICAgICAgICAgZW1wX3RvdGFsc19wdHItPnRvdGFsX292ZXJ0aW1lSHJzIC8gdGhlU2l6ZSwKICAgICAgICAgICAgICAgZW1wX3RvdGFsc19wdHItPnRvdGFsX2dyb3NzUGF5IC8gdGhlU2l6ZSwKICAgICAgICAgICAgICAgZW1wX3RvdGFsc19wdHItPnRvdGFsX3N0YXRlVGF4IC8gdGhlU2l6ZSwKICAgICAgICAgICAgICAgZW1wX3RvdGFsc19wdHItPnRvdGFsX2ZlZFRheCAvIHRoZVNpemUsCiAgICAgICAgICAgICAgIGVtcF90b3RhbHNfcHRyLT50b3RhbF9uZXRQYXkgLyB0aGVTaXplKTsKICAgIH0KCiAgICBwcmludGYoIk1pbmltdW06ICAgICAgICAgICAgICAgICAgICAgICAgICUuMmYgJS4xZiAlLjFmICUuMmYgJS4yZiAlLjJmICUuMmZcbiIsCiAgICAgICAgICAgZW1wX21pbk1heF9wdHItPm1pbl93YWdlUmF0ZSwgZW1wX21pbk1heF9wdHItPm1pbl9ob3VycywKICAgICAgICAgICBlbXBfbWluTWF4X3B0ci0+bWluX292ZXJ0aW1lSHJzLCBlbXBfbWluTWF4X3B0ci0+bWluX2dyb3NzUGF5LAogICAgICAgICAgIGVtcF9taW5NYXhfcHRyLT5taW5fc3RhdGVUYXgsIGVtcF9taW5NYXhfcHRyLT5taW5fZmVkVGF4LAogICAgICAgICAgIGVtcF9taW5NYXhfcHRyLT5taW5fbmV0UGF5KTsKCiAgICBwcmludGYoIk1heGltdW06ICAgICAgICAgICAgICAgICAgICAgICAgICUuMmYgJS4xZiAlLjFmICUuMmYgJS4yZiAlLjJmICUuMmZcbiIsCiAgICAgICAgICAgZW1wX21pbk1heF9wdHItPm1heF93YWdlUmF0ZSwgZW1wX21pbk1heF9wdHItPm1heF9ob3VycywKICAgICAgICAgICBlbXBfbWluTWF4X3B0ci0+bWF4X292ZXJ0aW1lSHJzLCBlbXBfbWluTWF4X3B0ci0+bWF4X2dyb3NzUGF5LAogICAgICAgICAgIGVtcF9taW5NYXhfcHRyLT5tYXhfc3RhdGVUYXgsIGVtcF9taW5NYXhfcHRyLT5tYXhfZmVkVGF4LAogICAgICAgICAgIGVtcF9taW5NYXhfcHRyLT5tYXhfbmV0UGF5KTsKfQo=