Please implement C++ to code Exercise P8.7. Implement a base class Appointment a
ID: 3880840 • Letter: P
Question
Please implement C++ to code
Exercise P8.7. Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, "see the den- tist") and a date and time. Write a virtual function occurs onCint year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches Then fill a vector of Appointment with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.Explanation / Answer
You can create your class structure like this
class CAppointment
{
public:
CAppointment();
~CAppointment();
virtual time_t Occurs_on(int year, int month, int day);
CString m_strAppointmentDescription;
time_t m_dtTime;
};
class COneTime : public CAppointment
{
public:
COneTime();
~COneTime();
virtual time_t Occurs_on(int year, int month, int day);
};
class CDaily : public CAppointment
{
public:
CDaily();
~CDaily();
virtual time_t Occurs_on(int year, int month, int day);
};
class CWeekly : public CAppointment
{
public:
CWeekly();
~CWeekly();
virtual time_t Occurs_on(int year, int month, int day);
};
class CMonthly : public CAppointment
{
public:
CMonthly();
~CMonthly();
virtual time_t Occurs_on(int year, int month, int day);
};
you have to define a method to fill out the vector of Appointments like below
void CAppointmentAppDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CAppointment * appoint = new COneTime();
appoint->m_strAppointmentDescription = "See the dentist";
appointments.push_back(appoint);
appoint = new CDaily();
appointments.push_back(appoint);
appoint = new CWeekly();
appointments.push_back(appoint);
appoint = new CMonthly();
appointments.push_back(appoint);
}
you have to call your override method inside a for loop for each appointments entered
for (int i = 0; i < appointments.size(); i++)
{
appointments[i]->Occurs_on(2016,05,25);
}