题意:请用类描述顶点信息,输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
题目链接:http://soj.me/1815
——>>别拿int到定义double的东西就好
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class node
{
private:
double x;
double y;
public:
node(double xx, double yy):
x(xx), y(yy){}
double dis(node b)
{
return hypot(x-b.x, y-b.y);
}
};
int main()
{
int n;
double x1, y1, x2, y2;
cin>>n;
while(n--)
{
cin>>x1>>y1>>x2>>y2;
node a(x1, y1), b(x2, y2);
cout<<setiosflags(ios::fixed)<<setprecision(2)<<a.dis(b)<<endl;
}
return 0;
}