#include<iostream>
#include<cmath>
using namespace std;
class dot{
public:
dot(double a,double b);
friend double dist(dot &,dot &);
void disp();
private:
double x;
double y;
};
dot::dot(double a, double b)
{
x=a;
y=b;
}
double dist(dot &D1,dot &D2)
{
return sqrt((D1.x-D2.x)*(D1.x-D2.x)+(D1.y-D2.y)*(D1.y-D2.y));
}
void dot::disp()
{
cout<<"坐标为:("<<x<<","<<y<<")"<<endl;
}
int main()
{
dot d1(2,4);
dot d2(4,6);
d1.disp();
d2.disp();
cout<<"这两个点之间的距离为:"<<dist(d1,d2)<<endl;
system("pause");
return 0;
}
4.22
最新推荐文章于 2024-05-27 09:12:51 发布