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 graphics
What are classes oop?
What are the features of oop?
What is encapsulation with example?
What are oops methods?
Why we use classes in oop?
Why do we use inheritance?
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
What is the full form of oops?
How long to learn object oriented programming?
What is difference between class and object with example?
Write A Program to find the ambiguities in Multiple Inheritance? How are they resolved.(Virtual Functions)
What does and I oop mean in text?
Describe these concepts: Polymorphism, Inheritance and Abstraction.
Why is destructor used?