Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. // Задание 4.5
  2. // Анастасия Коржилова
  3. // Вывести на дисплей календарь на выбранный месяц с учетом указанного номера дня недели для начала месяца. Определить количество выходных в заданном месяце.
  4.  
  5. #include <iostream>;
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11.     int month, start, counter = 0;
  12.     cout << " Enter the number of the month (1-12): ";
  13.     cin >> month;
  14.  
  15.     cout << " Enter the number of the day the month starts with (1-7): ";
  16.     cin >> start;
  17.     cout << "\n\t\t\t\t";
  18.  
  19.     switch (month)
  20.     {
  21.     case 1:
  22.         cout << " January" << endl;
  23.         break;
  24.     case 2:
  25.         cout << " February" << endl;
  26.         break;
  27.     case 3:
  28.         cout << " March" << endl;
  29.         break;
  30.     case 4:
  31.         cout << " April" << endl;
  32.         break;
  33.     case 5:
  34.         cout << " May" << endl;
  35.         break;
  36.     case 6:
  37.         cout << " June" << endl;
  38.         break;
  39.     case 7:
  40.         cout << " July" << endl;
  41.         break;
  42.     case 8:
  43.         cout << " August" << endl;
  44.         break;
  45.     case 9:
  46.         cout << " September" << endl;
  47.         break;
  48.     case 10:
  49.         cout << " October" << endl;
  50.         break;
  51.     case 11:
  52.         cout << " November" << endl;
  53.         break;
  54.     case 12:
  55.         cout << " December" << endl;
  56.         break;
  57.     default:
  58.         cout << "Please, try again!" << endl;
  59.         break;
  60.     }
  61.  
  62.     cout << "\n\t Mon \t Tues \t Wed \t Thurs \t Fri \t Sat \t Sun \n";
  63.  
  64.     for (int i = 1; i <= start; i++) {
  65.         cout << "\t";
  66.     }
  67.     cout << " ";
  68.     int daysInMonth = 31;
  69.  
  70.     if (month % 2 != 0) {
  71.         daysInMonth = 31;
  72.     }
  73.     else if (month % 2 == 0 && month != 2) {
  74.         daysInMonth = 30;
  75.     }
  76.     else if (month == 2) {
  77.         daysInMonth = 28;
  78.     }
  79.  
  80.     for (int i = 1; i <= daysInMonth; i++) {
  81.         if (start % 7 == 0) {
  82.             cout << i << "\n\t ";
  83.             counter++;
  84.             start++;
  85.         }
  86.         else {
  87.             cout << i << "\t ";
  88.             if ((start + 1) % 7 == 0) {
  89.                 counter++;
  90.             }
  91.             start++;
  92.         }
  93.     }
  94.  
  95.     cout << "\n\n There are " << counter << " weekends this month." << endl;
  96.  
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement