Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Лаб 1 сиспр.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <cstdlib>
- #include <string>
- #include <ctime>
- #include <iostream>
- using namespace std;
- int Date(int D, int M, int Y)
- {
- int a, y, m, R;
- a = (14 - M) / 12;
- y = Y - a;
- m = M + 12 * a - 2;
- R = 7000 + (D + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12);
- return R % 7;
- }
- int main()
- {
- int D, M, Y;
- char C;
- char mass[10];
- string S[7] = { "SUN", "MON", "TUS", "WED", "THU", "FRI", "SAT" };
- cout << "Enter the date(dd.mm.yyyy) : ";
- cin >> D >> C >> M >> C >> Y;
- if ((M == 4 || M == 6 || M == 9 || M == 11) && D>30) // если слишком много дней в коротком месяце
- {
- puts("The day or month is incorrect");
- exit(-2);
- }
- if (M == 2 && D >28) // отдельно проверяем месяц февраль
- {
- puts("The day or month is incorrect");
- exit(-3);
- }
- if (D >31) // если введен слишком большой день
- {
- puts("The day is incorrect");
- exit(-4);
- }
- if (M >12) // если введен слишком большой месяц
- {
- puts("The month is incorrect");
- exit(-5);
- }
- cout << S[Date(D, M, Y)] << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement