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
What is encapsulation in simple terms?
What exactly is polymorphism?
Why do we use polymorphism?
What is oops and its features?
Can we have inheritance without polymorphism?
What is a function in oop?
What is destructor example?
What is difference between inheritance and polymorphism?
Why multiple inheritance is not possible?
What is difference between oop and pop?
Can main method override?
What is polymorphism in oop example?
write a C++ program for booking using constructor and destructor.
Advantage and disadvantage of routing in telecom sector
Why is static class not inherited?