22. Consider a class point containing x and y coordinates.Write necessary functions for the following cases: 1. to accept a point 2. to display it 3. to find distance between two points using operator overloading (-)(Use friend function).


#include<iostream.h>
#include<conio.h>
class point
{
public:
int x,y;
public:
void get()
{
cout<<“\nEnter Two co-ordinate: \n”;
cin>>x>>y;
}
void disp()
{
cout<<“X= “<<x<<“\tY= “<<y;
}
friend point operator-(point &);
};
point operator-(point &t1,point &t2)
{
point z;
z.x=t1.x-t2.x;
z.y=t1.y-t2.y;
return z;
}
void main()
{

point p1,p2,p3;
clrscr();
p1.get();
p2.get();
cout<<“\n\n\tFirst point: “;
p1.disp();
cout<<“\n\n\tSecond point: “;
p2.disp();
p3=p1-p2;
cout<<“\n\nDistance between two Point: “;
p3.disp();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s