Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Libro Paga Elettronico - main.cpp

main.cpp

Caricato da: RiccardoG97
Scarica il programma completo

  1. //main.cpp//
  2.  
  3. #include "Employee.h"
  4. #include "SalariedEmployee.h"
  5. #include "HourlyEmployee.h"
  6. #include "CommissionEmployee.h"
  7. #include "BasePlusCommissionEmployee.h"
  8.  
  9. #include <iostream>
  10. #include <iomanip>
  11. #include <vector>
  12. using namespace std;
  13.  
  14. void virtualViaPointer ( const Employee * const );
  15. void virtualViaReference ( const Employee & );
  16.  
  17. int main ( void )
  18. {
  19.     cout << fixed << setprecision ( 2 );
  20.  
  21.     //Istanzia gli oggetti
  22.     SalariedEmployee salariedEmployee ( "John", "Smith", "111-11-1111", 800 );
  23.  
  24.     HourlyEmployee hourlyEmployee ( "Karen", "Price", "222-22-2222", 16.75, 40 );
  25.  
  26.     CommissionEmployee commissionEmployee ( "Sue", "Jones", "333-33-3333", 10000, 0.06 );
  27.  
  28.     BasePlusCommissionEmployee basePlusCommissionEmployee ( "Bob", "Lewis", "444-44-4444", 5000, 0.04, 300 );
  29.  
  30.     cout << "STATIC BINDING:" << endl << endl;
  31.  
  32.     salariedEmployee.print();
  33.     cout << endl;
  34.     cout << "Earned: " << salariedEmployee.earnings() << endl << endl;
  35.  
  36.     hourlyEmployee.print();
  37.     cout << endl;
  38.     cout << "Earned: " << hourlyEmployee.earnings() << endl << endl;
  39.  
  40.     commissionEmployee.print();
  41.     cout << endl;
  42.     cout << "Earned: " << commissionEmployee.earnings() << endl << endl;
  43.  
  44.     basePlusCommissionEmployee.print();
  45.     cout << endl;
  46.     cout << "Earned: " << basePlusCommissionEmployee.earnings() << endl << endl << endl;
  47.  
  48.  
  49.     //crea un vettore
  50.     vector < Employee * > employees ( 4 );
  51.  
  52.     //inizializzazione
  53.     employees[0] = &salariedEmployee;
  54.     employees[1] = &hourlyEmployee;
  55.     employees[2] = &commissionEmployee;
  56.     employees[3] = &basePlusCommissionEmployee;
  57.  
  58.     cout << "DYNAMIC BINDING:" << endl;
  59.     //Utilizzando i puntatori
  60.     cout << endl << "POINTERS:" << endl << endl;
  61.  
  62.     for ( size_t i = 0; i < employees.size(); i++ )
  63.         virtualViaPointer ( employees[i] );
  64.  
  65.     //Utilizzando i riferimenti
  66.     cout << endl << "REFERENCES:" << endl << endl;
  67.  
  68.     for ( size_t i = 0; i < employees.size(); i++ )
  69.         virtualViaReference ( *employees[i] );
  70.  
  71.     cout << endl;
  72.  
  73.     return 0;
  74. }
  75.  
  76. void virtualViaPointer ( const Employee * const baseClassPtr )
  77. {
  78.     baseClassPtr -> print();
  79.     cout << endl;
  80.     cout << "Earned: " << baseClassPtr -> earnings() << endl << endl;
  81. }
  82.  
  83. void virtualViaReference ( const Employee &baseClassRef )
  84. {
  85.     baseClassRef.print();
  86.     cout << endl;
  87.     cout << "Earned: " << baseClassRef.earnings() << endl << endl;
  88. }