Create a class Coordinates having two attributes X and Y and relative methods for it. Create another class Point which will carry the object form coordinates class.
Create two points and display their X and Y coordinates.
#include <iostream>
using namespace std;
class Coordinates{
private:
int X;
int Y;
public:
void setX(int x){
X=x;
}
int getX(){
return X;
}
void setY(int y){
Y=y;
}
int getY(){
return Y;
}
};
class Point{
public:
Coordinates c;
int X=c.getX();
int Y=c.getY();
};
int main()
{
Coordinates c1;
c1.setX(12);
c1.setY(23);
Point p;
cout<<"\nX= "<<p.X;
cout<<"\nY= "<<p.Y;
return 0;
}
Comments
Leave a comment