1815. 计算两点间的距离
Description
请用类描述顶点信息,输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
Input
输入数据第一行一个整数 n,代表测试数据组数,接下来 n 行,每行由 4 个实数组成,分别表示 x1,y1,x2,y2,数据之间用空格隔开。
Output
对于每组测试数据,输出一行,结果保留两位小数。
Sample Input
2 0 0 0 1 0 1 1 0
Sample Output
1.00 1.41
// source code of submission 992016, Zhongshan University Online Judge System
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class point
{
public:
void getpoint()
{
cin >> x >> y;
}
void showpoint(point & point1)
{
cout << fixed << setprecision(2) << sqrt(pow(fabs(x - point1.x), 2) + pow(fabs(y - point1.y), 2));
}
private:
double x,y;
};
int main()
{
int n;
cin >> n;
int i;
point point1, point2;
for (i = 0; i < n; i++)
{
point1.getpoint();
point2.getpoint();
point1.showpoint(point2);
cout << endl;
}
return 0;
}