Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///MAIN
- #include <iostream>
- #include"Nodo_.h"
- #include"Employee_.h"
- int main(){
- Employee *emp1=new Employee(string("Ciro Espostio"),1000);
- Employee *emp2=new Employee(string("Gennaro Espostio"),2000);
- Employee *emp3=new Manager(string("Carmine Espostio"),2000,2000);
- Employee *emp4=new Manager(string("Salvatore Espostio"),3000,3000);
- Nodo n1,n2,n3,n4;
- //Creo una lista di Employee
- n1.SetEmployee(emp1);
- n1.SetNext(&n2);
- n2.SetEmployee(emp2);
- n2.SetNext(&n3);
- n3.SetEmployee(emp3);
- n3.SetNext(&n4);
- n4.SetEmployee(emp4);
- n4.SetNext(nullptr);
- //Stampo le info di ogni impiegato
- n1.GetEmployee();
- //Employee tmp1, tmp2;
- //tmp1=*emp1;
- //tmp2=*emp2;
- int somma= *emp1+*emp2;
- somma+=*emp3+*emp4;
- cout<<endl<<"La somma dei salari e': "<<somma;
- }
- ///.H NODO
- #ifndef NODO_H
- #define NODO_H
- #include"Employee_.h"
- class Nodo
- {
- private:
- Nodo *Next;
- Employee *Emp;
- public:
- Nodo() {}
- virtual ~Nodo() {}
- void SetNext(Nodo *Emp)
- {
- this->Next=Emp;
- }
- Nodo* GetNext()
- {
- return this->Next;
- }
- void SetEmployee(Employee *Emp)
- {
- this->Emp=Emp;
- }
- void GetEmployee()
- {
- while(GetNext()!=nullptr)
- {
- Emp->PrintInfo();
- this->Emp=GetNext()->Emp;
- this->Next=GetNext()->Next;
- }
- Emp->PrintInfo();
- }
- };
- #endif // NODO_H
- ///.IMPIEGATO
- #ifndef EMPLOYEE_H
- #define EMPLOYEE_H
- #include<string>
- using namespace std;
- class Employee
- {
- private:
- string name;
- int salary;
- public:
- Employee(){};
- Employee(string name,int salary)
- {
- this->name=name;
- this->salary=salary;
- }
- virtual ~Employee() {}
- string GetName()
- {
- return name;
- }
- void SetSalary(int salary)
- {
- this->salary=salary;
- }
- int GetSalary()
- {
- return salary;
- }
- virtual void PrintInfo()
- {
- cout<<endl<<"Nome: "<<name<<", Stipendio: "<<salary;
- }
- int operator+ (Employee add)
- {
- return GetSalary()+add.GetSalary();
- }
- };
- class Manager:public Employee
- {
- private:
- int bonus;
- public:
- Manager(string name,int salary,int bonus) : Employee(name,salary)
- {
- this->bonus=bonus;
- }
- virtual ~Manager() {}
- int GetBonus()
- {
- return bonus;
- }
- void PrintInfo()
- {
- Employee::PrintInfo();
- cout<<", Bonus: "<<bonus;
- }
- };
- #endif // EMPLOYEE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement