一道有关c++继承的题目

来源:百度知道 编辑:UC知道 时间:2024/09/24 19:16:56
这是我们教材上的一道练习题(我把题目原文打上来):
Write an inheritance hierarchy for class Quadrilateral(四边形), Trapezoid(梯形), Parallelogram(平行四边形), Rectangle(矩形) and Square(正方形).Use Quadrilateral as the base class of the hierarchy. Make the hierarchy as deep(i.e., as many levels) as possible. The private data of Quadrilateral should be the x-y coordinate pairs for the four endpoints of the Quadrilateral.

大意是说用类"四边形"作基类,其他图形作为派生类.基类的私有数据是4个点对.

像教材上给的例子是point->circle->cylinder
这种继承是circle在point基础上加一个半径radius
cylinder在circle的基础上加一个高度height即可

但是这道题不同,他们的私有数据都是4个点,只不过4个点的相对位置不同而已

so,我想问,在这道题派生类定义中,相对基类应该添加哪些成员函数或成员数据?

thanks

在基类中加 对边相等或者平行 的判断函数做为虚函数
在各个继承类中再具体的重写判断函数 来判断是哪一种图形

成员函数:判断有效性,计算面积,计算周长

成员数据:4个点的坐标