Mancolo

12 task

Dec 1st, 2022
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Date
  5. {
  6. public:
  7.     Date() :Year(2018), Month(1), Day(1) {}
  8.     Date(int d, int m, int y) :Year(y), Month(m), Day(d) {}
  9.     int after_a_specified_number_of_days(int);
  10.     int subtraction_of_a_specified_number_of_days(int);
  11.     int leap_year();
  12.     Date assignment_of_individual_parts(Date d2);
  13.     void date_comparison(Date d2);
  14.     int calculating_the_number_of_days_between_dates(Date d2);
  15.     void set();
  16.     void show();
  17.  
  18. private:
  19.     int Year;
  20.     int Day;
  21.     int Month;
  22. };
  23.  
  24. int Date::after_a_specified_number_of_days(int d2)
  25. {
  26.     return(Day + d2);
  27. }
  28. int Date::subtraction_of_a_specified_number_of_days(int d2)
  29. {
  30.     return(Day - d2);
  31. }
  32. int Date::leap_year()
  33. {
  34.     if (Year / 4 == 0)
  35.     {
  36.         cout << "Year is a leap year";
  37.     }
  38.     else
  39.     {
  40.         cout << "The year is not a leap year";
  41.     }
  42.  
  43. }
  44. Date Date::assignment_of_individual_parts(Date d2)
  45. {
  46.     return Date(Day + d2.Day, Month + d2.Month, Year + d2.Year);
  47. }
  48. void Date::date_comparison(Date d2)
  49. {
  50.     int D = Day;
  51.     int D2 = d2.Day;
  52.     if (D < D2 && Month <= d2.Month && Year <= d2.Year)
  53.     {
  54.         cout << "The first date is more than the second" << endl;
  55.     }
  56.     else
  57.         if (D > D2 && Month >= d2.Month && Year >= d2.Year)
  58.         {
  59.             cout << "First date less than second" << endl;
  60.         }
  61.         else
  62.         {
  63.             cout << "The first date is equal to the second" << endl;
  64.         }
  65. }
  66. int Date::calculating_the_number_of_days_between_dates(Date d2)
  67. {
  68.     return  Day - d2.Day + (Month - d2.Month * 30 + (Year - d2.Year) * 365);
  69. }
  70. void Date::set()
  71. {
  72.     cout << "Enter the day, month and year you want to assign" << endl;
  73.     cin >> Day >> Month >> Year;
  74.  
  75.  
  76. }
  77. void Date::show()
  78. {
  79.     cout << Day << '/' << Month << '/' << Year << endl;
  80. }
  81.  
  82.  
  83. int main()
  84. {
  85.     Date n1(2018, 12, 20), n2;
  86.     n2.set();
  87.     n1.show();
  88.     n2.show();
  89.  
  90.     cout << "Date after the specified number of days:" << n1.after_a_specified_number_of_days(10) << endl;
  91.     cout << "Date after subtraction:" << n1.subtraction_of_a_specified_number_of_days(11) << endl;
  92.     cout << "Leap Year:" << n2.leap_year() << endl;
  93.  
  94.     Date n3 = n1.assignment_of_individual_parts(n2);
  95.     cout << "Date after assignment:";
  96.     n3.show();
  97.  
  98.     cout << "Days between dates:" << n1.calculating_the_number_of_days_between_dates(n2);
  99.  
  100.     n1.date_comparison(n2);
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment