COS3711 2023 ASSIGNMENT 1
DISCUSSION
(with the source code you need)
Crystal Indigo!
Crystal Indigo!
Providing all solutions you need anytime
+27 76 626 8187
***copy and run the code in Qt Creator ***
*** There is a link to the source code at the end of this discussion***
if there is a program that is not running, please contact
Note: do not submit as pdf and change the code where necessary
,Question 1:
Write an application that can be used to keep a list of staff member details. Each staff member
data should include the following:
1. A name
2. A birthdate, and
3. A staff appointment type (one of permanent, part-time, or contract, stored and handled as an
enum).
Include all necessary getter and setter functions. An additional getter can be used to return the
appointment type as a Qstring. The application should allow a user to enter details via a GUI. Also,
once a staff member’s details are entered, they should be saved to a list/container in the application.
The user should be able to write this list to file (in any acceptable, human-readable format) when
needed.
Ensure that you adhere to basic design principles and avoid any anti-patterns in the design of
your solution.
Discussion:
The application consists of three classes: MainWindow, StaffMember, and
StaffListModel. In the initial solution provided, the StaffMember class is responsible for
storing the details of a staff member, including their name, birthdate, and staff appointment type. In
the first part of the solution, the StaffMember class is defined with three private data members -
m_name, m_birthdate, and m_staffAppointment. These data members represent the
name, birthdate, and appointment type of a staff member, respectively.
The StaffMember class also provides public getter and setter functions for each of its private
data members, allowing external code to access and modify the staff member's information.
Additionally, the class provides a function that returns a string representation of the staff member's
information.
Overall, the StaffMember class encapsulates the data and behaviour related to an individual staff
member, providing a clean and modular way to represent and manipulate staff member information
in the application.
,Output when run:
,Source code
//staffmember.h
#ifndef STAFFMEMBER_H
#define STAFFMEMBER_H
#include <QString>
#include <QDate>
enum class AppointmentType {
Permanent,
PartTime,
Contract
};
class StaffMember
{
public:
StaffMember();
StaffMember(const QString& name, const QDate& birthdate, AppointmentType
appointmentType);
QString getName() const;
QDate getBirthdate() const;
AppointmentType getAppointmentType() const;
QString getAppointmentTypeString() const;
private:
QString m_name;
QDate m_birthdate;
AppointmentType m_appointmentType;
};
#endif // STAFFMEMBER_H
//staffmember.cpp
#include "staffmember.h"
StaffMember::StaffMember()
{
}
, StaffMember::StaffMember(const QString& name, const QDate& birthdate,
AppointmentType appointmentType)
: m_name(name), m_birthdate(birthdate), m_appointmentType(appointmentType)
{
}
QString StaffMember::getName() const
{
return m_name;
}
QDate StaffMember::getBirthdate() const
{
return m_birthdate;
}
AppointmentType StaffMember::getAppointmentType() const
{
return m_appointmentType;
}
QString StaffMember::getAppointmentTypeString() const
{
switch (m_appointmentType) {
case AppointmentType::Permanent:
return "Permanent";
case AppointmentType::PartTime:
return "Part-Time";
case AppointmentType::Contract:
return "Contract";
default:
return "";
}
}
//stafflistmodel.h
#ifndef STAFFLISTMODEL_H
#define STAFFLISTMODEL_H
#include <QAbstractListModel>
#include <QList>
#include "staffmember.h"
class StaffListModel : public QAbstractListModel
{
Q_OBJECT
public:
StaffListModel();
StaffListModel(QObject *parent = nullptr);