/*定义一个点Point,并定义成员函数double Distance(const& Point),求两点的距离。*/
#include<iostream>
#include<cmath>
using namespace std;
class Point{
private:
double x,y;
public:
Point(double x,double y)
{
this->x = x;
this->y = y;
}
double Getx()
{
return x;
}
double Gety()
{
return y;
}
double Distance(const Point &p) //定义拷贝构造函数
{
x -= p.x;
y -= p.y;
return sqrt(x*x+y*y);
}
void ShowPoint()
{
cout << "<" << Getx() << "," << Gety() << ">" << endl;
}
};
int main()
{
double x1,y1,x2,y2;
cout << "input two points:";
cin >> x1 >> y1 >> x2 >> y2;
Point P1(x1,y1);
Point P2(x2,y2);
P1.ShowPoint();
P2.ShowPoint();
cout << "the distance of the two points is:" << P1.Distance(P2) << endl;
return 0;
}