> 数学 >
定义point累来描述平面上的点,包含私有数据成员x和y.定义友元函数distance计算两点距离(说明两点p1(x1,y1),p2(x2,y2),则两点距离=根号(x1减去x2差的平方加上y1和y2差的平方)
人气:129 ℃ 时间:2020-06-18 19:10:33
解答
#include
class POINT
{
public;
Point(double a,double b){ x=a;y=b};
fiend double square(Point &a,Point &b);
private:
double x,y;
};
double square(Point &a,Point &b) { return sqr((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))};
void main()
{
Point p1(x1,y1),p2(x2,y2);
double l;
l=square(p1,p2);
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版