#include<iostream>
using namespace std;
class dot{
public:
dot(float i,float j)
{
x=i;
y=j;
}
static void show(dot &d)
{
cout<<"点的坐标为:"<<"("<<d.x<<","<<d.y<<")"<<endl;
}
friend void dist(dot&,dot&);
private:
float x;
float y;
};
void dist(dot& a,dot& b)
{
float sum=(b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y);
cout<<"这两点间的距离为:"<<sqrt(sum)<<endl;
}
int main()
{
dot d1(3,4);
dot::show(d1);
dot d2(0,0);
dot::show(d2);
dist(d1,d2);
system("pause");
return 0;
}
作业4.22
最新推荐文章于 2024-05-27 09:12:51 发布