#include<iostream>
#include<cmath>
using namespace std;
class dot{
public:
dot(float a,float b)
{
x=a;
y=b;
}
void show(dot& j,dot& k)
{
cout<<"A点的坐标为:("<<j.x<<","<<j.y<<")"<<endl;
cout<<"B点的坐标为:("<<k.x<<","<<k.y<<")"<<endl;
cout<<"两点的距离为:"<<dist(j,k)<<endl;
}
friend float dist(dot& j,dot& k);
private:
float x;
float y;
};
float dist(dot& j,dot& k)
{
float w;
w=sqrt(pow((j.x-k.x),2)+pow((j.y-k.y),2));
return w;
}
int main()
{
dot dot1(0,0);
dot dot2(1,1);
dist(dot1,dot2);
dot1.show(dot1,dot2);
return 0;
}
4.22两点之间的距离
最新推荐文章于 2024-08-04 15:08:55 发布