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 (ANSWERS) 2026 - DISTINCTION GUARANTEED

Rating
5,0
(1)
Sold
7
Pages
26
Grade
A+
Uploaded on
16-02-2026
Written in
2025/2026

Comprehensively structured COS3711 Assignment 1 (ANSWERS) 2026 - DISTINCTION GUARANTEED. Prepared to a distinction standard with detailed and well-developed responses... 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
QUESTION 1

#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;


DISCLAIMER & TERMS OF USE
 Educational Aid: These study notes are intended to be used as educational resources and should not be seen as a
replacement for individual research, critical analysis, or professional consultation. Students are encouraged to perform
their own research and seek advice from their instructors or academic advisors for specific assignment guidelines.
 Personal Responsibility: While every effort has been made to ensure the accuracy and reliability of the information in
these study notes, the seller does not guarantee the completeness or correctness of all content. The buyer is
responsible for verifying the accuracy of the information and exercising their own judgment when applying it to their
assignments.
 Academic Integrity: It is essential for students to maintain academic integrity and follow their institution's policies
regarding plagiarism, citation, and referencing. These study notes should be used as learning tools and sources of
inspiration. Any direct reproduction of the content without proper citation and acknowledgment may be considered
academic misconduct.
 Limited Liability: The seller shall not be liable for any direct or indirect damages, losses, or consequences arising from
the use of these notes. This includes, but is not limited to, poor academic performance, penalties, or any other negative
consequences resulting from the application or misuse of the information provided.

, For additional support +27 81 278 3372

QUESTION 1

#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 (with validation)
void setModel(const QString& model)
{
// Default if blank/whitespace
const QString trimmed = model.trimmed();
m_model = trimmed.isEmpty() ? defaultModel() : trimmed;
}

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

// Polymorphic detail output
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()
{
// Use current year as a sensible default
return QDate::currentDate().year();
}

, For additional support +27 81 278 3372


static bool isReasonableYear(int y)
{
// First practical car year ~1886; allow up to next year for new
models
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)
{
// Reasonable passenger count for typical passenger vehicles
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);
}

private:
static int defaultPassengers() { return 4; }
int m_passengers;
};

// ---------------------------
// TransportVehicle
// ---------------------------
class TransportVehicle : public Vehicle
{
public:

Document information

Uploaded on
February 16, 2026
Number of pages
26
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

Reviews from verified buyers

Showing all reviews
3 months ago

5,0

1 reviews

5
1
4
0
3
0
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

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.
Edge
View profile
Follow You need to be logged in order to follow users or courses
Sold
10785
Member since
3 year
Number of followers
4256
Documents
3143
Last sold
2 hours ago

4,2

1340 reviews

5
753
4
269
3
201
2
36
1
81

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