#include<iostream>
#include<cmath>
using namespace std;
class Point{
public:
Point(int x = 0,int y = 0):x(x),y(y){
}
int Getx(){return x;
}
int Gety(){return y;
}
friend float dist( Point &a,Point &b);
private:
int x,y;
};
float dist(Point &a,Point &b){
double x = a.x - b.x;
double y = a.y - b.y;
return static_cast<float>(sqrt(x*x+y*y)) ;
}
int main(){
Point p1(4,5),p2(1,1);
cout<<"两点之间的距离为:"<<dist(p1,p2)<<endl;
return 0;
}
c++使用友元函数求两点之间的距离
最新推荐文章于 2024-03-27 10:43:45 发布