I am writing a payroll program with inheritance for a school assignment that has the following requirments:
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).
This is my code:
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
ifstream fin;
public: string employeename;
char paystat;
int n;
float taxrate;
double hoursworked, overtimehours, regularhours;
double hourlyrate,regularpay,totalnetpay,minnp,maxnp;
double avgnetpay,taxamount,netpay,grosspay,overtimepay;
virtual double findgrosspay();
void setvariables(char[],int,char,char,char,double,double);
virtual double findtaxamount();
virtual double findnetpay();
virtual double findavgnetpay();
void printheaders();
void printdata();
double minnet(double, int);
double maxnet(double, int);
void printminmax(double, double);
void printreport();
void sortbypointers();
payroll();
~payroll();
};
class hourly: public payroll{
public: double findgrosspay(){
if(hoursworked > 40){
overtimehours=hoursworked-40;
regularpay=hoursworked*hourlyrate;
overtimepay=overtimehours*(hourlyrate*1.5);
grosspay=regularpay+overtimepay;}
else{
grosspay=hoursworked*hourlyrate;
regularpay=grosspay;
return grosspay;
}//IF
};//findgrosspay
};
class salaried:public payroll{
public: …