Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Examen

COS3711 Assignment 1 (DETAILED ANSWERS)2026 - DISTINCTION GUARANTEED

Puntuación
-
Vendido
-
Páginas
27
Grado
A+
Subido en
16-02-2026
Escrito en
2025/2026

COS3711 Assignment 1 (DETAILED ANSWERS)2026 - DISTINCTION GUARANTEED - DISTINCTION GUARANTEED - DISTINCTION GUARANTEED Answers, guidelines, workings and references.. 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”.

Mostrar más Leer menos
Institución
Grado

Vista previa del contenido

COS3711
Assignment 1 2026
Unique number:
Due Date: 2026

Detailed solutions, explanations, workings
and references.


+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();
}



Varsity Cube 2026 +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:



Varsity Cube 2026 +27 81 278 3372

Libro relacionado

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
16 de febrero de 2026
Número de páginas
27
Escrito en
2025/2026
Tipo
Examen
Contiene
Preguntas y respuestas

Temas

$4.82
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
VarsityC AAA School of Advertising
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
29069
Miembro desde
8 año
Número de seguidores
13262
Documentos
3383
Última venta
2 días hace

4.1

2890 reseñas

5
1531
4
590
3
402
2
122
1
245

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes