Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. /*
  2. https://cdn.discordapp.com/attachments/654482101256585216/654495688771764224/image0.png
  3. */
  4.  
  5. #include <iostream>
  6. #include <vector>
  7.  
  8. class Appointment
  9. {
  10. std::string description;
  11.  
  12. protected:
  13. int year = -1;
  14. int month = -1;
  15. int day = -1;
  16.  
  17. public:
  18. virtual bool occurs_on(int year, int month, int day) = 0;
  19.  
  20. std::string getDescription()
  21. {
  22. return description;
  23. }
  24.  
  25. Appointment(const std::string& description, int year, int month, int day) :
  26. description(description),
  27. year(year),
  28. month(month),
  29. day(day)
  30. {}
  31. };
  32.  
  33. class Onetime : public Appointment
  34. {
  35. bool occurs_on(int year, int month, int day)
  36. {
  37. return this->year == year && this->month == month && this->day == day;
  38. }
  39.  
  40. public:
  41. Onetime(const std::string& description, int year, int month, int day) :
  42. Appointment(description, year, month, day)
  43. {}
  44. };
  45.  
  46. class Daily : public Appointment
  47. {
  48. bool occurs_on(int year, int month, int day)
  49. {
  50. return true;
  51. }
  52.  
  53. public:
  54. Daily(const std::string& description) :
  55. Appointment(description, -1, -1, -1)
  56. {}
  57. };
  58.  
  59. class Weekly : public Appointment
  60. {
  61. bool occurs_on(int year, int month, int day)
  62. {
  63. return (this->day % 7) == (day % 7);
  64. }
  65.  
  66. public:
  67. Weekly(const std::string& description, int day) :
  68. Appointment(description, -1, -1, day)
  69. {}
  70. };
  71.  
  72. class Monthly : public Appointment
  73. {
  74. bool occurs_on(int year, int month, int day)
  75. {
  76. return this->day == day;
  77. }
  78.  
  79. public:
  80. Monthly(const std::string& description, int day) :
  81. Appointment(description, -1, month, day)
  82. {}
  83. };
  84.  
  85. int main()
  86. {
  87. int year;
  88. int month;
  89. int day;
  90.  
  91. std::cout << "Year: ";
  92. std::cin >> year;
  93.  
  94. std::cout << "Month: ";
  95. std::cin >> month;
  96.  
  97. std::cout << "Day: ";
  98. std::cin >> day;
  99.  
  100. std::vector<Appointment*> appointments
  101. {
  102. new Daily("Daily appointment #1"),
  103. new Daily("Daily appointment #2"),
  104. new Weekly("Weekly appointment #1", 3),
  105. new Weekly("Weekly appointment #2", 4),
  106. new Monthly("Monthly appointment #1", 8),
  107. new Onetime("Onetime appointment #1", 2019, 12, 24)
  108. };
  109.  
  110. for (Appointment* appointment : appointments)
  111. {
  112. if (appointment->occurs_on(year, month, day))
  113. std::cout << appointment->getDescription() << std::endl;
  114.  
  115. delete appointment;
  116. }
  117.  
  118. appointments.clear();
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement