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 the difference between abstraction and polymorphism?

823


Whats is abstraction in oops?

815


How do you explain polymorphism?

776


what is graphics

2198


What is inheritance in simple words?

801


What is the real time example of encapsulation?

784


What does and I oop and sksksk mean?

845


class type to basic type conversion

2067


What is abstraction in oops with example?

974


Whats oop mean?

770


what type of questions

1875


What is for loop and its syntax?

784


What are classes oop?

780


What is class and example?

796


Which type does string inherit from?

811