Lab 8

In this lab, we are going to create a simple Employee class hierachy. Use the following steps as a guide.
  1. Create the Employee class. Notice that this is an Abstract Base Class. Write the constructor and the two member functions.
  2. Now finish the two other classes, SalariedEmployee and HourlyEmployee. Implement the getPay() method for both of these. For hourly employees, multiply the rate by hours worked. For salaried employees, simply divide their salary by 52 - the hours worked do not matter. Also note, HourlyEmployee and SalariedEmployees constructors should call their base classes constructors to do the appropriate work.
  3. Now finish Manager - write the constructor and getPay method. Managers getPay should return the normal pay for a salaried employee (not so subtle hint: you need to call SalariedEmployees getPay() method). Run this with the test main below.
    
    
    #include <iostream>
    using namespace std;
    #include <string>
    #include <cstdio>
    
    class Employee
    {
       public:
     
       //ctors
       Employee(string, int);
       
       string getname();
       int    getID();
       virtual int getPay(int) = 0;
    
       private:
     
       string name;
       int    employeeID;
    };
    class SalariedEmployee : Employee
    {
       public:
       SalariedEmployee(string, int, int);
       virtual int getPay(int);
    
       private:
       int salary;
    };
    class HourlyEmployee : Employee
    {
       public:
       HourlyEmployee(string, int, double);
       virtual int getPay(int);
    
       private:
       double hourlyRate;
    };
    class Manager : SalariedEmployee
    {
       public:
       Manager(string, int, int, int);
       virtual int getPay(int);
    
       private:
       int bonus;
    
    };
    
    void ProcessPayroll(Employee* roster[], int size)
    {
      int hoursWorked = 20;
      cout <<endl<<"Hours Worked : "<<hoursWorked;
      for (int i=0; i<size; i++)
      {
        cout <endl<"Name: "<<roster[i]->getname()<<"  ID: "<<roster[i]->getID()
             <<"  Pay: "<<roster[i]->getPay(hoursWorked);
      }
    
    }
    
    int main()
    {
      HourlyEmployee* he1 = new HourlyEmployee(string("Larry"), 1111, 20.0);
      HourlyEmployee* he2 = new HourlyEmployee(string("Moe"), 2222, 17.5);
      SalariedEmployee* se1 = new SalariedEmployee(string("Curly"), 3333, 50000);
      SalariedEmployee* se2 = new SalariedEmployee(string("Shemp"), 4444, 60000);
      Manager* me1 = new Manager(string("Chris"), 5555, 75000, 15000);
    
      Employee* empList[5];
    
      empList[0] = (Employee*) he1; 
      empList[1] = (Employee*) he2;
      empList[2] = (Employee*) se1;
      empList[3] = (Employee*) se2;
      empList[4] = (Employee*) me1;
    
      ProcessPayroll(empList, 5);
    }
    
    
    What to hand in:
    A test run with the main seen below, then change hoursWorked to 40, and re-run it.