Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My assignment from problem 1 was to Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description

My assignment from problem 1 was to Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example "see an advisor") and a date and a time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether a day of the month matches. Then fill a vector of Appointment* with a mixtures of appointments. Have user enter a date and printout all appointments that happens on that date.

I need help with this part 2, which is as follows. Based on the code below. Improve the appointment book program. Give the user the option to add new appointments. The user must specify the type of the appointment, the descriptoin, and the date and the time. Please include output when responding. Every other person who helped had errors and changed the code to the point where it's not following the original instructions. Much thanks ahead of time.

#include #include #include #include

using namespace std;

const int DAYS_PER_MONTH = 30;

/** A class that describes a time of day (between 00:00:00 and 23:59:59) */ class Time { public: /** Constructs a time of day. @param hour the hours @param min the minutes @param sec the seconds */ Time(int hour, int min, int sec); /** Constructs a Time object that is set to the time at which the constructor executes. */ Time();

/** Gets the hours of this time. @return the hours */ int get_hours() const; /** Gets the minutes of this time. @return the minutes */ int get_minutes() const; /** Gets the seconds of this time. @return the seconds */ int get_seconds() const;

/** Computes the seconds between this time and another. @param t the other time @return the number of seconds between this time and t */ int seconds_from(Time t) const; /** Adds a number of seconds to this time. @param s the number of seconds to add */ void add_seconds(int s);

private: int time_in_secs; }; /** Computes the correct remainder for negative dividend @param a - an integer @param n - an integer > 0 @return the mathematically correct remainder r such that a - r is divisible by n and 0 => */ int remainder(int a, int n) { if (a >= 0) { return a % n; } else { return n - 1 - (-a - 1) % n; } }

Time::Time(int hour, int min, int sec) { time_in_secs = 60L * 60 * hour + 60 * min + sec; }

Time::Time() { time_in_secs = 0; }

int Time::get_hours() const { return time_in_secs / (60 * 60); }

int Time::get_minutes() const { return (time_in_secs / 60) % 60; }

int Time::get_seconds() const { return time_in_secs % 60; }

int Time::seconds_from(Time t) const { return time_in_secs - t.time_in_secs; }

void Time::add_seconds(int s) { const int SECONDS_PER_DAY = 60 * 60 * 24; time_in_secs = remainder(time_in_secs + s, SECONDS_PER_DAY); }

//..................................................................

class Date { public: Date(); Date(int y, int m, int d); void print() const; bool equals(Date other) const; private: int day; int month; int year; };

Date::Date() { day = 1; month = 1; year = 1; }

Date::Date(int y, int m, int d) { day = d; month = m; year = y; }

void Date::print() const { cout }

bool Date::equals(Date other) const { return day == other.day && month == other.month && year == other.year; }

class Appointment { public: Appointment(); Appointment(string desc, Time s, Time e); void print() const; void read(); virtual bool occurs_on(int year, int month, int day) const; private: string description; Time start; Time end; };

Appointment::Appointment() { }

Appointment::Appointment(string desc, Time s, Time e) { description = desc; start = s; end = e; }

void Appointment::print() const { cout if (start.get_minutes() cout if (end.get_minutes() cout }

void Appointment::read() { int sh; int sm; int eh; int em; cout cin >> sh >> sm >> eh >> em; getline(cin, description); start = Time(sh, sm, 0); end = Time(eh, em, 0); }

/** Determines if the appointment occurs on the given date. @param year a year value @param month a month value of 1 for Jan, to 12 for Dec @param day a day value @return true if the appointment occurs on the given date */ bool Appointment::occurs_on(int year, int month, int day) const { return false; }

class Onetime : public Appointment { public: Onetime(); Onetime(string desc, Date d, Time s, Time e); void read(); virtual bool occurs_on(int year, int month, int day) const; private: Date when; };

Onetime::Onetime() { }

Onetime::Onetime(string desc, Date d, Time s, Time e) : Appointment(desc, s, e) { when = d; }

void Onetime::read() { Appointment::read(); cout int year; int month; int day; cin >> year >> month >> day; when = Date(year, month, day); }

/** Determines if the appointment occurs on the given date. @param year a year value @param month a month value of 1 for Jan, to 12 for Dec @param day a day value @return true if the appointment occurs on the given date */ bool Onetime::occurs_on(int year, int month, int day) const { return when.equals(Date(year, month, day)); }

class Daily : public Appointment { public: Daily(); Daily(string desc, Time s, Time e); virtual bool occurs_on(int year, int month, int day) const; };

Daily::Daily() { }

Daily::Daily(string desc, Time s, Time e) : Appointment(desc, s, e) { }

/** Determines if the appointment occurs on the given date. @param year a year value @param month a month value of 1 for Jan, to 12 for Dec @param day a day value @return true if the appointment occurs on the given date */ bool Daily::occurs_on(int year, int month, int day) const { return true; }

class Monthly : public Appointment { public: Monthly(); Monthly(string desc, int d, Time s, Time e); void read(); virtual bool occurs_on(int year, int month, int day) const; private: int day; };

Monthly::Monthly() { }

Monthly::Monthly(string desc, int d, Time s, Time e) : Appointment(desc, s, e) { day = d; }

void Monthly::read() { Appointment::read(); cout int d; cin >> d; day = d; }

bool Monthly::occurs_on(int year, int month, int d) const /** Determines if the appointment occurs on the given date. @param year a year value @param month a month value of 1 for Jan, to 12 for Dec @param day a day value @return true if the appointment occurs on the given date */

{ return day == d; }

int main() { vector schedule(3); schedule[0]= new Onetime("see the dentist", Date(1998, 9, 4), Time(11, 30, 0), Time(12, 30, 0)); schedule[1]= new Daily("brush my teeth", Time(8,0,0), Time(8, 5, 0)); schedule[2]= new Monthly("clean the house", 4, Time(14,0,0), Time(16, 0, 0));

cout int year; int month; int day; cin >> year >> month >> day;

cout for (int i = 0; i { if (schedule[i]->occurs_on(year, month, day)) { schedule[i]->print(); } } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Android Graphics

Authors: Wallace Jackson

1st Edition

1430257857, 978-1430257851

More Books

Students also viewed these Programming questions