1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
// main.cpp
#include <iostream>
#include <vector>
#include "salaried.h"
#include "hourly.h"
#include "base_plus_commissioned.h"
using namespace std;
int main()
{
cout << "Employee payroll processed successfully!" << endl << endl;
Date currentDate(20, 5, 2014);
Date birth_emp1(5, 7, 1975);
Date hire_emp1(3, 4, 1992);
Salaried salEmp1("John", "Roberts", 25, 500, birth_emp1, hire_emp1);
Date birth_emp2(2, 8, 1978);
Date hire_emp2(15, 4, 1995);
Hourly hrlyEmp1("Phil", "Brooks", 23, 5, 10, birth_emp2, hire_emp2);
Date birth_emp3(25, 4, 1985);
Date hire_emp3(30, 6, 2001);
Commissioned commEmp1("Andy", "Leo", 12, 100, 500, birth_emp3, hire_emp3);
Date birth_emp4(18, 7, 1960);
Date hire_emp4(29, 4, 1989);
Base_Plus_Commissioned bpcEmp1("Jack", "Benson", 43, 700, 250, 3000, birth_emp4, hire_emp4);
// polymorphic action starts here
vector<Employee *> empPtr(4); // creating a vector of 4 base class pointers
empPtr[0] = &salEmp1;
empPtr[0]->print();
cout << endl << "Total earnings: $" << empPtr[0]->earnings() << endl << endl;
empPtr[1] = &hrlyEmp1;
empPtr[1]->print();
cout << endl << "Total Earnings: $" << empPtr[1]->earnings() << endl << endl;
empPtr[2] = &commEmp1;
empPtr[2]->print();
cout << endl << "Total Earnings: $" << empPtr[2]->earnings() << endl << endl;
empPtr[3] = &bpcEmp1;
empPtr[3]->print();
cout << endl << "Total Earnings: $" << empPtr[3]->earnings() << endl << endl;
return 0;
}
| |