//********************************************************
//
// Assignment 11 - Object Oriented Design
//
// Name: <Kyle Merrihew>
//
// Class: C Programming, <Spring 2025>
//
// Date: <April 25,2025>
//
// 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 FED_TAX_RATE 0.25
#define FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
using namespace std;
// class Employee
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; // Fed Tax
float netPay; // Net Pay
// private member function to calculate Overtime Hours
float calcOverTimeHrs ( )
{
if (hours > STD_HOURS)
overTimeHrs = hours - STD_HOURS; // ot hours
else
overTimeHrs = 0; // no ot hours
return (overTimeHrs);
}
// private member function to calculate Gross Pay
float calcGrossPay ( )
{
if (overTimeHrs > 0)
{
grossPay = (STD_HOURS * wageRate) + (overTimeHrs * (wageRate * OT_RATE)); // ot pay
}
else
{
grossPay = wageRate * hours; // normal pay
}
return (grossPay);
}
// private member function to calculate State Tax
float calcStateTax ()
{
float theStateTax = grossPay; // initialize to gross pay
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; // any other state
return (theStateTax);
}
// private member function to calculate Federal Tax
float calcFedTax ()
{
return grossPay * FED_TAX_RATE;
}
// private member function to 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;
// Convert taxState 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;
overTimeHrs = calcOverTimeHrs();
grossPay = calcGrossPay();
stateTax = calcStateTax();
fedTax = calcFedTax();
netPay = calcNetPay();
}
// Getter functions
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; }
// Function to display entered details
void printEnteredDetails()
{
cout << "*** Entered Details are ***" << endl;
cout << endl;
cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "Tax State: " << taxState << endl;
cout << "Clock Number: " << clockNumber << endl;
cout << "Wage Rate: " << fixed << setprecision(2) << wageRate << endl;
cout << "Hours: " << fixed << setprecision(2) << hours << endl;
}
// Function to display calculated values
void printCalculatedValues()
{
cout << "*** Calculated Values are ***" << endl;
cout << endl;
cout << "Overtime Hours : " << fixed << setprecision(2) << overTimeHrs << endl;
cout << "Gross Pay : $" << fixed << setprecision(2) << grossPay << endl;
cout << "State Tax : $" << fixed << setprecision(2) << stateTax << endl;
cout << "Federal Tax : $" << fixed << setprecision(2) << fedTax << endl;
cout << "Net Pay : $" << fixed << setprecision(2) << netPay << endl;
}
};
int main()
{
string myFirstName, myLastName, myTaxState;
int myClockNumber;
float myWageRate, myHours;
Employee e[EMP_SIZE];
for (int i = 0; i < EMP_SIZE; ++i)
{
cout << "\nEnter Employee First Name: ";
cin >> myFirstName;
cout << "Enter Employee Last Name: ";
cin >> myLastName;
cout << "Enter Employee Tax State: ";
cin >> myTaxState;
cout << "Enter Employee Clock Number: ";
cin >> myClockNumber;
cout << "Enter Employee Hourly Wage Rate: ";
cin >> myWageRate;
cout << "Enter Employee Hours Worked for the Week: ";
cin >> myHours;
// Create employee object
e[i] = Employee(myFirstName, myLastName, myTaxState, myClockNumber, myWageRate, myHours);
// Print entered details and calculated values
e[i].printEnteredDetails();
e[i].printCalculatedValues();
}
return 0;
}