Three level point/circle/cylinder hierarchy
- Point
- Circle
- x-y coordinate pair
- Radius
- Cylinder
- x-y coordinate pair
- Radius
- Height
Derive class Cylinder from class Circle4. Class Cylinder should redefine member functions getArea and print member functions. Figs. 4.26-4.27 present class Cylinder, which inherits from class Circle4.
Figure 4.26:
Cylinder class header file.
|
Figure 4.27:
Cylinder class inherits from class Circle4 and redefines member function
getArea.
|
Figure 4.28:
Point/Circle/Cylinder hierarchy test program. (part 1 of 2)
|
Figure 4.29:
Point/Circle/Cylinder hierarchy test program. (part 2 of 2)
|
We were able to develop classes Circle4 and Cylinder much more quickly by using inheritance than if we had developed these classes "from scratch". Inheritance avoids duplicating code and the associated code-maintenance problems.
2004-07-29