Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include "Date.h"
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. Date A, B;
  9. cout << "Input the first month and day" << endl;
  10. A.GetDate();
  11. cout << "Input the second month and day" << endl;
  12. B.GetDate();
  13.  
  14. A.WriteDate();
  15. A.Validate();
  16.  
  17. B.WriteDate();
  18. B.Validate();
  19. }
  20.  
  21. #ifndef DATE_H
  22. #define DATE_H
  23.  
  24. class Date
  25. {
  26. private:
  27. int month;
  28. int day;
  29. public:
  30. Date();
  31. void setMonth(int m){month = m;}
  32. void setDay(int d){day = d;}
  33. int getMonth(){return month;}
  34. int getDay(){return day;}
  35. void GetDate();
  36. void WriteDate();
  37. bool Validate();
  38. };
  39.  
  40. #endif
  41.  
  42. #include <iostream>
  43. #include "Date.h"
  44.  
  45. using namespace std;
  46.  
  47. char monthNames[30][12] = {"January", "February", "March", "April", "May",
  48. "June", "July", "August", "September", "October", "November", "December"};
  49. int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  50.  
  51. Date::Date()
  52. {
  53. month = 1;
  54. day = 1;
  55. }
  56.  
  57. void Date::GetDate()
  58. {
  59. cout << "Input the month: ";
  60. int x;
  61. cin >> x;
  62. Date::setMonth(x);
  63. cout << "Input the day: ";
  64. int y;
  65. cin >> y;
  66. Date::setDay(y);
  67. cout << "n";
  68. }
  69.  
  70. void Date::WriteDate()
  71. {
  72. cout << "The date is " << monthNames[getMonth() - 1] << " " << day <<
  73. "nn";
  74. }
  75.  
  76. bool Date::Validate()
  77. {
  78. bool check = false;
  79. if((getMonth() > 0 && getMonth() < 12) && (getDay() > 0 && getDay() <=
  80. days[getMonth() - 1])){
  81. check = true;
  82. }
  83. else{
  84. cout << "The date is invalid. Date will be reset now" << endl;
  85. Date();
  86. }
  87. return check;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement