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 use inheritance in unity?
Why oops is important?
Which language is not a true object oriented programming language?
What is difference between multiple inheritance and multilevel inheritance?
What is an example of genetic polymorphism?
What is oops and why we use oops?
What do you mean by overloading?
What is abstraction in oops?
Give an example where we have to specifically use C programming language and C++ programming language cannot be used?
which feature are not hold visual basic of oop?
What does and I oop mean in text?
Can a destructor be called directly?
What is abstraction with example?
What are main features of oop?
What is the purpose of polymorphism?