Write a program to demonstrate the use of 'Composition' in C++
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / jojo
#ifndef POINT2D_H
#define POINT2D_H
#include <iostream>
class Point2D
{
private:
int m_nX;
int m_nY;
public:
// A default constructor
Point2D()
: m_nX(0), m_nY(0)
{
}
// A specific constructor
Point2D(int nX, int nY)
: m_nX(nX), m_nY(nY)
{
}
// An overloaded output operator
friend std::ostream& operator<<(std::ostream& out, const
Point2D &cPoint)
{
out << "(" << cPoint.GetX() << ", " << cPoint.GetY()
<< ")";
return out;
}
// Access functions
void SetPoint(int nX, int nY)
{
m_nX = nX;
m_nY = nY;
}
int GetX() const { return m_nX; }
int GetY() const { return m_nY; }
};
#endif
| Is This Answer Correct ? | 1 Yes | 3 No |
How can we use the preprocessor #if and #elseif.
if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?
what is object oriented programming and procedure oriented programming?
What is for loop and its syntax?
Where is pseudocode used?
Pls...could any one tell me that whether we can access the public data memeber of a class from another class with in the same program. Awaiting for your response Thanku
What is encapsulation in oops?
string is a class or data type in java?
What is differance between Abstract and Interface
What is the outcome of the line of code "cout<<abs(- 16.5);"? 1) 16 2) 17 3) 16.5
How to hide the base class functionality in Inheritance?
What language is oop?