#include<iostream>
#include<cmath>
using namespace std;
class CPoint
{
private:
double x; // 横坐标
double y; // 纵坐标
public:
CPoint(double xx=0,double yy=0):x(xx),y(yy){}
double distance1(CPoint &);
friend double distance2(CPoint &,CPoint &);
double get_x(){return x;}
double get_y(){return y;}
};
double distance3(CPoint &a,CPoint &b){
return sqrt(((a.get_x()-b.get_x())*(a.get_x()-b.get_x())+(a.get_y()-b.get_y())*(a.get_y()-b.get_y())));
}
double distance2(CPoint &a,CPoint &b){
return sqrt(((a.get_x()-b.get_x())*(a.get_x()-b.get_x())+(a.get_y()-b.get_y())*(a.get_y()-b.get_y())));
}
double CPoint::distance1(CPoint &b){
return sqrt(((x-b.get_x())*(x-b.get_x())+(y-b.get_y())*(y-b.get_y())));
}
int main()
{ CPoint p1(10,13), p2(-5,6);
cout<<"1. "<<p1.distance1(p2)<<endl;
cout<<"2. "<<distance2(p1,p2)<<endl;
cout<<"3. "<<distance3(p1,p2)<<endl;
//system("pause");
return 0;
}
运行结果: