1815. 计算两点间的距离(类实现)

来源:互联网 发布:烂番茄新鲜度100 知乎 编辑:程序博客网 时间:2024/05/08 12:03
Sicily 1815. 计算两点间的距离

Description

请用类描述顶点信息,输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。

 

Input

输入数据第一行一个整数 n,代表测试数据组数,接下来 n 行,每行由 4 个实数组成,分别表示 x1,y1,x2,y2,数据之间用空格隔开。

 

Output

对于每组测试数据,输出一行,结果保留两位小数。

 

Sample Input
 Copy sample input to clipboard
20 0 0 10 1 1 0
Sample Output
1.001.41

 1 #include <iostream> 2 #include <iomanip> 3 #include <cmath> 4 using namespace std; 5  6 class point 7 { 8 public: 9     void getpoint()10     {11         cin >> x >> y;12     }13     void showpoint(point & point1)14     {15         cout << fixed << setprecision(2) << sqrt(pow(fabs(x - point1.x), 2) + pow(fabs(y - point1.y), 2));16     }17 private:18     double x,y;19 };20 int main()21 {22     int n;23     cin >> n;24     int i;25     point point1, point2;26     for (i = 0; i < n; i++)27     {28         point1.getpoint();29         point2.getpoint();30         point1.showpoint(point2);31         cout << endl;32     }33     return 0;34 }



原创粉丝点击