Answer to Question #230077 in C++ for mahnoor

Question #230077

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.  


1
Expert's answer
2021-08-27T02:04:14-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS