下面程序用来求直角三角形斜边长度。
#include ﹤iostream. h﹥
#include ﹤math.h﹥
class Line;
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;
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;
}