#include<iostream.h>
#include<conio.h>
class point
{
int x;
int y;
public:
void accept()
{
cout<<endl<<"Enter x,y co-ordinates of point: ";
cin>>x>>y;
}
void display()
{
cout<<endl<<"X:"<<x<<" Y:"<<y;
}
friend point operator-(point p1,point p2);
};//End of class
point operator-(point p1,point p2)
{
point temp;
temp.x=p1.x-p2.x;
temp.y=p1.y-p2.y;
return temp;
}
int main()
{
point p1,p2,p3;
clrscr();
p1.accept();
p2.accept();
cout<<endl<<"Point P1 is: ";
p1.display();
cout<<endl<<"Point P2 is: ";
p2.display();
p3=p1-p2;
cout<<endl<<"Distance between point P1 and P2: ";
p3.display();
getch();
return 0;
}
Post a Comment