AIM:-  A point on the two dimensional plane can be represented by two numbers: an X coordinate and a Y coordinate. The distance of the point from the origin can be calculated using Pythagorean Theorem. Write a program that uses a class called point to model a point. Allow user to perform following task on point: a. Set X coordinate

input:-

 

#include<iostream>

#include<math.h>

using namespace std;

class point

{

    int x=0,y=0;

    float x1,x2,y1,y2,d1,d2,d;

    

public:

    

    void accept()

    {

        cout<<“enter x1:”;

        cin>>x1;

        cout<<“enter y1:”;

        cin>>y1;

        // cout<<“enter x2:”;

        //cin>>x2;

        // cout<<“enter y2:”;

        //  cin>>y2;

        

    }

    

    void calculat()

    {

        d1=sqrt((x1x)+(y1y));

        // d2=(x2-x)+(y2-y);

        

        //d=sqrt(d1+d2);

        

    }

    

    void display()

    {

        cout<<“\n(x1,y1)=”<<“(“<<x1<<“,”<<y1<<“)”;

        //cout<<“\n(x2,y2)=”<<“(“<<x2<<“,”<<y2<<“)”;

        

        // cout<<“\n(d1,d2)=”<<“(“<<d1<<“,”<<d2<<“)”;

        cout<<“\ndistance d1:”<<d1;

        cout<<“\n”;

    }

    

    

};

int main()

{

    point p;

    p.accept();

    p.calculat();

    p.display();

    

    return 0

}

Output:-

enter x1:5

enter y1:5

(x1,y1)=(5,5)

distance d1:3.16228

 

Advertisements