Exercises in this lecture               Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home      

Exercise 7.2
Polygons, Quadrangles and Squares

The purpose of this exercise is to get some experience with programming of classes in a pure specialization hierarchy.

I have programmed the class Polygon. The well-known class Point, which we have seen several times during the course, is used as a building block of class Polygon type. (Notice that class Point has a MidPoint operation and a RotateAroundPoint operation).

The class Polygon has the following public operations:

  • A constructor.
  • Rank: The number of edges of the polygon
  • Circumference: The sum of the edge lengths.

Now program the following specializations of Polygon:

  • Quadrangle
  • Square

For the sake of simplicity you are allowed (but not forced) to assume that the edges of the square are parallel with the x-axis and the y-axis.

Please refer to the Polygon type hierarchy on the accompanying slide.

Quadrangle and Square should support the same operations as Polygon. In particular Quadrangle and Square should support adequate constructors of their own.

It is not necessary to use four points for representation of a square. Discuss this problem and try to find a solution.