COS3711 Assignment 1 Semester 1 2026 (Answer Guide)
VERIFIED AND CERTIFIED ANSWERS. WRITTEN IN REQUIRED FORMAT AND WITHIN
GIVEN GUIDELINES. IT IS GOOD TO USE AS A GUIDE AND FOR REFERENCE, NEVER
PLAGARIZE. Thank you and success in your academics.
UNISA, 2026
QUESTION 1
Object-Oriented Design: Vehicle Management Console Application (Qt)
1.1 Introduction and Design Approach
The objective of this question is to design and implement a Qt-based console
application that manages vehicle details while adhering strictly to object-oriented
programming (OOP) principles. The design avoids common anti-patterns such as
code duplication, tight coupling, and poor encapsulation.
To achieve this:
Inheritance is used to model shared vehicle characteristics.
Polymorphism is applied to allow different vehicle types to output their details
appropriately.
Encapsulation ensures that class attributes are protected and accessed through
getters and setters.
Qt’s parent–child (QObject) mechanism is used to manage a list of vehicles
safely and efficiently without manual memory management.
1.2 Identification of Required Classes
Based on the specification, the following classes are required:
1. Vehicle – Base class representing common vehicle attributes
2. PassengerVehicle – Derived class for vehicles that carry passengers
,2|Page
3. TransportVehicle – Derived class for vehicles that carry goods
4. Main application (main.cpp) – Used to test the implementation
1.3 Base Class: Vehicle
1.3.1 Purpose of the Class
The Vehicle class represents the general concept of a vehicle. It contains properties
that are common to all vehicles, namely:
Model
Year of manufacture
This class is designed as a QObject-derived class to enable the use of Qt’s parent–
child system.
1.3.2 Attributes
QString model – Stores the vehicle model
int year – Stores the year of manufacture
The year value is validated to ensure it is reasonable, meaning:
It is not earlier than the invention of modern vehicles
It is not later than the current year
1.3.3 Constructors
A default constructor assigns safe default values when no information is
provided.
This satisfies the requirement that vehicles created without necessary details
must still have valid values.
1.3.4 Getters, Setters, and Output Function
, 3|Page
class Vehicle : public QObject {
Q_OBJECT
public:
explicit Vehicle(QObject *parent = nullptr)
: QObject(parent), m_model("Unknown"), m_year(2000) {}
QString getModel() const {
return m_model;
}
void setModel(const QString &model) {
m_model = model;
}
int getYear() const {
return m_year;
}
void setYear(int year) {
if (year >= 1886 && year <= QDate::currentDate().year()) {
m_year = year;
}
}
virtual void printDetails() const {
qDebug() << "Model:" << m_model << ", Year:" << m_year;
}
private:
QString m_model;