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
Document preview thumbnail
Vista previa 3 fuera de 29 páginas
Examen

COS3711 Assignment 1 (QUALITY ANSWERS) 2026

Document preview thumbnail
Vista previa 3 fuera de 29 páginas

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”.

Vista previa del contenido

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

Libro relacionado
 image
Marcus Richards Python Advanced Programming
Editorial: Desconocido ISBN: 9781657482852 Edición: Desconocido

Información del documento

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

¿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

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.
StudyShack
4.1
(1828)
Vendido
31072
Seguidores
13941
Artículos
2089
Última venta
2 horas hace



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