//********************************************************
//
// Assignment 11 - Object Oriented Design
//
// Name: John Nguyen
//
// Class: C Programming, Fall 2024
//
// Date: 12/1/2024
//
// Description: An object oriented program design using
// C++ that will process our existing set of employees.
// It utilizes a class called Employee and generates an
// array of objects that are used to store, calculate,
// and print out a simple report of inputted and calculated
// values.
//
//
// Object Oriented Design (using C++)
//
//********************************************************
#include <iomanip>
#include <iostream>
#include <string>
#define EMP_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
using namespace std;
class Employee {
private:
string firstName;
string lastName;
string taxState;
int clockNumber;
float wageRate;
float hours;
float overTimeHrs;
float grossPay;
float stateTax;
float fedTax;
float netPay;
// Calculate overtime hours
float calcOverTimeHrs() {
return (hours > STD_HOURS) ? (hours - STD_HOURS) : 0;
}
// Calculate gross pay
float calcGrossPay() {
if (overTimeHrs > 0) {
return (STD_HOURS * wageRate) + (overTimeHrs * wageRate * OT_RATE);
}
return wageRate * hours;
}
// Calculate state tax
float calcStateTax() {
float taxRate;
if (taxState == "MA") taxRate = MA_TAX_RATE;
else if (taxState == "NH") taxRate = NH_TAX_RATE;
else if (taxState == "VT") taxRate = VT_TAX_RATE;
else if (taxState == "CA") taxRate = CA_TAX_RATE;
else taxRate = DEFAULT_TAX_RATE;
return grossPay * taxRate;
}
// Calculate federal tax
float calcFedTax() {
return grossPay * FED_TAX_RATE;
}
// Calculate net pay
float calcNetPay() {
return grossPay - (stateTax + fedTax);
}
public:
Employee() : firstName(""), lastName(""), taxState(""), clockNumber(0), wageRate(0), hours(0) {}
Employee(string myFirstName, string myLastName, string myTaxState, int myClockNumber, float myWageRate, float myHours) {
firstName = myFirstName;
lastName = myLastName;
taxState = myTaxState;
clockNumber = myClockNumber;
wageRate = myWageRate;
hours = myHours;
overTimeHrs = calcOverTimeHrs();
grossPay = calcGrossPay();
stateTax = calcStateTax();
fedTax = calcFedTax();
netPay = calcNetPay();
}
string getFirstName() { return firstName; }
string getLastName() { return lastName; }
string getTaxState() { return taxState; }
int getClockNumber() { return clockNumber; }
float getWageRate() { return wageRate; }
float getHours() { return hours; }
float getOverTimeHrs() { return overTimeHrs; }
float getGrossPay() { return grossPay; }
float getStateTax() { return stateTax; }
float getFedTax() { return fedTax; }
float getNetPay() { return netPay; }
void printEmployee() {
cout << "\n\n *** Entered Details are *** \n";
cout << "\n First Name: " << getFirstName();
cout << "\n Last Name: " << getLastName();
cout << "\n Tax State: " << getTaxState();
cout << "\n Clock Number: " << getClockNumber();
cout << "\n Wage Rate: $" << getWageRate();
cout << "\n Hours: " << getHours();
cout << "\n\n *** Calculated Values are *** \n";
cout << "\n Overtime Hours : " << getOverTimeHrs();
cout << "\n Gross Pay : $" << getGrossPay();
cout << "\n State Tax : $" << getStateTax();
cout << "\n Federal Tax : $" << getFedTax();
cout << "\n Net Pay : $" << getNetPay();
cout << "\n";
}
};
int main() {
string myFirstName, myLastName, myTaxState;
int myClockNumber;
float myWageRate, myHours;
Employee e[EMP_SIZE];
for (int i = 0; i < EMP_SIZE; ++i) {
cout << "\n\n Enter Employee First Name: ";
cin >> myFirstName;
cout << "\n Enter Employee Last Name: ";
cin >> myLastName;
cout << "\n Enter Employee Tax State: ";
cin >> myTaxState;
cout << "\n Enter Employee Clock Number: ";
cin >> myClockNumber;
cout << "\n Enter Employee Hourly Wage Rate: ";
cin >> myWageRate;
cout << "\n Enter Employee Hours Worked for the Week: ";
cin >> myHours;
e[i] = {myFirstName, myLastName, myTaxState, myClockNumber, myWageRate, myHours};
e[i].printEmployee();
}
return 0;
}