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: