//********************************************************
//
// Assignment 11 - Object Oriented Design
//
// Name: Anthony Principe
//
// Class: C Programming, Fall 2025
//
// Date: 11/30/25
//
// 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> // std::setprecision, std::setw
#include <iostream> // std::cout, std::fixed
#include <string> // string functions
// define constants
#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 NAME_SIZE 20
#define TAX_STATE_SIZE 3
#define FED_TAX_RATE 0.25
#define FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
using namespace std;
//**************************************************************
// class Employee
//
// Contains all employee data items plus private calculation
// functions that compute overtime, gross pay, taxes, and net pay.
//**************************************************************
class Employee
{
private:
// private data available only to member functions
string firstName; // Employee First Name
string lastName; // Employee Last Name
string taxState; // Employee Tax State
int clockNumber; // Employee Clock Number
float wageRate; // Hourly Wage Rate
float hours; // Hours worked in a week
float overTimeHrs; // Overtime Hours worked
float grossPay; // Weekly Gross Pay
float stateTax; // State Tax
float fedTax; // Federal Tax
float netPay; // Net Pay (take home amount)
// private member function to calculate Overtime Hours
float calcOverTimeHrs ( )
{
// Determine overtime based on standard hours
if (hours > STD_HOURS)
overTimeHrs = hours - STD_HOURS;
else
overTimeHrs = 0;
return overTimeHrs;
}
// private member function to calculate Gross Pay
float calcGrossPay ( )
{
// Check for overtime and calculate appropriately
if (overTimeHrs > 0)
{
grossPay = (STD_HOURS * wageRate)
+ (overTimeHrs * (wageRate * OT_RATE));
}
else
{
grossPay = wageRate * hours;
}
return grossPay;
}
// private member function to calculate State Tax
float calcStateTax ()
{
float theStateTax = grossPay; // initialize with gross pay
// compute based on employee's state
if (taxState.compare("MA") == 0)
theStateTax *= MA_TAX_RATE;
else if (taxState.compare("VT") == 0)
theStateTax *= VT_TAX_RATE;
else if (taxState.compare("NH") == 0)
theStateTax *= NH_TAX_RATE;
else if (taxState.compare("CA") == 0)
theStateTax *= CA_TAX_RATE;
else
theStateTax *= DEFAULT_TAX_RATE; // for all other states
return theStateTax;
}
// private member function to calculate Federal Tax
float calcFedTax ()
{
float theFedTax;
// federal tax applies uniformly
theFedTax = grossPay * FED_TAX_RATE;
return theFedTax;
}
// private member function to calculate Net Pay
float calcNetPay ()
{
float theTotalTaxes; // combined tax burden
float theNetPay; // resulting take-home pay
theTotalTaxes = stateTax + fedTax;
theNetPay = grossPay - theTotalTaxes;
return theNetPay;
}
public:
// public no argument constructor with defaults
Employee() {
firstName = "";
lastName = "";
taxState = "";
clockNumber = 0;
wageRate = 0;
hours = 0;
overTimeHrs = 0;
grossPay = 0;
stateTax = 0;
fedTax = 0;
netPay = 0;
}
// public constructor with arguments passed to it
Employee (string myFirstName, string myLastName, string myTaxState,
int myClockNumber, float myWageRate, float myHours);
~Employee(); // destructor
// public getter function prototypes
string getFirstName();
string getLastName();
string getTaxState();
int getClockNumber();
float getWageRate();
float getHours();
float getOverTimeHrs();
float getGrossPay();
// newly added getter functions
float getStateTax();
float getFedTax();
float getNetPay();
// member function to print an Employee object
void printEmployee(Employee e);
}; // class Employee
//**************************************************************
// Constructor with arguments
//**************************************************************
Employee::Employee (string myFirstName, string myLastName, string myTaxState,
int myClockNumber, float myWageRate, float myHours)
{
// Initialize and/or set all inputted member data items
firstName = myFirstName;
lastName = myLastName;
// Convert tax state to uppercase
if (std::islower(myTaxState[0]))
myTaxState[0] = std::toupper(myTaxState[0]);
if (std::islower(myTaxState[1]))
myTaxState[1] = std::toupper(myTaxState[1]);
taxState = myTaxState;
clockNumber = myClockNumber;
wageRate = myWageRate;
hours = myHours;
// Perform calculations using private functions
overTimeHrs = calcOverTimeHrs();
grossPay = calcGrossPay();
stateTax = calcStateTax();
fedTax = calcFedTax();
netPay = calcNetPay();
}
// destructor
Employee::~Employee()
{
// Nothing special for this assignment
}
//**************************************************************
// Getter functions
//**************************************************************
string Employee::getFirstName() { return firstName; }
string Employee::getLastName() { return lastName; }
string Employee::getTaxState() { return taxState; }
int Employee::getClockNumber() { return clockNumber; }
float Employee::getWageRate() { return wageRate; }
float Employee::getHours() { return hours; }
float Employee::getOverTimeHrs(){ return overTimeHrs; }
float Employee::getGrossPay() { return grossPay; }
// new getters
float Employee::getStateTax() { return stateTax; }
float Employee::getFedTax() { return fedTax; }
float Employee::getNetPay() { return netPay; }
//**************************************************************
// Function: printEmployee
//
// Prints all input fields and all calculated values.
//**************************************************************
void Employee::printEmployee(Employee e) {
// Display the inputted values
cout<<"\n\n *** Entered Details are *** \n";
cout<<"\n First Name: " << e.getFirstName();
cout<<"\n Last Name: " << e.getLastName();
cout<<"\n Tax State: " << e.getTaxState();
cout<<"\n Clock Number: " << e.getClockNumber();
cout<<"\n Wage Rate: " << e.getWageRate();
cout<<"\n Hours: " << e.getHours();
// Display the calculated values
cout<<"\n\n *** Calculated Values are *** \n";
cout<<"\n Overtime Hours : " << e.getOverTimeHrs();
cout<<"\n Gross Pay : $" << e.getGrossPay();
cout<<"\n State Tax : $" << e.getStateTax();
cout<<"\n Federal Tax : $" << e.getFedTax();
cout<<"\n Net Pay : $" << e.getNetPay();
cout << "\n";
}
//**************************************************************
// main function to start the processing
//**************************************************************
int main ()
{
// Local variables to store input temporarily
string myFirstName;
string myLastName;
string myTaxState;
int myClockNumber;
float myWageRate;
float myHours;
cout << fixed << setprecision(2);
// Array of Employee objects
Employee e[EMP_SIZE];
// Read and process employee information
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;
// Create object using constructor with arguments
e[i] = {myFirstName, myLastName, myTaxState,
myClockNumber, myWageRate, myHours};
// Print all details
e[i].printEmployee(e[i]);
}
return 0;
}