Question: Expand the Employee Payroll program to include hourly based and salary based employees. This phase uses an array of employee objects, inheritance for different classes
Expand the Employee Payroll program to include hourly based and salary based employees. This phase uses 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).
I cannot get my code to work at all ugh.
#include
using namespace std; class payroll{ protected: string firstName, lastName; int employeeID, payStat; double hourlyRate, taxRate, hours, salary;
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; } public: virtual double calculateGrossPay() = 0; double calculateTaxAmount(){ double taxRate = .30; double taxAmount = calculateGrossPay() * taxRate; return taxAmount; } double calculateNetPay(){ double NetPay=calculateGrossPay()-calculateTaxAmount(); return NetPay; } };
class employeeSalary : public payroll{ public: double calculateGrossPay() { double regPay = (salary/52); hourlyRate =(regPay/40); double otPay, otHours; double grossPay; if (hours > 40) {otHours = (hours - 40); otPay = (otHours * hourlyRate); grossPay = (regPay + otPay); } else if (hours <= 40) {otHours = 0; otPay = 0; grossPay = regPay; } return grossPay; } }; class employeeHourly : public payroll{ public: double calculateGrossPay(){ double regPay = (40 * hourlyRate); double otPay, otHours; double grossPay; if (hours > 40){ otHours = (hours - 40); otPay = (otHours * hourlyRate * 1.5); grossPay = (regPay + otPay); } else { otHours = 0; otPay = 0; grossPay = regPay; } return grossPay; } //Payroll class }; void printHeader(){ cout< int main(void){ int empID; double rate; double hrs; int N cout<<"Enter # of employees you want to process: "; int totalEmployeeCount; cin>>totalEmployeeCount; payroll * employee[100]; for (int employeeCounter = 0; employeeCounter < totalEmployeeCount; employeeCounter++){ cout<<"Is employee "< void sort_hourly_based(hourly_based *employee[], int size){ int i,j,max; hourly_based *temp; for(i=0;i void sort_salary_based(salary_based *employee[], int size){ int i,j,max; salary_based *temp; for(i=0;i void swap1(salary_based *employee1, salary_based *employee2){ salary_based *temp; temp=employee1; employee1=employee2; employee2=temp; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
