Write a program to demonstrate the use of 'Composition' in C++
Answer Posted / 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 |
Post New Answer View All Answers
How do you achieve polymorphism?
What is protected in oop?
How do you use inheritance in unity?
What is the oops and benefits of oops programming?
What is encapsulation with real life example?
Which language is pure oop?
Which method cannot be overridden?
What are the benefits of interface?
What is the real life example of polymorphism?
What is the point of polymorphism?
i got a backdoor offer in process global,Bangalore..Can i work with it?
Please send ford technologies placement paper 2 my mail id
Can you explain polymorphism?
What are the three main types of variables?
What is the significance of classes in oop?