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 the difference between abstraction and polymorphism?
Whats is abstraction in oops?
How do you explain polymorphism?
what is graphics
What is inheritance in simple words?
What is the real time example of encapsulation?
What does and I oop and sksksk mean?
class type to basic type conversion
What is abstraction in oops with example?
Whats oop mean?
what type of questions
What is for loop and its syntax?
What are classes oop?
What is class and example?
Which type does string inherit from?