Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.31 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int newdays;
  4. struct time
  5. {
  6.     long year;
  7.     int month;
  8.     int day;
  9.     time()
  10.     {
  11.         year = 0;
  12.         month = 0;
  13.         day = 0;
  14.     }
  15. };
  16.  
  17.  
  18. int newday()
  19. {
  20.     cout << "Введите количество дней " << endl;
  21.     cin >> newdays;
  22.     return newdays;
  23. }
  24. void positive(time first, int result_newday)
  25. {
  26.             while (result_newday--) {
  27.                 first.day++;
  28.                 switch (first.month) {
  29.                 case 1:
  30.                 case 3:
  31.                 case 5:
  32.                 case 7:
  33.                 case 8:
  34.                 case 10:
  35.                 case 12: {
  36.                     if (first.day > 31) {
  37.                         first.month++;
  38.                         first.day -= 31;
  39.                     }
  40.                     break;
  41.                 }
  42.  
  43.                 case 2: {
  44.                     if (first.year % 4 == 0) {
  45.                         if (first.year % 100 == 0) {
  46.                             if (first.year % 400 == 0) {
  47.                                 if (first.day > 29) {
  48.                                     first.month++;
  49.                                     first.day -= 29;
  50.                                 }
  51.                             }
  52.                             else if (first.day > 28) {
  53.                                 first.month++;
  54.                                 first.day -= 28;
  55.                             }
  56.                         }
  57.                         else if (first.day > 29) {
  58.                             first.month++;
  59.                             first.day -= 29;
  60.                         }
  61.                     }
  62.                     else if (first.day > 28) {
  63.                         first.month++;
  64.                         first.day -= 28;
  65.                     }
  66.                     break;
  67.                 }
  68.                 case 4:
  69.                 case 6:
  70.                 case 9:
  71.                 case 11: {
  72.                     if (first.day > 30) {
  73.                         first.month++;
  74.                         first.day -= 30;
  75.                     }
  76.                     break;
  77.                 }
  78.                 default:
  79.                     break;
  80.                 }
  81.  
  82.                 while (first.month > 12) {
  83.                     first.month -= 12;
  84.                     first.year++;
  85.                 }
  86.             }
  87.             cout << "Новая дата: " << first.day << '.' << first.month << '.' << first.year << endl;
  88.         }
  89.  
  90. int negative(time first, int result_newday) {
  91.  
  92.     while (result_newday++) {
  93.         first.day--;
  94.         switch (first.month) {
  95.         case 1:
  96.         case 3:
  97.         case 5:
  98.         case 7:
  99.         case 8:
  100.         case 10:
  101.         case 12: {
  102.             if (first.day < 31) {
  103.                 first.month--;
  104.                 first.day += 31;
  105.             }
  106.             break;
  107.         }
  108.  
  109.         case 2: {
  110.             if (first.year % 4 == 0) {
  111.                 if (first.year % 100 == 0) {
  112.                     if (first.year % 400 == 0) {
  113.                         if (first.day < 29) {
  114.                             first.month--;
  115.                             first.day += 29;
  116.                         }
  117.                     }
  118.                     else if (first.day < 28) {
  119.                         first.month--;
  120.                         first.day += 28;
  121.                     }
  122.                 }
  123.                 else if (first.day < 29) {
  124.                     first.month--;
  125.                     first.day += 29;
  126.                 }
  127.             }
  128.             else if (first.day < 28) {
  129.                 first.month--;
  130.                 first.day += 28;
  131.             }
  132.             break;
  133.         }
  134.         case 4:
  135.         case 6:
  136.         case 9:
  137.         case 11: {
  138.             if (first.day < 30) {
  139.                 first.month--;
  140.                 first.day += 30;
  141.             }
  142.             break;
  143.         }
  144.         default:
  145.             break;
  146.         }
  147.  
  148.         while (first.month < 1) {
  149.             first.month += 12;
  150.             first.year--;
  151.         }
  152.         if (first.year < 0) {
  153.             cout << "Калькулятор работает только в пределах нашей эры!" << endl;
  154.             return 0;
  155.         }
  156.         cout << "Новая дата: " << first.day << '.' << first.month << '.' << first.year << endl;
  157.     }
  158.     return 0;
  159. }
  160.  
  161. void calculator(time first) {
  162.     cout << "Введите изначальную дату(день, месяц, год): " << endl;
  163.     cin >> first.day;
  164.     cin >> first.month;
  165.     cin >> first.year;
  166.     cout << "Изначальная дата: " << first.day << "." << first.month << "." << first.year << endl;
  167.     int result_newday = newday();
  168.     if (result_newday>0)
  169.     positive(first, result_newday);
  170.     else
  171.     negative(first, result_newday);
  172. }
  173.  
  174. int main()
  175. {
  176.     setlocale(0, "rus");
  177.     time first;
  178.     calculator(first);
  179.     system("pause");
  180.     return 0;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement