0% found this document useful (0 votes)
15 views2 pages

Association Task

The document outlines the implementation of UML class diagrams for aggregation and composition relationships in programming. It provides detailed steps for creating classes 'Address', 'Employee', 'Student', and 'Project', including constructor and destructor statements, data member accessibility, and method calls. The main method instructions involve creating dynamic objects, passing values, and invoking display methods, followed by memory management using the delete keyword.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Association Task

The document outlines the implementation of UML class diagrams for aggregation and composition relationships in programming. It provides detailed steps for creating classes 'Address', 'Employee', 'Student', and 'Project', including constructor and destructor statements, data member accessibility, and method calls. The main method instructions involve creating dynamic objects, passing values, and invoking display methods, followed by memory management using the delete keyword.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ASSOCIATION, COMPOSITION & AGGREGATION

(Has-A Relationship)

Aggregation:
Implement the following UML class diagram.

Address Employee

-addrLine: string -name:string


-city: string -id:int
-state: string -*addr:Address

+Address () +Employee ()

+Address (al:string, ct:string, state: string) +Employee(name:string,id:int,*addr:Address)

+~Address () +display (): void

+~Employee ()

After converting the UML class diagram into the code, perform the following steps:

STEPS:

1. Print the following statements in each constructor & destructor of both the Address &
Employee class.
Example:
“Address Constructor”, “Address Destructor”
“Employee Constructor”, “Employee Destructor”

2. Print the data members of the Address class (using the address pointer) in the display ()
method of Employee class. Since, the data members of the Address class are private, they
will not be accessible. You’ve to resolve this issue, so that they are accessible inside the
display () method of Employee class.

3. In the main () method:

a) Create a dynamic object (using pointers) of both the Address & Employee class.
b) Pass the appropriate values to the constructors of Address & Employee class.
c) Call the display method using the object of Employee class.
d) Delete the object of Employee class using the delete keyword. Observe the output.
Composition:
Implement the following UML class diagram.

Student Project

-id: int -name:string


-name: string -category:string
-proj: Project

+Student () +Project ()

+Student (id:int, name:string) +Project(name:string, category:string)

+display (): void +setProject(name:string,category:string):void

+~Student () +printProject (): void

+~Project ()

After converting the UML class diagram into the code, perform the following steps:

STEPS:

1. Print the following statements in each constructor & destructor of both the Student &
Project class.
Example:
“Student Constructor”, “Student Destructor”
“Project Constructor”, “Project Destructor”

2. Call the setProject () method (using the object of the Project class) in the parameterized
constructor of the Student class.

3. Call the printProject () method (using the object of the Project class) in the display ()
method of Student class.

4. In the main () method:

e) Create a dynamic object (using pointer) of Student class.


f) Pass the appropriate values to the constructor of Student class.
g) Call the display method using the object of Student class.
h) Delete the object of Student class using the delete keyword. Observe the output.

You might also like