Advertisement
nicb

EseFeroneLab3

Oct 10th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. ///MAIN
  2.  
  3. #include <iostream>
  4. #include"Nodo_.h"
  5. #include"Employee_.h"
  6. int main(){
  7.     Employee *emp1=new Employee(string("Ciro Espostio"),1000);
  8.     Employee *emp2=new Employee(string("Gennaro Espostio"),2000);
  9.     Employee *emp3=new Manager(string("Carmine Espostio"),2000,2000);
  10.     Employee *emp4=new Manager(string("Salvatore Espostio"),3000,3000);
  11.     Nodo n1,n2,n3,n4;
  12.     //Creo una lista di Employee
  13.     n1.SetEmployee(emp1);
  14.     n1.SetNext(&n2);
  15.     n2.SetEmployee(emp2);
  16.     n2.SetNext(&n3);
  17.     n3.SetEmployee(emp3);
  18.     n3.SetNext(&n4);
  19.     n4.SetEmployee(emp4);
  20.     n4.SetNext(nullptr);
  21.     //Stampo le info di ogni impiegato
  22.     n1.GetEmployee();
  23.     //Employee tmp1, tmp2;
  24.     //tmp1=*emp1;
  25.     //tmp2=*emp2;
  26.     int somma= *emp1+*emp2;
  27.     somma+=*emp3+*emp4;
  28.     cout<<endl<<"La somma dei salari e': "<<somma;
  29.  
  30. }
  31.  
  32. ///.H NODO
  33.  
  34. #ifndef NODO_H
  35. #define NODO_H
  36. #include"Employee_.h"
  37.  
  38. class Nodo
  39. {
  40.     private:
  41.         Nodo *Next;
  42.         Employee *Emp;
  43.  
  44.     public:
  45.         Nodo() {}
  46.         virtual ~Nodo() {}
  47.         void SetNext(Nodo *Emp)
  48.         {
  49.             this->Next=Emp;
  50.         }
  51.         Nodo* GetNext()
  52.         {
  53.             return this->Next;
  54.         }
  55.         void SetEmployee(Employee *Emp)
  56.         {
  57.             this->Emp=Emp;
  58.         }
  59.         void GetEmployee()
  60.         {
  61.             while(GetNext()!=nullptr)
  62.             {
  63.                 Emp->PrintInfo();
  64.                 this->Emp=GetNext()->Emp;
  65.                 this->Next=GetNext()->Next;
  66.  
  67.             }
  68.             Emp->PrintInfo();
  69.         }
  70.  
  71. };
  72.  
  73. #endif // NODO_H
  74.  
  75.  
  76. ///.IMPIEGATO
  77.  
  78. #ifndef EMPLOYEE_H
  79. #define EMPLOYEE_H
  80. #include<string>
  81.  
  82. using namespace std;
  83.  
  84. class Employee
  85. {
  86.     private:
  87.         string name;
  88.         int salary;
  89.  
  90.     public:
  91.         Employee(){};
  92.         Employee(string name,int salary)
  93.         {
  94.             this->name=name;
  95.             this->salary=salary;
  96.         }
  97.         virtual ~Employee() {}
  98.         string GetName()
  99.         {
  100.             return name;
  101.         }
  102.         void SetSalary(int salary)
  103.         {
  104.             this->salary=salary;
  105.         }
  106.         int GetSalary()
  107.         {
  108.             return salary;
  109.         }
  110.         virtual void PrintInfo()
  111.         {
  112.             cout<<endl<<"Nome: "<<name<<", Stipendio: "<<salary;
  113.         }
  114.  
  115.         int operator+ (Employee add)
  116.         {
  117.             return GetSalary()+add.GetSalary();
  118.         }
  119.  
  120. };
  121.  
  122. class Manager:public Employee
  123. {
  124.     private:
  125.         int bonus;
  126.  
  127.     public:
  128.         Manager(string name,int salary,int bonus) : Employee(name,salary)
  129.         {
  130.             this->bonus=bonus;
  131.         }
  132.         virtual ~Manager() {}
  133.         int GetBonus()
  134.         {
  135.             return bonus;
  136.         }
  137.         void PrintInfo()
  138.         {
  139.             Employee::PrintInfo();
  140.             cout<<", Bonus: "<<bonus;
  141.         }
  142. };
  143.  
  144.  
  145. #endif // EMPLOYEE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement