Advertisement
mercMatvey4

Untitled

May 26th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. class Date
  6. {
  7. private:
  8. int day;
  9. int month;
  10. int year;
  11. int cmp(Date d1, Date d2)
  12. {
  13. if (d1.year>d2.year)
  14. return 1;
  15. else
  16. if (d1.year<d2.year)
  17. return -1;
  18. else
  19. if (d1.month>d2.month)
  20. return 1;
  21. else
  22. if (d1.month<d2.month)
  23. return -1;
  24. else
  25. if (d1.day>d2.day)
  26. return 1;
  27. else
  28. if (d2.day<d2.day)
  29. return -1;
  30. return 0;
  31. }
  32.  
  33. bool vys(int year)
  34. {
  35. bool res= false;
  36. if (year%4==0)
  37. res= true;
  38. if (year%100==0)
  39. res= false;
  40. if (year%400==0)
  41. res= true;
  42. return res;
  43. }
  44.  
  45.  
  46. void Add(Date &d)//функция увеличивает дату на 1, то есть показывает слудуущий день
  47. {
  48. int mes[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  49. if (vys(d.year))//если высокосный год то в фефрале 29 дней
  50. mes[1]= 29;
  51. d.day++;//увеличиваем день
  52. if (d.day>mes[d.month-1])//если привысили месяц, то увеличиваем месяц
  53. {
  54. d.day= 1;
  55. d.month++;
  56. if (d.month>12)
  57. {
  58. d.month= 1;
  59. d.year++;
  60. }
  61. }
  62. }
  63. public:
  64. Date(int day, int month, int year){SetDay(day); SetMonth(month); SetYear(year);}
  65. Date(){day=0; month=0; year=0;}
  66. int GetDay(){return day;}
  67. int GetMonth(){return month;}
  68. int GetYear(){return year;}
  69. void SetDay(int day){this->day= day;}
  70. void SetMonth(int month){this->month= month;}
  71. void SetYear(int year){this->year= year;}
  72. void Vvod(){cout<<"Введите дату в формате dd.mm.yyyy: ";scanf("%d.%d.%d", &day, &month, &year);}
  73. void Vyvod(){printf("%.2d.%.2d.%.4d", day, month, year);}
  74. int raz(Date d)
  75. {
  76. Date date1= *this;
  77. Date date2= d;
  78. if (cmp(date1, date2)>0)
  79. swap(date1, date2);
  80. int kol=0;
  81. for (int i=date1.year; i<date2.year; i++)
  82. {
  83. kol+= 365;
  84. if (vys(i))
  85. kol++;
  86. }
  87. while ((date1.day!=date2.day)||(date1.month!=date2.month))
  88. {
  89. kol++;
  90. Add(date1);
  91. }
  92. return kol;
  93. }
  94. };
  95.  
  96. int week(Date ob1)
  97. {
  98. int a, y, m, R;
  99. a = ( 14 - ob1.GetMonth() ) / 12;
  100. y = ob1.GetYear() - a;
  101. m = ob1.GetMonth() + 12 * a - 2;
  102. R = 7000 + (ob1.GetDay() + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12 );
  103. return R % 7;
  104. }
  105.  
  106. int main()
  107. {
  108. setlocale(LC_ALL,"");
  109. Date d1;
  110. Date d2;
  111. Date d3;
  112. d1.Vvod();
  113. d2.Vvod();
  114. int q = d1.raz(d2);
  115. cout<<"Разница в днях: " << q << endl << endl;
  116. int a;
  117. cin >> a;
  118. d3.SetDay(d1.GetDay()+a);
  119. d3.SetMonth(d1.GetMonth());
  120. d3.SetYear(d1.GetYear());
  121. cout << "\nДата, отстающая от первой даты на " << a << " дней\n\n";
  122. d3.Vyvod();
  123. cout << "\n\nДень недели последней даты : ";
  124. if(week(d3) == 0) cout << "\nВоскресенье";
  125. if(week(d3) == 1) cout << "\nПонедельник";
  126. if(week(d3) == 2) cout << "\nВторник";
  127. if(week(d3) == 3) cout << "\nСреда";
  128. if(week(d3) == 4) cout << "\nЧетверг";
  129. if(week(d3) == 5) cout << "\nПятница";
  130. if(week(d3) == 6) cout << "\nСуббота";
  131. return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement