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
Exam (elaborations)

COS3711 Assignment 1 (QUALITY ANSWERS) 2026

Rating
-
Sold
-
Pages
29
Grade
A+
Uploaded on
16-02-2026
Written in
2025/2026

This document provides detailed workings, clear explanations, and well-structured solutions for the COS3711 Assignment 1 (QUALITY ANSWERS) 2026 - For assistance call or Whats-App us on 0.8.1..2.7.8..3.3.7.2 .... Question 1 For this question you need to ensure that you design the appropriate classes needed to address the specification below. Create a console application to handle vehicle details. Considering the required functionality that is required and OOP design principles (avoiding anti-patterns and having minimal redundant code), create and implement the appropriate classes necessary to achieve the following. • A vehicle needs to have a model and a year (which should be a reasonable value). There are basically 2 types of vehicles: passenger vehicles (that can carry a specified number of passengers) and transport vehicles (that have a set carrying capacity expressed in kilograms). Vehicles that are created without the necessary details should have default values. • Ensure all appropriate getters and setters are included. • Include a function that can output the details of the vehicle. • Use Qt’s parent-child facility to implement a list of vehicles. • Test your solution by creating some passenger and transport vehicles (at least one of which is created using the default constructor), adding them to the list, and then outputting the values in the list to the console. Question 2 This question tests the concepts of reflection and meta-objects. Extend the application you wrote in question 1 by adding a class named FileWriter as described in the UML class diagram below: Downloaded by Polar magnats () lOMoARcPSD| COS3711/Assignment 1/2026 3 The write() function should use the meta-object of the items in list to write each item’s type of vehicle, properties and their values to a text file named in filename. You should use reflective programming techniques to do this, and should not use the getters or the toString() functions to extract the type of vehicle and the data from each item in the list. Thus you cannot assume that you know what properties an item holds. The function should return the number of items that were written to file. From main(), create an instance of the FileWriter class, passing the list of vehicles (as a QObjectList) and a file name, and then write the list to file. Display the number of records printed to the console. Question 3 This question focuses on model-view programming. A reference for a journal article needs the following data: the author, year of publication, article title, journal name, volume and issue numbers, and the pages on which the article can be found. Using a QStandardItemModel and an appropriate view, create a database for journal articles. The user should be able to do the following. • Sort on any column in view. • Add data to the database. • Remove data from the database. • Filter the database on any of the fields (except the page numbers). The user should be able to provide a wildcard filter and select which field to filter the database on. Then only fields that meet the requirements should be displayed. There should also be an option to clear the filter so that all records are displayed again. Additionally, a year value later than the current year should not be allowed (and you can decide how you will deal with situations where this is attempted). Also, if a reference is older than 10 years, highlight the row in red; if within the last 5 years, highlight in green. Note that you cannot assume that the current year is 2025. Note further that if the year should be changed in the view, it should not be allowed to be later than the current year, and the highlight colour of the row should still change appropriately. Below is an example of a possible interface. Downloaded by Polar magnats () lOMoARcPSD| COS3711/Assignment 1/2026 4 Question 4 This question looks at validating user input. Extend the application developed in question 3 so that only valid input is allowed in the cases where strings have been used to input data. Remember that such validation should take place both when data is input and when it is edited. Note the following. • An author’s name could be names like “SZ Mbanjwa-Mhlana”. You should assume that no full stops will be used with author initials, and that no other special characters should be allowed. • Assume (for this exercise) that article and journal titles can allow letters of the alphabet (“Journal”, for example), numbers, and spaces. However, do not allow a word in the title to contain both alphabetic characters and numbers in the same word – that is, 3D should not be allowed. • The page numbers should be of the form “12-15” or “121 - 155”.

Show more Read less

Content preview

COS3711
Assignment 1 2026

Unique number:

Due Date: 2026



This document includes:

 Helpful answers and guidelines
 Detailed explanations and/ or calculations
 References




Connect with the tutor on

+27 81 278 3372

, QUESTION 1

// main.cpp (Qt Console Application)
//
// qmake:
// QT += core
// CONFIG += console c++17
//
// What this includes (Question 1):
// - Vehicle base class: model + year (validated) + defaults
// - PassengerVehicle: passengerCount
// - TransportVehicle: capacityKg
// - Getters + setters
// - details() function to output vehicle details (polymorphic)
// - VehicleList uses Qt parent-child ownership for the vehicles
// - main() creates vehicles (incl. one default ctor), adds to list, prints
to console

#include <QCoreApplication>
#include <QDate>
#include <QList>
#include <QTextStream>

// ---------------------------
// Vehicle (base class)
// ---------------------------
class Vehicle : public QObject
{
public:
explicit Vehicle(QObject* parent = nullptr)
: QObject(parent)
, m_model(defaultModel())
, m_year(defaultYear())
{}

Vehicle(const QString& model, int year, QObject* parent = nullptr)
: QObject(parent)
{
setModel(model);
setYear(year);
}

virtual ~Vehicle() = default;

// Getters
QString model() const { return m_model; }
int year() const { return m_year; }

// Setters (validated)
void setModel(const QString& model)
{
const QString trimmed = model.trimmed();
m_model = trimmed.isEmpty() ? defaultModel() : trimmed;
}

void setYear(int year)
{
m_year = isReasonableYear(year) ? year : defaultYear();
}




© Study Shack 2026. All rights Reserved +27 81 278 3372

, // Output function
virtual QString details() const
{
return QString("Type=Vehicle, Model=%1,
Year=%2").arg(m_model).arg(m_year);
}

protected:
static QString defaultModel() { return "Unknown Model"; }

static int defaultYear()
{
return QDate::currentDate().year();
}

static bool isReasonableYear(int y)
{
const int current = QDate::currentDate().year();
return (y >= 1886 && y <= current + 1);
}

private:
QString m_model;
int m_year;
};

// ---------------------------
// PassengerVehicle
// ---------------------------
class PassengerVehicle : public Vehicle
{
public:
explicit PassengerVehicle(QObject* parent = nullptr)
: Vehicle(parent)
, m_passengers(defaultPassengers())
{}

PassengerVehicle(const QString& model, int year, int passengers,
QObject* parent = nullptr)
: Vehicle(model, year, parent)
{
setPassengerCount(passengers);
}

int passengerCount() const { return m_passengers; }

void setPassengerCount(int count)
{
m_passengers = (count >= 1 && count <= 15) ? count :
defaultPassengers();
}

QString details() const override
{
return QString("Type=PassengerVehicle, Model=%1, Year=%2,
Passengers=%3")
.arg(model())
.arg(year())
.arg(m_passengers);
}




© Study Shack 2026. All rights Reserved +27 81 278 3372

Document information

Uploaded on
February 16, 2026
Number of pages
29
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

R75,00
Get access to the full document:

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

Get to know the seller

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.
StudyShack Cornerstone College, Pretoria, Gauteng
View profile
Follow You need to be logged in order to follow users or courses
Sold
31020
Member since
9 year
Number of followers
13941
Documents
2074
Last sold
4 days ago
Study Guides for Unisa Students

4,1

1822 reviews

5
1002
4
342
3
267
2
81
1
130

Recently viewed by you

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