// Assignment 11 - Employee Pay Calculator using C++ Classes
//
// Name: Felix Henriquez
//
// Class: C Programming, Fall 2025
//
// Date: November 30, 2025
//
// Description: This program implements an object-oriented design using C++
// to calculate employee pay, taxes, and net pay. It uses
// classes to encapsulate employee data and calculations.
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;
// Constants for tax rates and overtime
const float FED_TAX_RATE = 0.25;
const float OT_RATE = 1.5;
const int STD_HOURS = 40;
class Employee {
private:
string firstName;
string lastName;
string taxState;
string clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
float stateTax;
float fedTax;
float netPay;
public:
// Constructor
Employee() : wageRate(0), hours(0), overtimeHrs(0), grossPay(0),
stateTax(0), fedTax(0), netPay(0) {}
// Member function to set employee data from provided values
void setEmployeeData(string fname, string lname, string state,
string clock, float wage, float hrs) {
firstName = fname;
lastName = lname;
taxState = state;
clockNumber = clock;
wageRate = wage;
hours = hrs;
}
// Member function to calculate overtime hours
void calculateOvertimeHrs() {
overtimeHrs = (hours > STD_HOURS) ? (hours - STD_HOURS) : 0.0;
}
// Member function to calculate gross pay
void calculateGrossPay() {
float regularHrs = hours - overtimeHrs;
grossPay = (regularHrs * wageRate) + (overtimeHrs * wageRate * OT_RATE);
}
// Member function to calculate state tax
void calculateStateTax() {
if (taxState == "MA") {
stateTax = grossPay * 0.05;
} else if (taxState == "VT") {
stateTax = grossPay * 0.06;
} else if (taxState == "NH") {
stateTax = 0.00;
} else if (taxState == "CA") {
stateTax = grossPay * 0.07;
} else if (taxState == "NY") {
stateTax = grossPay * 0.08;
} else {
stateTax = 0.00;
}
}
// TODO: Implement calculateFedTax member function
void calculateFedTax() {
fedTax = grossPay * FED_TAX_RATE;
}
// TODO: Implement calculateNetPay member function
void calculateNetPay() {
netPay = grossPay - stateTax - fedTax;
}
// Member function to display employee data
void displayEmployeeData() const {
cout << "\n *** Entered Details are *** \n\n";
cout << " First Name: " << firstName << endl;
cout << " Last Name: " << lastName << endl;
cout << " Tax State: " << taxState << endl;
cout << " Clock Number: " << clockNumber << endl;
cout << fixed << setprecision(2);
cout << " Wage Rate: " << wageRate << endl;
cout << " Hours: " << hours << endl;
}
// Member function to display calculated values
void displayCalculatedValues() const {
cout << "\n *** Calculated Values are *** \n\n";
cout << fixed << setprecision(2);
cout << " Overtime Hours : " << overtimeHrs << endl;
cout << " Gross Pay : $" << grossPay << endl;
cout << " State Tax : $" << stateTax << endl;
cout << " Federal Tax : $" << fedTax << endl;
cout << " Net Pay : $" << netPay << endl;
}
// Advanced display function for formatted output
void displayFormatted() const {
// Format clock number with leading zeros if needed
string formattedClock = clockNumber;
if (formattedClock.length() < 6) {
formattedClock = string(6 - formattedClock.length(), '0') + formattedClock;
}
// Format the full name
string fullName = firstName + " " + lastName;
if (fullName.length() > 19) {
fullName = fullName.substr(0, 19);
}
cout << left << setw(19) << fullName
<< right << setw(4) << taxState << " "
<< setw(6) << formattedClock << " "
<< setw(6) << fixed << setprecision(2) << wageRate << " "
<< setw(5) << setprecision(1) << hours << " "
<< setw(4) << setprecision(1) << overtimeHrs << " "
<< setw(7) << setprecision(2) << grossPay << " "
<< setw(6) << setprecision(2) << stateTax << " "
<< setw(6) << setprecision(2) << fedTax << " "
<< setw(8) << setprecision(2) << netPay << endl;
}
};
// Function to display advanced formatted output
void displayAdvancedOutput(const Employee employees[], int count) {
cout << "\n\n*** Pay Calculator ***\n\n";
cout << "---------------------------------------------------------------------------------" << endl;
cout << "Name Tax Clock# Wage Hours OT Gross State Fed Net" << endl;
cout << " State Pay Tax Tax Pay" << endl;
cout << "---------------------------------------------------------------------------------" << endl;
for (int i = 0; i < count; i++) {
employees[i].displayFormatted();
}
cout << "---------------------------------------------------------------------------------" << endl;
}
int main() {
const int NUM_EMPLOYEES = 5;
Employee employees[NUM_EMPLOYEES];
cout << fixed << setprecision(2);
// Pre-defined employee data for Ideone.com (no interactive input)
string first_names[] = {"Connie", "Mary", "Frank", "Jeff", "Anton"};
string last_names[] = {"Cobol", "Apl", "Fortran", "Ada", "Pascal"};
string tax_states[] = {"MA", "NH", "VT", "NY", "CA"};
string clock_numbers[] = {"98401", "526488", "765349", "34645", "127615"};
float wage_rates[] = {10.60, 9.75, 10.50, 12.25, 8.35};
float hours[] = {51.0, 42.5, 37.0, 45.0, 40.0};
// Process each employee
for (int i = 0; i < NUM_EMPLOYEES; i++) {
// Set employee data from pre-defined arrays
employees[i].setEmployeeData(first_names[i], last_names[i], tax_states[i],
clock_numbers[i], wage_rates[i], hours[i]);
// Calculate all values
employees[i].calculateOvertimeHrs();
employees[i].calculateGrossPay();
employees[i].calculateStateTax();
employees[i].calculateFedTax(); // TODO: Call the federal tax calculation
employees[i].calculateNetPay(); // TODO: Call the net pay calculation
// Display results
employees[i].displayEmployeeData();
employees[i].displayCalculatedValues();
}
// Display advanced formatted output
displayAdvancedOutput(employees, NUM_EMPLOYEES);
return 0;
}