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


Please Help Members By Posting Answers For Below Questions

Is this job good for future? can do this job post grduate student?

1694


What does I oop mean?

618


Why do we use class?

635


write string class as your own class in java without using any built-in function

1976


What is object and class in oops?

588






Why do we use class in oops?

555


What is the importance of oop?

611


What are benefits of oop?

639


What is persistence in oop?

673


What are the features of oop?

641


What is encapsulation in simple terms?

541


What is a class oop?

594


What is the types of inheritance?

604


How do you achieve runtime polymorphism?

571


What is encapsulation example?

549