Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //exercise 12
- #include <string> //there is a date in dd.mm.yyyy format. What day of the week corresponds to this date?
- //01.01.1973 - monday
- //0 - monday, 1 - tuesday, ..., 6 - sunday
- using namespace std;
- int curDay, curMonth, curYear;
- void stringToDate(string s)
- {
- curDay = stoi(s.substr(0, 2));
- curMonth = stoi(s.substr(3, 5));
- curYear = stoi(s.substr(6));
- }
- bool bisSextus(int n)
- {
- if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0)
- return 1;
- else
- return 0;
- }
- int main()
- {
- int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- string s;
- cout << "Enter the date\n";
- cin >> s;
- int dayNULL = 1;
- int monthNULL = 1;
- int yearNULL = 1973;
- stringToDate(s);
- int counter = 0;
- for(int i = yearNULL; i < curYear; i++)
- {
- if (bisSextus(i))
- counter += 366;
- else
- counter += 365;
- }
- for(int i = monthNULL; i < curMonth; i++)
- {
- counter += daysInMonth[i - 1];
- }
- if (curMonth > 2 && bisSextus(curYear))
- counter++;
- counter += (curDay - dayNULL);
- counter %= 7;
- switch (counter)
- {
- case 0:{cout << "MONDAY\n"; break;}
- case 1:{cout << "TUESDAY\n"; break;}
- case 2:{cout << "WEDNESDAY\n"; break;}
- case 3:{cout << "THURSDAY\n"; break;}
- case 4:{cout << "FRIDAY\n"; break;}
- case 5:{cout << "SATURDAY\n"; break;}
- case 6:{cout << "SUNDAY\n"; break;}
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement