Write a program to demonstrate the use of 'Composition' in C++
Answer Posted / mahendra
Find the program below to demonstrate the composition.
first define the class called the DataBirth.
class DateOfBirth
{
public:
void UpdateDMY();
void GetDMY();
private:
int date,month,year;
};
define the Employee class.
class Employee
{
public:
void GetDetails();
void UpdateDetails();
private:
DateOfBirth BirthDate;
}
Here the EMployee class is having the object of the
DateOfBirth class as data member. With this the Employee
class is achieving the "has-a" relation with the
DateOfBorth class. In this way the Employee class can have
objects of the many calsses as members.
Is This Answer Correct ? | 14 Yes | 8 No |
Post New Answer View All Answers
how to get the oracle certification? send me the answer
What is destructor oops?
How to use CMutex, CSemaphore in VC++ MFC
How long to learn object oriented programming?
Can we create object of interface?
What are the 4 main oop principles?
Describe these concepts: Polymorphism, Inheritance and Abstraction.
What is encapsulation in oop?
i=20;k=0;
for(j=1;k-i;k+=j<10?4:3)
{
cout<
Can main method override?
What is the real life example of polymorphism?
Why oops is important?
Why do we use oops?
What are properties in oop?
What is coupling in oop?