#include<iostream>
#include<cmath>
using namespace std;
class Point{
float x1,y1,x2,y2;
public:
Point(float a,float b,float c,float d)
{x1=a,y1=b,x2=c,y2=d;}
float length()
{return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
};
int main()
{float x1=1,y1=2,x2=3,y2=4;
Point s2(x1,y1,x2,y2);
cout<<"两点间距离为:"<<s2.length<<'\n';
return 0;
}
可以运行,结果为:
我的本意是想求直角坐标系两点间的距离,但结果不对