Aggregation In Class Diagram with Examples.
#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.