Aggregation In Class Diagram with Examples.
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 |
#include <iostream> using namespace std; class Address { public: string Address_ByT4Tutorials; Address(string Address_ByT4Tutorials) { this->Address_ByT4Tutorials = Address_ByT4Tutorials; } }; class Student_ByT4Tutorials { private: Address* address; //Student_ByT4Tutorials HAS-A Address_ByT4Tutorials public: int id; string name; Student_ByT4Tutorials(string name, Address* address) { this->name = name; this->address = address; } void display() { cout<<id <<" "<<name<< " "<< address->Address_ByT4Tutorials<<endl; } }; int main(void) { Address a1= Address("United States"); Student_ByT4Tutorials e1 = Student_ByT4Tutorials("Bill Gates",&a1); e1.display(); return 0; } |
Examples of Aggregation
- A Teacher may belong to multiple departments.