College of Science, Engineering and Technology
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄
COS3711: Advanced Programming
Assignment 2 — 2026
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄
COS3711
Module Code:
Advanced Programming
Module Name:
Assignment 2
Assignment:
2026
Year:
Submitted in partial fulfilment of the require-
ments for Advanced Programming — UNISA 2026
,UNISA | COS3711 Advanced Programming – Assignment 2
Question 1: Inheritance Hierarchy and Shape Drawing Application
Object-oriented design makes drawing applications considerably cleaner when shapes share
common properties. The Qt framework is well suited for this kind of work because its QPainter
API maps naturally onto pen-and-brush abstractions, and its widget system handles the ren-
dering surface (Stroustrup, 2013). The class hierarchy specified in the assignment separates
shared state from shape-specific measurements, which is exactly what abstract base classes
are for.
1.1 Design Overview
The hierarchy has three abstract layers and four concrete leaf classes. Shape holds pen width,
pen colour, and fill colour. Shape1Property extends Shape with one integer property (used
as radius for circles or side-length for squares). Shape2Property extends Shape1Property
with a second integer property (used for the second dimension of rectangles and ellipses).
The four concrete classes, Circle, Square, Ellipse, and Rectangle, each implement the pure
virtual draw() function. The UML diagram below captures this structure.
Shape
penWidth, penColour, fillColour
draw()
Shape1Property
property1
draw()
Shape2Property
property2
draw()
Circle Square
draw() draw()
Ellipse Rectangle
draw() draw()
Figure 1: UML inheritance hierarchy for the Shapes application
Page 2 of 30
, UNISA | COS3711 Advanced Programming – Assignment 2
1.2 Header Files
shape.h
1 # ifndef SHAPE_H
2 # define SHAPE_H
3
4 # include < QColor >
5 # include < QPainter >
6
7 class Shape {
8 public :
9 Shape () ;
10 Shape ( int penWidth , QColor penColour , QColor fillColour ) ;
11 virtual ~ Shape () {}
12
13 // Getters
14 int getPenWidth () const ;
15 QColor getPenColour () const ;
16 QColor getFillColour () const ;
17
18 // Setters
19 void setPenWidth ( int pw ) ;
20 void setPenColour ( QColor pc ) ;
21 void setFillColour ( QColor fc ) ;
22
23 virtual void draw ( QPainter & painter ) = 0;
24
25 protected :
26 int m_penWidth ;
27 QColor m_penColour ;
28 QColor m_fillColour ;
29 };
30
31 # endif // SHAPE_H
Page 3 of 30