将下面类定义补充完整,类Point是坐标点,Line是两点间的直线,Distance求出两点间的距离。
class Line;
class Point
{private:int x,y;
____________________;
public:Point(int i=0,int j=0){ x=i;y=j:}
};
class Line
{private:Point p1,p2;
public:Line(Point xpl,Point
将下面类定义补充完整,类Point是坐标点,Line是两点间的直线,Distance求出两点间的距离。
class Line;
class Point
{private:int x,y;
____________________;
public:Point(int i=0,int j=0){ x=i;y=j:}
};
class Line
{private:Point p1,p2;
public:Line(Point xpl,Point xp2):pl(xp1),p2(xp2){};
double Distance();
};
double Line::Distance()
{ double dx=p2.x-pl.x;
_______________;
return sqrt(dx*dx+dy*dy);
}
【正确答案】:friend class Line / friend void Line::Distance() , double dy=p2.y-p1.y注:每题答案有 2 处下划线,每答对一处得 2 分。
Top