定义Point类和Line类,其中Line类是Point类的友元类,包含两个Point对象,分别表示起点和终点,根据程序框架补充必要的函数,并实现Line的len函数,计算线段的长度。
#include
using namespace std;
class Point {
private:
int x;
int y;
};
class Line {
private:
Point sp; // start point
Point ep; // end point
public:
double len() const; // 计算线段长度
};
void main() {
Point p1(1, 1), p2(5, 6);
Line li(p1, p2);
cout << "Line len = " << li.len() << endl;
}