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 graphics

2004


What are classes oop?

594


What are the features of oop?

629


What is encapsulation with example?

574


What are oops methods?

562






Why we use classes in oop?

574


Why do we use inheritance?

628


If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?

939


What is the full form of oops?

605


How long to learn object oriented programming?

558


What is difference between class and object with example?

560


Write A Program to find the ambiguities in Multiple Inheritance? How are they resolved.(Virtual Functions)

3550


What does and I oop mean in text?

616


Describe these concepts: Polymorphism, Inheritance and Abstraction.

604


Why is destructor used?

578