//********************************************************
//
// Assignment 11 - Object Oriented Design
//
// Name: <replace with your name>
//
// Class: C Programming, <replace with Semester and Year>
//
// Date: <replace with the current date>
//
// 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> // setprecision, setw
#include <iostream> // cout, cin, fixed
#include <string> // string functions
#include <cctype> // islower, toupper
using namespace std;
// Define constants
#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
#define EMP_SIZE 5
//********************************************************
// Class Employee
//********************************************************
class Employee
{
private:
// Private data members
string firstName = "";
string lastName = "";
string taxState = "";
int clockNumber = 0;
float wageRate = 0.0;
float hours = 0.0;
float overTimeHrs = 0.0;
float grossPay = 0.0;
float stateTax = 0.0;
float fedTax = 0.0;
float netPay = 0.0;
// Private calculation functions
float calcOverTimeHrs();
float calcGrossPay();
float calcStateTax();
float calcFedTax();
float calcNetPay();
// Getter function declarations
string getFirstName();
string getLastName();
string getTaxState();
int getClockNumber();
float getWageRate();
float getHours();
float getOverTimeHrs();
float getGrossPay();
float getStateTax();
float getFedTax();
float getNetPay();
public:
// Default constructor
Employee() {}
// Constructor with arguments
Employee(string myFirstName, string myLastName,
string myTaxState, int myClockNumber,
float myWageRate, float myHours);
// Destructor
~Employee();
// Print employee information
void printEmployee();
}; // End Employee class
//********************************************************
// Inline Getter Functions
//********************************************************
// Retrieve First Name
inline string Employee::getFirstName()
{
return firstName;
}
// Retrieve Last Name
inline string Employee::getLastName()
{
return lastName;
}
// Retrieve Tax State
inline string Employee::getTaxState()
{
return taxState;
}
// Retrieve Clock Number
inline int Employee::getClockNumber()
{
return clockNumber;
}
// Retrieve Wage Rate
inline float Employee::getWageRate()
{
return wageRate;
}
// Retrieve Hours Worked
inline float Employee::getHours()
{
return hours;
}
// Retrieve Overtime Hours
inline float Employee::getOverTimeHrs()
{
return overTimeHrs;
}
// Retrieve Gross Pay
inline float Employee::getGrossPay()
{
return grossPay;
}
// Retrieve State Tax
inline float Employee::getStateTax()
{
return stateTax;
}
// Retrieve Federal Tax
inline float Employee::getFedTax()
{
return fedTax;
}
// Retrieve Net Pay
inline float Employee::getNetPay()
{
return netPay;
}
//********************************************************
// Calculate Overtime Hours
//********************************************************
float Employee::calcOverTimeHrs()
{
if (hours > STD_HOURS)
overTimeHrs = hours - STD_HOURS;
else
overTimeHrs = 0;
return overTimeHrs;
} // calcOverTimeHrs
//********************************************************
// Calculate Gross Pay
//********************************************************
float Employee::calcGrossPay()
{
if (overTimeHrs > 0)
{
// Regular pay plus overtime pay
grossPay = (STD_HOURS * wageRate)
+ (overTimeHrs * (wageRate * OT_RATE));
}
else
{
// Regular pay only
grossPay = wageRate * hours;
}
return grossPay;
} // calcGrossPay
//********************************************************
// Calculate State Tax
//********************************************************
float Employee::calcStateTax()
{
float theStateTax;
theStateTax = grossPay;
// Calculate state tax based on employee residence
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;
return theStateTax;
} // calcStateTax
//********************************************************
// Calculate Federal Tax
//********************************************************
float Employee::calcFedTax()
{
float theFedTax;
// Federal tax is the same for all employees
theFedTax = grossPay * FED_TAX_RATE;
return theFedTax;
} // calcFedTax
//********************************************************
// Calculate Net Pay
//********************************************************
float Employee::calcNetPay()
{
float theNetPay;
float theTotalTaxes;
// Calculate total taxes
theTotalTaxes = stateTax + fedTax;
// Calculate take-home pay
theNetPay = grossPay - theTotalTaxes;
return theNetPay;
} // calcNetPay
//********************************************************
// Constructor with Arguments
//********************************************************
Employee::Employee(string myFirstName, string myLastName,
string myTaxState, int myClockNumber,
float myWageRate, float myHours)
{
// Initialize employee information
firstName = myFirstName;
lastName = myLastName;
// Convert state abbreviation to uppercase
if (myTaxState.length() >= 2)
{
if (std::islower(static_cast<unsigned char>(myTaxState[0])))
myTaxState[0] = std::toupper(static_cast<unsigned char>(myTaxState[0]));
if (std::islower(static_cast<unsigned char>(myTaxState[1])))
myTaxState[1] = std::toupper(static_cast<unsigned char>(myTaxState[1]));
}
taxState = myTaxState;
clockNumber = myClockNumber;
wageRate = myWageRate;
hours = myHours;
// Calculate overtime hours
overTimeHrs = calcOverTimeHrs();
// Calculate gross pay
grossPay = calcGrossPay();
// Calculate state tax
stateTax = calcStateTax();
// Calculate federal tax
fedTax = calcFedTax();
// Calculate net pay
netPay = calcNetPay();
} // Employee constructor
//********************************************************
// Print Employee Information
//********************************************************
void Employee::printEmployee()
{
// Display employee input information
cout << endl << endl << "*** Entered Details are ***" << endl;
cout << endl << " First Name: " << getFirstName();
cout << endl << " Last Name: " << getLastName();
cout << endl << " Tax State: " << getTaxState();
cout << endl << " Clock Number: " << getClockNumber();
cout << endl << " Wage Rate: $" << getWageRate();
cout << endl << " Hours: " << getHours();
// Display calculated employee information
cout << endl << endl << "*** Calculated Values are ***" << endl;
// Display overtime hours
cout << endl << " Overtime Hours: "
<< getOverTimeHrs();
// Display gross pay
cout << endl << " Gross Pay: $"
<< getGrossPay();
// Display state tax
cout << endl << " State Tax: $"
<< getStateTax();
// Display federal tax
cout << endl << " Federal Tax: $"
<< getFedTax();
// Display net pay
cout << endl << " Net Pay: $"
<< getNetPay();
cout << "\n";
} // printEmployee
//********************************************************
// Employee Destructor
//********************************************************
Employee::~Employee()
{
// Nothing to print here
}
//********************************************************
// Main Function
//********************************************************
int main()
{
// Local variables for employee information
string myFirstName;
string myLastName;
string myTaxState;
int myClockNumber;
float myWageRate;
float myHours;
// Set output to two decimal places
cout << fixed << setprecision(2);
// Array of Employee objects
Employee e[EMP_SIZE];
// Collect information for five employees
for (int i = 0; i < EMP_SIZE; ++i)
{
cout << "\n\nEnter Employee First Name: ";
cin >> myFirstName;
cout << "\nEnter Employee Last Name: ";
cin >> myLastName;
cout << "\nEnter Employee Tax State: ";
cin >> myTaxState;
cout << "\nEnter Employee Clock Number: ";
cin >> myClockNumber;
cout << "\nEnter Employee Hourly Wage Rate: ";
cin >> myWageRate;
cout << "\nEnter Employee Hours Worked for the Week: ";
cin >> myHours;
// Create and assign Employee object
e[i] = {myFirstName, myLastName, myTaxState,
myClockNumber, myWageRate, myHours};
// Print employee information
e[i].printEmployee();
} // End for loop
return 0;
} // End main