Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Expand the Employee Payroll program to include hourly based and salary based emp

ID: 3850121 • Letter: E

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 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<iostream>
#include<fstream>
#include<iomanip>

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" << " "
           << "LAST NAME" << " "
           << "EMP ID" << " "
           << "HOURS" << " "
           << "OT HOURS" << " "
           << "RATE" << " "
           << "OT RATE" << " "
           << "OT PAY" << " "
           << "GROSSPAY" << " "
           << "TAX PAID" << " "
           << "NET PAY" << " " << endl << endl;
   }//end of the print headers for data fields

   void payroll::printdata()
   {
       cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint);
       cout << fname << " "
           << lname << " "
           << empid << " "
           << hwork << " "
           << otwork << " "
           << hrate << " "
           << otrate << " "
           << otpay << " "
           << grpay << " "
           << taxamt << " "
           << 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

Explanation / Answer

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class Employee_Info{
public:
   int employeeid;
   string firstname, lastname;
   char taxstatus, typeemp;
   double hoursworked, hourlyrate, overtimehours, overtimepay, grosspay, grosssalary, taxrate, taxamount, netpay;
};//end class
class Employee :public Employee_Info{
public:
   ifstream input;
   Employee_Info empi[100];
   int counter;
   void headers();
   virtual void grosspaycalc() = 0;
   virtual void taxratecalc() = 0;
   virtual void netpaycalc() = 0;
   virtual void employee_report() = 0;
   void netpaysort();
   virtual void displayinfo() = 0;
};//end class
void Employee::netpaysort(){
   for (int pass = 1; pass <= counter; pass = pass + 1) {
       for (int i = 0; i<counter - 1; i = i + 1) {
           if (empi[i].netpay<empi[i + 1].netpay) {
               swap(empi[i].netpay, empi[i + 1].netpay);
           }//end if
       }//end for
   }//end for
}//end netpaysort
class Hourly_Employee : public Employee{
public:
   Hourly_Employee();//constructor
   ~Hourly_Employee();//destructor
   void grosspaycalc(){
       for (int i = 0; i<counter; i++) {
           if(empi[i].typeemp == 'Y')
           {
           // 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.
           double gross_pay = empi[i].grosspay/52;
           empi[i].hourlyrate = gross_pay/40;
           if (empi[i].hoursworked>40) {
           empi[i].overtimehours = empi[i].hoursworked - 40;
           empi[i].overtimepay = 1.5*empi[i].overtimehours*empi[i].hourlyrate;
           }
           else
           {
            empi[i].overtimehours = 0;
           empi[i].overtimepay = 0;
           }
           }
           else if (empi[i].hoursworked>40){
               empi[i].overtimehours = empi[i].hoursworked - 40;
               empi[i].overtimepay = 1.5*empi[i].overtimehours*empi[i].hourlyrate;
               empi[i].grosspay = empi[i].overtimepay + (empi[i].hoursworked*empi[i].hourlyrate);
           }//end if
           else
           {
           empi[i].overtimehours = 0;
           empi[i].overtimepay = 0;
           empi[i].grosspay = empi[i].hoursworked*empi[i].hourlyrate;
           }
       }//end for
   }//end grosspaycalc
   void taxratecalc(){
       for (int i = 0; i<counter; i++) {
           if (empi[i].grosspay>1000) {
               empi[i].taxrate = .30;
           }//end if
           if (empi[i].grosspay>800 && empi[i].grosspay <= 1000) {
               empi[i].taxrate = .20;
           }//end if
           if (empi[i].grosspay>500 && empi[i].grosspay <= 800) {
               empi[i].taxrate = .10;
           }//end if
           if (empi[i].grosspay >= 0 && empi[i].grosspay <= 500) {
               empi[i].taxrate = 0;
           }//end if
           if ((empi[i].taxstatus == 'H' || empi[i].taxstatus == 'h') && (empi[i].grosspay>500)){
               empi[i].taxrate = empi[i].taxrate - .05;
           }//end if
           if (empi[i].taxstatus == 'S' || empi[i].taxstatus == 's'){
               empi[i].taxrate = empi[i].taxrate + .05;
           }//end if
           if (empi[i].taxstatus == 'M' || empi[i].taxstatus == 'm'){
               empi[i].taxrate = empi[i].taxrate;
           }//end if
       }//end for
   }//end Hourly_Employee taxratecalc
   void netpaycalc(){
       for (int i = 0; i<counter; i++) {
           empi[i].taxamount = empi[i].grosspay*empi[i].taxrate;
           empi[i].netpay = empi[i].grosspay - empi[i].taxamount;
       }//end for
   }//end netpaycalc
   void displayinfo(){
    
       //if (empi[i].typeemp == 'N' || empi[i].typeemp == 'n') {
           cout << setiosflags(ios::fixed | ios::showpoint | ios::left) << setprecision(2);
            for(int i=0; i<counter; i++)
           cout << setw(15) << empi[i].employeeid << setw(15) << empi[i].firstname << setw(15) << empi[i].lastname << "XXX-XX-" << setw(15) << empi[i].taxstatus << setw(15) << empi[i].typeemp << setw(15) << empi[i].hoursworked << "$ " << setw(15) << empi[i].hourlyrate << setw(15) << empi[i].grosspay << setw(15) << empi[i].overtimehours << "$ " << setw(17) << empi[i].overtimepay << "% " << setw(15) << empi[i].taxrate * 100 << "$ " << setw(15) << empi[i].taxamount << "$ " << setw(15) << empi[i].netpay << endl;
       //}//end if
   }//end employeeinfo
   void employee_report(){
       grosspaycalc();
       taxratecalc();
       netpaycalc();
       netpaysort();
   }//end readindata
};//end class
Hourly_Employee::Hourly_Employee():Employee(){
   input.open("data.txt");
   counter=0;
   while (input >> empi[counter].firstname >> empi[counter].lastname >> empi[counter].employeeid >> empi[counter].taxstatus >> empi[counter].typeemp
   >> empi[counter].hoursworked >> empi[counter].hourlyrate >> empi[counter].grosspay) {
       counter++;
   }//end while
}//end constructor
Hourly_Employee::~Hourly_Employee(){
   input.close();
}// end Destructor
//end function
void headers();
int main(int argc, char * argv[]){
   const int MAXSIZE = 70;
   Hourly_Employee hourly_report;
   cout << setw(100) << "NOREEN Payroll Program" << endl;
   headers();
   //for (int i = 0; i<MAXSIZE; i++) {
       hourly_report.employee_report();
       hourly_report.displayinfo();
   //}//end for
   return 0;
}// End Main
void headers(){
   cout << setiosflags(ios::fixed | ios::showpoint | ios::left);
   cout << setw(15) << "EMPLOYEE ID" << setw(15) << "FIRST NAME" << setw(15) << "LAST NAME" << setw(22) << "TAX STATUS" << setw(15) << "SALARIED" << setw(15) << "HOURS WORKED" << setw(17) << "HOURLY RATE" << setw(15) << "GROSS PAY" << setw(15) << "OVERTIME HOURS" << setw(18) << "OVERTIME PAY" << setw(18) << "TAX RATE" << setw(17) << "TAX AMOUNT" << setw(15) << "NET PAY" << endl;
}//end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote