ASSIGNMENT 1 2026
UNIQUE NO.
DUE DATE: 15 MAY 2026
, Advanced Programming - COS3711
Question 1: Vehicle Console Application (OOP + Qt Parent-Child)
Vehicle Base Class (vehicle.h)
#ifndef VEHICLE_H
#define VEHICLE_H
#include <QObject>
#include <QString>
class Vehicle : public QObject
{
Q_OBJECT
Q_PROPERTY(QString model READ getModel WRITE setModel)
Q_PROPERTY(int year READ getYear WRITE setYear)
public:
explicit Vehicle(QObject *parent = nullptr);
Vehicle(QString model, int year, QObject *parent = nullptr);
QString getModel() const;
int getYear() const;
void setModel(const QString &model);
void setYear(int year);
virtual QString toString() const;
protected:
QString model;
int year;
};
#endif
Vehicle Implementation (vehicle.cpp)
#include "vehicle.h"
Vehicle::Vehicle(QObject *parent) : QObject(parent), model("Unknown"),
year(2000) {}
Vehicle::Vehicle(QString model, int year, QObject *parent)
: QObject(parent), model(model), year(year > 1885 ? year : 2000) {}
QString Vehicle::getModel() const { return model; }
int Vehicle::getYear() const { return year; }
void Vehicle::setModel(const QString &model) { this->model = model; }