Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. // Лаб 1 сиспр.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <cstdlib>
  6. #include <string>
  7. #include <ctime>
  8.  
  9.  
  10. #include <iostream>
  11.  
  12.  
  13. using namespace std;
  14.  
  15. int Date(int D, int M, int Y)
  16. {
  17. int a, y, m, R;
  18. a = (14 - M) / 12;
  19. y = Y - a;
  20. m = M + 12 * a - 2;
  21. R = 7000 + (D + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12);
  22. return R % 7;
  23. }
  24.  
  25. int main()
  26. {
  27. int D, M, Y;
  28. char C;
  29. char mass[10];
  30. string S[7] = { "SUN", "MON", "TUS", "WED", "THU", "FRI", "SAT" };
  31.  
  32. cout << "Enter the date(dd.mm.yyyy) : ";
  33.  
  34. cin >> D >> C >> M >> C >> Y;
  35.  
  36.  
  37. if ((M == 4 || M == 6 || M == 9 || M == 11) && D>30) // если слишком много дней в коротком месяце
  38. {
  39. puts("The day or month is incorrect");
  40. exit(-2);
  41. }
  42.  
  43. if (M == 2 && D >28) // отдельно проверяем месяц февраль
  44. {
  45. puts("The day or month is incorrect");
  46. exit(-3);
  47. }
  48.  
  49. if (D >31) // если введен слишком большой день
  50. {
  51. puts("The day is incorrect");
  52. exit(-4);
  53. }
  54.  
  55. if (M >12) // если введен слишком большой месяц
  56. {
  57. puts("The month is incorrect");
  58. exit(-5);
  59. }
  60. cout << S[Date(D, M, Y)] << endl;
  61.  
  62. system("pause");
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement