//********************************************************
//
// 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> // 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
using namespace std;
// class Employee
class Employee {
private:
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
float calcOverTimeHrs() {
return (hours > STD_HOURS) ? (hours - STD_HOURS) : 0;
}
float calcGrossPay() {
return (overTimeHrs > 0)
? (STD_HOURS * wageRate + overTimeHrs * (wageRate * OT_RATE))
: (hours * wageRate);
}
float calcStateTax() {
if (taxState == "MA") return grossPay * MA_TAX_RATE;
if (taxState == "NH") return grossPay * NH_TAX_RATE;
if (taxState == "VT") return grossPay * VT_TAX_RATE;
if (taxState == "CA") return grossPay * CA_TAX_RATE;
return grossPay * DEFAULT_TAX_RATE;
}
float calcFedTax() {
return grossPay * FED_TAX_RATE;
}
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), clockNumber(myClockNumber), wageRate(myWageRate), hours(myHours) {
if (islower(myTaxState[0])) myTaxState[0] = toupper(myTaxState[0]);
if (islower(myTaxState[1])) myTaxState[1] = toupper(myTaxState[1]);
taxState = myTaxState;
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(Employee e) {
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();
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";
}
};
int main() {
string myFirstName, myLastName, myTaxState;
int myClockNumber;
float myWageRate, myHours;
cout << fixed << setprecision(2);
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] = Employee(myFirstName, myLastName, myTaxState, myClockNumber, myWageRate, myHours);
e[i].printEmployee(e[i]);
}
return 0;
}