描述
定义一个Point类,用来描述平面上的一个点.要求支持以Point A,B(0,0)等方式完成对象的生成.定义友元函数Dist,计算并返回两点之间的距离
输入
两个点的坐标
输出
两点之间的距离(保留小数点后两位数)
样例输入
0 0 0 2
样例输出
2.00
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class Dist;
class Point{
double x,y;
public:
Point(int x,int y)
{
this->x=x;
this->y=y;
}
friend double Dist(Point A,Point B);
};
double Dist(Point A,Point B){
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
Point A(a,b);
Point B(c,d);
cout<<fixed<<setprecision(2)<<Dist(A,B)<<endl;
return 0;
}