Advertisement
kokokozhina

struct_12

Dec 10th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream> //exercise 12
  2. #include <string> //there is a date in dd.mm.yyyy format. What day of the week corresponds to this date?
  3. //01.01.1973 - monday
  4. //0 - monday, 1 - tuesday, ..., 6 - sunday
  5. using namespace std;
  6.  
  7. int curDay, curMonth, curYear;
  8.  
  9. void stringToDate(string s)
  10. {
  11.     curDay = stoi(s.substr(0, 2));
  12.     curMonth = stoi(s.substr(3, 5));
  13.     curYear = stoi(s.substr(6));
  14. }
  15.  
  16.  
  17. bool bisSextus(int n)
  18. {
  19.     if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0)
  20.         return 1;
  21.     else
  22.         return 0;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28.     int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  29.     string s;
  30.     cout << "Enter the date\n";
  31.     cin >> s;
  32.  
  33.     int dayNULL = 1;
  34.     int monthNULL = 1;
  35.     int yearNULL = 1973;
  36.  
  37.     stringToDate(s);
  38.     int counter = 0;
  39.     for(int i = yearNULL; i < curYear; i++)
  40.     {
  41.         if (bisSextus(i))
  42.             counter += 366;
  43.         else
  44.             counter += 365;
  45.     }
  46.  
  47.     for(int i = monthNULL; i < curMonth; i++)
  48.     {
  49.         counter += daysInMonth[i - 1];
  50.     }
  51.     if (curMonth > 2 && bisSextus(curYear))
  52.         counter++;
  53.  
  54.     counter += (curDay - dayNULL);
  55.  
  56.     counter %= 7;
  57.  
  58.     switch (counter)
  59.     {
  60.     case 0:{cout << "MONDAY\n"; break;}
  61.     case 1:{cout << "TUESDAY\n"; break;}
  62.     case 2:{cout << "WEDNESDAY\n"; break;}
  63.     case 3:{cout << "THURSDAY\n"; break;}
  64.     case 4:{cout << "FRIDAY\n"; break;}
  65.     case 5:{cout << "SATURDAY\n"; break;}
  66.     case 6:{cout << "SUNDAY\n"; break;}
  67.     }
  68.  
  69.     system("pause");
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement