Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- https://cdn.discordapp.com/attachments/654482101256585216/654495688771764224/image0.png
- */
- #include <iostream>
- #include <vector>
- class Appointment
- {
- std::string description;
- protected:
- int year = -1;
- int month = -1;
- int day = -1;
- public:
- virtual bool occurs_on(int year, int month, int day) = 0;
- std::string getDescription()
- {
- return description;
- }
- Appointment(const std::string& description, int year, int month, int day) :
- description(description),
- year(year),
- month(month),
- day(day)
- {}
- };
- class Onetime : public Appointment
- {
- bool occurs_on(int year, int month, int day)
- {
- return this->year == year && this->month == month && this->day == day;
- }
- public:
- Onetime(const std::string& description, int year, int month, int day) :
- Appointment(description, year, month, day)
- {}
- };
- class Daily : public Appointment
- {
- bool occurs_on(int year, int month, int day)
- {
- return true;
- }
- public:
- Daily(const std::string& description) :
- Appointment(description, -1, -1, -1)
- {}
- };
- class Weekly : public Appointment
- {
- bool occurs_on(int year, int month, int day)
- {
- return (this->day % 7) == (day % 7);
- }
- public:
- Weekly(const std::string& description, int day) :
- Appointment(description, -1, -1, day)
- {}
- };
- class Monthly : public Appointment
- {
- bool occurs_on(int year, int month, int day)
- {
- return this->day == day;
- }
- public:
- Monthly(const std::string& description, int day) :
- Appointment(description, -1, month, day)
- {}
- };
- int main()
- {
- int year;
- int month;
- int day;
- std::cout << "Year: ";
- std::cin >> year;
- std::cout << "Month: ";
- std::cin >> month;
- std::cout << "Day: ";
- std::cin >> day;
- std::vector<Appointment*> appointments
- {
- new Daily("Daily appointment #1"),
- new Daily("Daily appointment #2"),
- new Weekly("Weekly appointment #1", 3),
- new Weekly("Weekly appointment #2", 4),
- new Monthly("Monthly appointment #1", 8),
- new Onetime("Onetime appointment #1", 2019, 12, 24)
- };
- for (Appointment* appointment : appointments)
- {
- if (appointment->occurs_on(year, month, day))
- std::cout << appointment->getDescription() << std::endl;
- delete appointment;
- }
- appointments.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement