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


Please Help Members By Posting Answers For Below Questions

What is oops with example?

566


Why do we use inheritance?

630


What is polymorphism and types?

602


Is react oop?

611


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

2150






Why is polymorphism needed?

605


Can enum be null?

587


Why is abstraction used?

612


can inline function declare in private part of class?

3660


Plese get me a perfect C++ program for railway/airway reservation with all details.

3431


Which language is pure oop?

551


write string class as your own class in java without using any built-in function

1978


What are constructors in oop?

596


What does oop mean in snapchat?

688


Can we create object of abstract class?

577