Advertisement
FaDaQ

Грёбаное говно, которое работает с ужасной погрешностью и сделано из говнокода

Feb 26th, 2022
1,367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.26 KB | None | 0 0
  1. #include<iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. enum Months {
  6.     January = 1,
  7.     February,
  8.     March,
  9.     April,
  10.     May,
  11.     June,
  12.     July,
  13.     August,
  14.     September,
  15.     October,
  16.     November,
  17.     December,
  18. };
  19.  
  20. struct DateStruct {
  21.     unsigned int day = 0;
  22.     unsigned int month = 0;
  23.     unsigned int year = 0;
  24.  
  25. };
  26.  
  27. class Date {
  28. private:
  29.     DateStruct date;
  30.     DateStruct tempDate;
  31.  
  32. public:
  33.     void setDateNow() {
  34.        
  35.         cout << "Введите текущий год: ";
  36.         cin >> date.year;
  37.  
  38.         cout << "Введите текущий месяц: ";
  39.         cin >> date.month;
  40.  
  41.         cout << "Введите текущий день: ";
  42.         cin >> date.day;
  43.  
  44.     }
  45.  
  46.     void afterCountDays(int countDays) {
  47.         tempDate = date;
  48.         if (tempDate.month != February) {
  49.             int temp = countDays;
  50.            
  51.             if (temp > 30) {
  52.                 while (temp > 0) {
  53.                     if (temp >= 365) {
  54.                         tempDate.year++;
  55.                         temp -= 365;
  56.                     }
  57.                     else if (temp >= 30) {
  58.                         tempDate.month++;
  59.                         temp -= 30;
  60.                         if (tempDate.month > 12) {
  61.                             tempDate.month = 1;
  62.                             tempDate.year++;
  63.                         }
  64.                     }
  65.                     else {
  66.                         tempDate.day += temp;
  67.                         temp -= temp;
  68.                     }
  69.                 }
  70.                 if (tempDate.day > 30) {
  71.                     tempDate.month++;
  72.                     tempDate.day = 1;
  73.                 }
  74.                 printDate(true, countDays, tempDate);
  75.             }
  76.  
  77.             else {
  78.                 tempDate.day += countDays;
  79.                 printDate(true, countDays, tempDate);
  80.             }
  81.         }
  82.     }
  83.  
  84.     void SubtractDays(int countDays) {
  85.         tempDate = date;
  86.         for (int i = countDays; i > 0; i--) {
  87.             tempDate.day--;
  88.             if (tempDate.day == 0) {
  89.                 tempDate.day = 30;
  90.                 tempDate.month--;
  91.             }
  92.             if (tempDate.month == 0) {
  93.                 tempDate.month = 12;
  94.                 tempDate.year--;
  95.             }
  96.         }
  97.         printDate(true, countDays, tempDate);
  98.     }
  99.  
  100.     void leapYear() {
  101.         if (date.year % 4 == 0) {
  102.             cout << "Год является високосным!" << endl;
  103.         }
  104.         else {
  105.             cout << "Год НЕ является високосным!" << endl;
  106.         }
  107.     }
  108.  
  109.     void printDate(bool afterCountDays, int countDays, DateStruct tempDate) {
  110.  
  111.         if (afterCountDays) {
  112.             cout << "Через " << countDays << " дней от введённой даты будет(примерно): "
  113.                 << tempDate.year << ":" << tempDate.month << ":" << tempDate.day << endl;
  114.         }
  115.         else {
  116.             cout << "Сейчас " << date.year << " год" << endl;
  117.         }
  118.     }
  119. };
  120.  
  121.  
  122. int main()
  123. {
  124.     setlocale(LC_ALL, "rus");
  125.  
  126.     Date nowDate;
  127.     nowDate.setDateNow();
  128.     nowDate.afterCountDays(34);
  129.     nowDate.SubtractDays(765);
  130.     nowDate.leapYear();
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement