-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAggregation.cpp
70 lines (62 loc) · 1.43 KB
/
Aggregation.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <string>
#define SIZE 2
using namespace std;
class Employee
{
private :
string empID;
string name;
public :
Employee(string pempID, string pname)
{
empID = pempID;
name = pname;
}
void displayEmployee()
{
cout << "empID = " << empID << endl;
cout << "name = " << name << endl;
cout << "**************************" << endl;
}
~Employee()
{
cout << "Deleting Employee " << empID << endl;
}
};
class Department
{
private:
Employee *emp[SIZE]; // Aggregation Relationship
public:
Department() {}
void addEmployee(Employee *emp1, Employee *emp2) {
emp[0] = emp1;
emp[1] = emp2;
}
void displayDepartment() {
for (int r=0; r < SIZE; r++)
emp[r]->displayEmployee();
}
~Department() {
cout << "Department Delete " << endl;
}
};
int main()
{
Employee *e1 = new Employee("E001", "Nimal");
Employee *e2 = new Employee("E002", "Jagath");
Department *ABC = new Department();
ABC->addEmployee(e1, e2);
ABC->displayDepartment();
delete ABC;
e2->displayEmployee();
e1->displayEmployee();
delete e1;
delete e2;
Employee *e3 = new Employee("E003", "Pradeep");
Employee *e4 = new Employee("E004", "Amila");
ABC->addEmployee(e3, e4);
ABC->displayDepartment();
return 0;
}