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
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).
Here is the existing code for the program I need to expand:
#include
using namespace std;
class payroll { ifstream fin; char empid[15];//employee id char fname[10];//first name char lname[10];//last name char marstat;//marital status character. it's not case-dependent int hwork, rwork, otwork;//quantity of hours in whole numbers double hrate, otrate;//rates double rpay, grpay, netpay, otpay;//regular pay, gross pay, net pay, overtime pay double taxamt;//taxes paid const double TAXRATE = 0.3;//all tax conditions result in a 30% tax rate
void calcgrpay(); void calctax(); void calcnetpay(); void printheadings(); void printdata();
public: double sum = 0;//declaration of sum variable, initialized to 0 int counter = 0;//counter for number of employees and their related data payroll();//constructor ~payroll();//destructor void printreport(); };//end class payroll
payroll::payroll() { fin.open("employee.txt");//constructor } payroll::~payroll() { fin.close(); }
void payroll::calcgrpay() { if (hwork > 40)//if hours worked are greater than 40 { otwork = hwork - 40; rwork = hwork - otwork; rpay = rwork * hrate; otrate = (hrate * 1.5); otpay = otwork * otrate; grpay = rpay + otpay; }//end IF loop else if (hwork <= 40)//if hours worked are less than or equal to 40 { otwork = 0; rpay = hwork * hrate; otrate = 0; otpay = 0; grpay = rpay; }//end ELSE IF loop }//end of calculations for gross pay
void payroll::calctax() { TAXRATE; if (marstat == 'S' || marstat == 's' || marstat == 'm' || marstat == 'M' || marstat == 'h' || marstat == 'H')//all conditions result in the same tax rate { taxamt = grpay * TAXRATE; }//end of IF loop }//end of calculations for taxrate
void payroll::calcnetpay() { netpay = (grpay - taxamt); sum += netpay; }//end of calculations for net pay
void payroll::printheadings() { cout << setw(45) << "PAYROLL" << endl; cout << "FIRST NAME" << "\t" << "LAST NAME" << "\t" << "EMP ID" << "\t" << "HOURS" << "\t" << "OT HOURS" << "\t" << "RATE" << "\t" << "OT RATE" << "\t" << "OT PAY" << "\t\t" << "GROSSPAY" << "\t" << "TAX PAID" << "\t" << "NET PAY" << "\t" << endl << endl; }//end of the print headers for data fields
void payroll::printdata() { cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint); cout << fname << "\t\t" << lname << "\t\t" << empid << "\t" << hwork << "\t" << otwork << "\t\t" << hrate << "\t" << otrate << "\t" << otpay << "\t\t" << grpay << "\t\t" << taxamt << "\t\t" << netpay << endl; }//end of print data
void payroll::printreport() { int i = 0; printheadings(); while (fin >> fname >> lname >> empid >> marstat >> hwork >> hrate) { counter++; calcgrpay(); calctax(); calcnetpay(); printdata(); i++; }//end of WHILE }//end of print report
int main() { payroll employee; employee.printreport(); cout << endl << "SUM OF ALL NET PAYS: " << endl << employee.sum << endl << endl; cout << "THE AVERAGE OF ALL NET PAYS IS: " << endl << employee.sum/employee.counter << endl << endl; }//end of INT main
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