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 oops with example?
Why do we use inheritance?
What is polymorphism and types?
Is react oop?
given a set based questions and 5 questions based on it next data sufficiciency questions 2 and 2/3 english sentence completion with options very easy and 2 synononmys paragraph with 10 questions 10 minutes replace =,-,*,% with -,%,+,* type questions 5 3 questions lik following itssickhere itssickthere itssickhere istsickhere which is nt alike the others very easy
Why is polymorphism needed?
Can enum be null?
Why is abstraction used?
can inline function declare in private part of class?
Plese get me a perfect C++ program for railway/airway reservation with all details.
Which language is pure oop?
write string class as your own class in java without using any built-in function
What are constructors in oop?
What does oop mean in snapchat?
Can we create object of abstract class?