Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4,6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 33 pages
Exam (elaborations)

COS3711 Assigment 2 2026 Year Module Due 2026

Document preview thumbnail
Preview 4 out of 33 pages

This assignment has been carefully put together to give you more than just answers; it walks you through the reasoning behind each one, so you actually understand the material rather than just memorising it. Every solution has been verified for accuracy, with academic references that hold up to scrutiny. Whether you're working through it the night before a submission or using it to reinforce your understanding over time, it's built to be genuinely useful. The explanations are clear without being condescending, and the structure follows what examiners actually look for not just what sounds impressive. If you put in the effort to engage with it properly, distinction-level results are well within reach.

Content preview

UNIVERSITY OF SOUTH AFRICA (UNISA)
College of Science, Engineering and Technology







ASSIGNMENT 2
Year Module — 2026







Module Code: COS3711

Module Name: Advanced Programming

Assignment No.: 2

Semester: Year Module 2026




Submitted in partial fulfilment of the requirements for Advanced Programming (COS3711)
at the University of South Africa.

,UNISA | COS3711 Assignment 2 — Advanced Programming



Question 1: Shape Inheritance Hierarchy and Qt GUI Application

This question requires building a Qt C++ application that draws shapes (squares, circles,
rectangles, and ellipses) using an abstract inheritance hierarchy. The design separates com-
mon pen and brush attributes into a base class, delegates one-property shapes (circles and
squares) to a mid-level abstract class, and handles two-property shapes (ellipses and rectan-
gles) through a further subclass.


1.1 Class Hierarchy Design


The hierarchy shown in the assignment UML follows a clean stratification. The Shape base
class holds three protected attributes: penWidth (int), penColour (QColor), and fillColour
(QColor). It declares draw() as a pure virtual function, making it abstract.

Shape1Property inherits from Shape and adds property1 (int), which represents the radius
for a circle or the side length for a square. It also declares draw() as pure virtual.

Shape2Property inherits from Shape1Property and adds property2 (int), representing the
second dimension needed by ellipses and rectangles. It too declares draw() as pure virtual.

Circle and Square each inherit directly from Shape1Property and provide concrete draw()
implementations.

Ellipse and Rectangle inherit from Shape2Property and provide their own concrete draw()
implementations.




Page 1 of 32

, UNISA | COS3711 Assignment 2 — Advanced Programming


Shape (abstract)
#penWidth: int
#penColour: QColor
#fillColour: QColor
+draw() = 0




Shape1Property (abstract)
#property1: int
+draw() = 0


Circle Square
+Circle() +Square()
+draw() +draw()

Shape2Property (abstract)
#property2: int
+draw() = 0




Ellipse Rectangle
+Ellipse() +Rectangle()
+draw() +draw()


Figure 1: Shape inheritance hierarchy for COS3711 Assignment 2



1.2 Header Files


shape.h


Listing 1: shape.h – Abstract base class
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 // Pure virtual -- all concrete shapes must implement this


Page 2 of 32

, UNISA | COS3711 Assignment 2 — Advanced Programming


14 virtual void draw ( QPainter & painter ) = 0;
15

16 // Getters
17 int getPenWidth () const { return penWidth ; }
18 QColor getPenColour () const { return penColour ; }
19 QColor getFillColour () const { return fillColour ; }
20

21 // Setters
22 void setPenWidth ( int w ) { penWidth = w ; }
23 void setPenColour ( QColor c ) { penColour = c ; }
24 void setFillColour ( QColor c ) { fillColour = c ; }
25

26 protected :
27 int penWidth ;
28 QColor penColour ;
29 QColor fillColour ;
30 };
31

32 # endif // SHAPE_H




Page 3 of 32

Connected book
 image
W. Richard Stevens, Stephen A. Rago Advanced Programming in the UNIX Environment
Publisher: 2013 ISBN: 9780321637734 Edition: Unknown

Document information

Uploaded on
March 23, 2026
Number of pages
33
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
R80,74

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
LectureLab
3,6
(86)
Sold
689
Followers
188
Items
1561
Last sold
3 days ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions