问答题
下面程序用来求直角三角形斜边长度。
#include <iostream.h>
#include <math.h>
class Point
{ private:
double x, y;
______
public:
Point (double i = 0, double j = 0)
{x=i; y=j; }
Point( Point &p)
{x=p.x; y=p.y;}
};
class Line
{ private:
Point p1, p2;
public:
Line(Point &xp1, Point &xp2):______{}
double GetLength();
};
double Line::GetLength()
{ double dx=p2.x-p1.x;
double dy=p2.y-p1.y;
return sqrt( dx * dx + dy * dy);
}
void main()
{ Point p1, p2(6, 8);
Line L1 (p1, p2);
cout<<L1. GetLength()<<endl;
}
【参考答案】
friend class Line;
p1(xp1), p2(xp2)