Question
C++: Create an Employee class for a basic payroll program to compute the net pay salary of hourly based employees. Your program should also find
C++:
Create an Employee class for a basic payroll program to compute the net pay salary of hourly based employees. Your program should also find the average net pay for a small company. To define the class, include the appropriate data members, member functions, and access modifiers. For simplicity, use a constant tax rate of 30% to compute the tax amount. Employees that work over 40 hours will receive overtime pay of one and a half of their hourly rate for overtime hours worked. The output should display the name of each employee, hours worked, hourly rate, overtime pay, regular (gross) pay, tax amount, and net pay. The average net pay of all employees should also be displayed.
The Employee Payroll program will include hourly based and salary based employees. It will use an array of employee objects, inheritance for different classes of employees, and polymorphism for salary computation. The 52 week yearly salary as well as number of overtime hours worked by a salary based employee is given). For salary based employees, to find the regular (gross) pay for a week, divide the salary by 52. To compute the overtime pay for a salary based employee, first find the hourly rate by dividing the gross pay by 40, and then compute overtime pay. For every employee, overtime pay, tax amount, and net pay must also be computed. In addition, the program should find the minimum and maximum net pay of all employees as well as sort the employees based on their net pay (ascending order).The program must combine two sorting techniques; the Selection and Exchange sorts. It will efficiently sort the employees' net pay.
My code for the assingment is below. It has a working output, but does not computate the correct formula for a salary based employee. Please help me. C++.
#include
#include
#include
#include
using namespace std;
int employeeID, payStat, totalEmployeeCount, employeeCounter;
string firstName, lastName, maritalstatus;
double hourlyRate, salary, hours, taxRate, taxAmount, grossPay, netPay[100], regPay, otHours, otPay;
class payroll{
public: void setVariables(int empID, string fName, string lName, int stat, double rate, double hrs){
employeeID = empID; firstName = fName; lastName = lName; payStat = stat;
if (payStat == 1){ hourlyRate = rate; }
else { salary = rate;}
hours = hrs; }
//declare function to calculate gross pay
public: virtual double calculateGrossPay() = 0;
double calculateTaxAmount(){ taxRate = .30; //set a flat taxrate 30%
taxAmount = grossPay * taxRate; //formula to calculate tax amount
return taxAmount; } //end calculateTaxAmount() function
virtual double calculateNetPay(){
netPay[100] = grossPay - taxAmount;
return netPay[100]; } //end
void printHeader();
void printreport();
void printheadings();
};
class employeeSalary : public payroll{
public: double calculateGrossPay() {
regPay = salary/52;
hourlyRate = regPay/40;
if (hours > 40) {otHours = (hours - 40); //calculate OT hours
otPay = (otHours * hourlyRate); //calculate OT pay
grossPay = (regPay + otPay); }
else if (hours <= 40) {otHours = 0; otPay = 0; grossPay = regPay;}
return grossPay; }
}; //end EmployeeSalary class
class employeeHourly : public payroll{
public: double calculateGrossPay(){
regPay = (40 * hourlyRate); //calculate regular hours
if (hours > 40){ otHours = (hours - 40); //calculate OT hours
otPay = (otHours * hourlyRate * 1.5); //calculate OT pay
grossPay = (regPay + otPay); //calculate gross pay
} //enf if clause for gross pay with overtime
else { otHours = 0; otPay = 0; grossPay = regPay;
} //end else clause for four hours
return grossPay; } //end calculateGrossPay() function
}; //end EmployeeHourly class
void payroll::printheadings(){
cout< cout<<"------------------------------------------------------------------------------"< cout<<" NAME ID HW OT RT-PAY OT-PAY GROSS" " TAX NETPAY"< cout<<"------------------------------------------------------------------------------"< }//PRINTHEADINGS void payroll::printHeader(){ cout< cout< < < < }//PRINTDATA //end Payroll class void payroll::printreport(){ if(totalEmployeeCount>0){ calculateGrossPay(); calculateTaxAmount(); calculateNetPay(); printHeader(); } }//end printData() function int main(void){ int stat, i, empID; string fName, lName; double rate, hrs, netPayhold[100]; cout<<"Enter # of employees you want to process: "; cin>>totalEmployeeCount; payroll *employee[100]; employeeCounter = 0; //while loop to get input for each employee while (employeeCounter < totalEmployeeCount){ //prompt the user for hourly or salary employee cout<<"Is employee "< cin>>stat; if (stat == 1){ cout<<"Instantiating an HOURLY employee object inherited from base class payroll..."< cout<<"Enter employee's ID: ";cin>>empID; cout<<"Enter employee's first name: ";cin >>fName; cout<<"Enter employee's last name: ";cin>>lName; cout<<"Enter employee's hourly wage: "; cin>>rate; cout<<"Enter employee's hours for this week: "; cin>>hrs; employee[employeeCounter] = new employeeHourly(); employee[employeeCounter]->setVariables(empID, fName, lName, stat, rate, hrs); employee[employeeCounter]->calculateGrossPay(); employee[employeeCounter]->calculateTaxAmount(); employee[employeeCounter]->calculateNetPay(); employee[employeeCounter]->printheadings(); employee[employeeCounter]->printreport(); netPayhold[employeeCounter] = netPay[100]; } //end if //if employee is NOT hourly (Salary clause) else if(stat == 2) { cout<<"Instantiating a SALARY employee object inherited from base class payroll..."< cout<<"Enter employee's ID: ";cin>>empID; cout<<"Enter employee's first name: ";cin >>fName; cout<<"Enter employee's last name: ";cin>>lName; cout<<"Enter employee's salary: "; cin>>rate; cout<<"Enter employee's hours for this week: "; cin>>hrs; employee[employeeCounter] = new employeeSalary(); employee[employeeCounter]->setVariables(empID, fName, lName, stat, rate, hrs); employee[employeeCounter]->calculateGrossPay(); employee[employeeCounter]->calculateTaxAmount(); employee[employeeCounter]->calculateNetPay(); employee[employeeCounter]->printheadings(); employee[employeeCounter]->printreport(); netPayhold[employeeCounter] = netPay[100]; } employeeCounter++; } cout< cout<<"Net Pay Sorted"< for (i=0; i cout<< netPayhold[i]< } };
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started