Problem Description定义点类Point,其中有数据成员x和y,表示点的横坐标与纵坐标。成员函数double Distance(const Point &)的功能是求两点之间的距离。请完善下面的程序。
//你的代码将被嵌在这里
int main()
{
Point a,b;
a.setPoint();
b.setPoint();
cout<<a.Distance(b);
return 0;
}
Input Description从键盘输入a点的横坐标、纵坐标;
从键盘输入b点的横坐标、纵坐标。
Output Description在一行中输出点a和点b之间的距离。Sample Input0 0 3 4
Sample Output5
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
public:
void setPoint()
{
cin >> x >> y;
}
double x;
double y;
double Distance(const Point&p)
{
return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}
};