//main.cpp//
#include "Employee.h"
#include "SalariedEmployee.h"
#include "HourlyEmployee.h"
#include "CommissionEmployee.h"
#include "BasePlusCommissionEmployee.h"
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
void virtualViaPointer ( const Employee * const );
void virtualViaReference ( const Employee & );
int main ( void )
{
cout << fixed << setprecision ( 2 );
//Istanzia gli oggetti
SalariedEmployee salariedEmployee ( "John", "Smith", "111-11-1111", 800 );
HourlyEmployee hourlyEmployee ( "Karen", "Price", "222-22-2222", 16.75, 40 );
CommissionEmployee commissionEmployee ( "Sue", "Jones", "333-33-3333", 10000, 0.06 );
BasePlusCommissionEmployee basePlusCommissionEmployee ( "Bob", "Lewis", "444-44-4444", 5000, 0.04, 300 );
cout << "STATIC BINDING:" << endl << endl;
salariedEmployee.print();
cout << endl;
cout << "Earned: " << salariedEmployee.earnings() << endl << endl;
hourlyEmployee.print();
cout << endl;
cout << "Earned: " << hourlyEmployee.earnings() << endl << endl;
commissionEmployee.print();
cout << endl;
cout << "Earned: " << commissionEmployee.earnings() << endl << endl;
basePlusCommissionEmployee.print();
cout << endl;
cout << "Earned: " << basePlusCommissionEmployee.earnings() << endl << endl << endl;
//crea un vettore
vector < Employee * > employees ( 4 );
//inizializzazione
employees[0] = &salariedEmployee;
employees[1] = &hourlyEmployee;
employees[2] = &commissionEmployee;
employees[3] = &basePlusCommissionEmployee;
cout << "DYNAMIC BINDING:" << endl;
//Utilizzando i puntatori
cout << endl << "POINTERS:" << endl << endl;
for ( size_t i = 0; i < employees.size(); i++ )
virtualViaPointer ( employees[i] );
//Utilizzando i riferimenti
cout << endl << "REFERENCES:" << endl << endl;
for ( size_t i = 0; i < employees.size(); i++ )
virtualViaReference ( *employees[i] );
cout << endl;
return 0;
}
void virtualViaPointer ( const Employee * const baseClassPtr )
{
baseClassPtr -> print();
cout << endl;
cout << "Earned: " << baseClassPtr -> earnings() << endl << endl;
}
void virtualViaReference ( const Employee &baseClassRef )
{
baseClassRef.print();
cout << endl;
cout << "Earned: " << baseClassRef.earnings() << endl << endl;
}