c++定义一个平面坐标point类,设计成员函数求出给定两点间的距离

2025-04-14 18:36:53
推荐回答(1个)
回答1:

两点距离公式 (x1-x2)^2 + (y1-y2)^2 再开根。

float point::distance(const point& pt)
{
return sqrt((this.x-pt.x)*(this.x-pt.x) + (this.y-pt.y)*(this.y-pt.y)) ;

}

//sqrt 求平方根。

this应该用 -> 也就是 this->x 。笔误。