c++计算两点之间的距离
#include<bits/stdc++.h>
using namespace std;
class point
{
private:
int a;
int b;
public:
point(int x=0,int y=0)
{
a=x;
b=y;
}
int xcord()
{
return a;
}
int ycord()
{
return b;
}
};
class Distance
{
private:
point p1,p2;
double lea;
public:
Distance(point q1,point q2)
{
p1=q1;
p2=q2;
int q=p1.xcord()-p2.xcord();
int w=p1.ycord()-p2.ycord();
lea=sqrt(q*q+w*w);
}
double display()
{
return lea;
}
};
int main()
{
point p1(3,5);
point p2(3,2);
Distance des(p1,p2);
cout<<des.display()<<endl;
}