COS3711
Assignment 3 2024
Detailed Solutions, References & Explanations
Unique number:
Due Date: 9 September 2024
QUESTION 1
### Staff.h
/// cpp
#ifndef STAFF_H
#define STAFF_H
#include <QString>
#include <QDate>
class Staff {
public:
enum class AppointmentType { Permanent, PartTime, Contract };
Staff(const QString& name, const QDate& birthdate, AppointmentType
type);
// Getters
QString getName() const;
QDate getBirthdate() const;
QString getAppointmentType() const;
// Setters
void setName(const QString& name);
void setBirthdate(const QDate& birthdate); Terms of use
void setAppointmentType(const QString& type);
By making use of this document you agree to:
• Use this document as a guide for learning, comparison and reference purpose,
• Not to duplicate, reproduce and/or misrepresent the contents of this document as your own work,
• Fully accept the consequences should you plagiarise or misuse this document.
Disclaimer
Extreme care has been used to create this document, however the contents are provided “as is” without
any representations or warranties, express or implied. The author assumes no liability as a result of
reliance and use of the contents of this document. This document is to be used for comparison, research
and reference purposes ONLY. No part of this document may be reproduced, resold or transmitted in any
form or by any means.
, +27 67 171 1739
QUESTION 1
Sure, let me provide a high-level design and implementation outline for the application
using C++ with the Qt framework. We'll create the necessary classes to handle this
functionality while ensuring proper separation of concerns.
### High-Level Class Structure
1. Staff class: Represents an individual staff member.
2. StaffList class: Manages a list of Staff objects.
3. StaffWriter class: Handles writing Staff objects to a file.
4. MainWindow class: Provides GUI for user interaction.
### Staff.h
/// cpp
#ifndef STAFF_H
#define STAFF_H
#include <QString>
#include <QDate>
class Staff {
public:
enum class AppointmentType { Permanent, PartTime, Contract };
Staff(const QString& name, const QDate& birthdate,
AppointmentType type);
// Getters
QString getName() const;
QDate getBirthdate() const;
QString getAppointmentType() const;
// Setters
void setName(const QString& name);
void setBirthdate(const QDate& birthdate);
void setAppointmentType(const QString& type);
private:
QString name;
QDate birthdate;
AppointmentType appointmentType;
Disclaimer
Extreme care has been used to create this document, however the contents are provided “as is” without
any representations or warranties, express or implied. The author assumes no liability as a result of
reliance and use of the contents of this document. This document is to be used for comparison, research
and reference purposes ONLY. No part of this document may be reproduced, resold or transmitted in any
form or by any means.
, +27 67 171 1739
// Static method to convert between QString and AppointmentType
static QString appointmentTypeToString(AppointmentType type);
static AppointmentType stringToAppointmentType(const QString&
type);
};
#endif // STAFF_H
///
### Staff.cpp
/// cpp
#include "Staff.h"
Staff::Staff(const QString& name, const QDate& birthdate,
Staff::AppointmentType type)
: name(name), birthdate(birthdate), appointmentType(type) {}
// Getters
QString Staff::getName() const { return name; }
QDate Staff::getBirthdate() const { return birthdate; }
QString Staff::getAppointmentType() const { return
appointmentTypeToString(appointmentType); }
// Setters
void Staff::setName(const QString& name) { this->name = name; }
void Staff::setBirthdate(const QDate& birthdate) { this->birthdate =
birthdate; }
void Staff::setAppointmentType(const QString& type) { this-
>appointmentType = stringToAppointmentType(type); }
QString Staff::appointmentTypeToString(Staff::AppointmentType type)
{
switch(type) {
case AppointmentType::Permanent: return "Permanent";
case AppointmentType::PartTime: return "Part-time";
case AppointmentType::Contract: return "Contract";
default: return "";
}
}
Staff::AppointmentType Staff::stringToAppointmentType(const QString&
type) {
if (type == "Permanent") return AppointmentType::Permanent;
if (type == "Part-time") return AppointmentType::PartTime;
if (type == "Contract") return AppointmentType::Contract;
throw std::invalid_argument("Invalid appointment type");
}
///
### StaffList.h
/// cpp
#ifndef STAFFLIST_H
Disclaimer
Extreme care has been used to create this document, however the contents are provided “as is” without
any representations or warranties, express or implied. The author assumes no liability as a result of
reliance and use of the contents of this document. This document is to be used for comparison, research
and reference purposes ONLY. No part of this document may be reproduced, resold or transmitted in any
form or by any means.