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

Help please! This is for C++; Here is the Payroll System Code: // PayrollSystem

ID: 655634 • Letter: H

Question

Help please! This is for C++;

Here is the Payroll System Code:

// PayrollSystem
// Processing Employee derived-class objects individually
// and polymorphically using dynamic binding.
#include <iostream>
#include <iomanip>
#include <vector>
#include "Employee.h"
#include "SalariedEmployee.h"
#include "CommissionEmployee.h"
#include "BasePlusCommissionEmployee.h"
using namespace std;

void virtualViaPointer( const Employee * const ); // prototype
void virtualViaReference( const Employee & ); // prototype

int main()
{
// set floating-point output formatting
cout << fixed << setprecision( 2 );

// create derived-class objects
SalariedEmployee salariedEmployee(
"John", "Smith", "111-11-1111", 800 );
CommissionEmployee commissionEmployee(
"Sue", "Jones", "333-33-3333", 10000, .06 );
BasePlusCommissionEmployee basePlusCommissionEmployee(
"Bob", "Lewis", "444-44-4444", 5000, .04, 300 );

cout << "Employees processed individually using static binding: ";

// output each Employee?s information and earnings using static binding
salariedEmployee.print();
cout << " earned $" << salariedEmployee.earnings() << " ";
commissionEmployee.print();
cout << " earned $" << commissionEmployee.earnings() << " ";
basePlusCommissionEmployee.print();
cout << " earned $" << basePlusCommissionEmployee.earnings()
<< " ";

// create vector of three base-class pointers
vector < Employee * > employees( 3 );

// initialize vector with Employees
employees[ 0 ] = &salariedEmployee;
employees[ 1 ] = &commissionEmployee;
employees[ 2 ] = &basePlusCommissionEmployee;

cout << "Employees processed polymorphically via dynamic binding: ";

// call virtualViaPointer to print each Employee's information
// and earnings using dynamic binding
cout << "Virtual function calls made off base-class pointers: ";

for ( const Employee *employeePtr : employees )
virtualViaPointer( employeePtr );

// call virtualViaReference to print each Employee's information
// and earnings using dynamic binding
cout << "Virtual function calls made off base-class references: ";

for ( const Employee *employeePtr : employees )
virtualViaReference( *employeePtr ); // note dereferencing
} // end main

// call Employee virtual functions print and earnings off a
// base-class pointer using dynamic binding
void virtualViaPointer( const Employee * const baseClassPtr )
{
baseClassPtr->print();
cout << " earned $" << baseClassPtr->earnings() << " ";
} // end function virtualViaPointer

// call Employee virtual functions print and earnings off a
// base-class reference using dynamic binding
void virtualViaReference( const Employee &baseClassRef )
{
baseClassRef.print();
cout << " earned $" << baseClassRef.earnings() << " ";
} // end function virtualViaReference

For this program we will modify the existing Payroll System located in the attached compressed folder (this is the code from Figures 12.9 thru 12.17 in the Deitel & Deitel textbook on pages 537-548). We will modify the code to include some additional Employee subclasses: Pieceworker and HourlyWorker. The Pieceworker's pay is based on the number of pieces of merchandise produced. The HourlyWorker's pay is based on an hourly wage times the number of hours worked. HourlyWorkers should receive overtime pay of 1.5 times the hourly wage rate for all hours worked over 40. Class Pieceworker should have the following private instance variables: wage (to store the employee's wage per piece) pieces (to store the number of pieces produced) Class HourlyWorker should have the following private instance variables: wage (to store the employee's wage per hour) hours (to store the number of hours worked) Solution: In class Pieceworker, provide a concrete implementation of method earnings per piece. In class HourhlyWorker, provide a concrete implementation of method earnings that calculates the employee's earnings by multiplying the number of hours worked by the wage per hour. If the number of hours worked is over 40, be sure to pay the HourlyWorker for the overtime hours. Add a pointer to an object of each new class into the vector of Employee pointers in main. For each employee, display its string representation and earnings.

Explanation / Answer

// PayrollSystem
// Processing Employee derived-class objects individually
// and polymorphically using dynamic binding.
#include <iostream.h>
#include <iomanip.h>
#include <vector.h>
#include "Employee.h"
#include "SalariedEmployee.h"
#include "CommissionEmployee.h"
#include "BasePlusCommissionEmployee.h"
using namespace std;
void virtualViaPointer( const Employee * const ); // prototype
void virtualViaReference( const Employee & ); // prototype
int main()
{
// set floating-point output formatting
cout << fixed << setprecision( 2 );
// create derived-class objects
SalariedEmployee salariedEmployee(
"John", "Smith", "111-11-1111", 800 );
CommissionEmployee commissionEmployee(
"Sue", "Jones", "333-33-3333", 10000, .06 );
BasePlusCommissionEmployee basePlusCommissionEmployee(
"Bob", "Lewis", "444-44-4444", 5000, .04, 300 );

cout << "Employees processed individually using static binding: ";
// output each Employee