Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Задание 4.5
- // Анастасия Коржилова
- // Вывести на дисплей календарь на выбранный месяц с учетом указанного номера дня недели для начала месяца. Определить количество выходных в заданном месяце.
- #include <iostream>;
- using namespace std;
- int main() {
- int month, start, counter = 0;
- cout << " Enter the number of the month (1-12): ";
- cin >> month;
- cout << " Enter the number of the day the month starts with (1-7): ";
- cin >> start;
- cout << "\n\t\t\t\t";
- switch (month)
- {
- case 1:
- cout << " January" << endl;
- break;
- case 2:
- cout << " February" << endl;
- break;
- case 3:
- cout << " March" << endl;
- break;
- case 4:
- cout << " April" << endl;
- break;
- case 5:
- cout << " May" << endl;
- break;
- case 6:
- cout << " June" << endl;
- break;
- case 7:
- cout << " July" << endl;
- break;
- case 8:
- cout << " August" << endl;
- break;
- case 9:
- cout << " September" << endl;
- break;
- case 10:
- cout << " October" << endl;
- break;
- case 11:
- cout << " November" << endl;
- break;
- case 12:
- cout << " December" << endl;
- break;
- default:
- cout << "Please, try again!" << endl;
- break;
- }
- cout << "\n\t Mon \t Tues \t Wed \t Thurs \t Fri \t Sat \t Sun \n";
- for (int i = 1; i <= start; i++) {
- cout << "\t";
- }
- cout << " ";
- int daysInMonth = 31;
- if (month % 2 != 0) {
- daysInMonth = 31;
- }
- else if (month % 2 == 0 && month != 2) {
- daysInMonth = 30;
- }
- else if (month == 2) {
- daysInMonth = 28;
- }
- for (int i = 1; i <= daysInMonth; i++) {
- if (start % 7 == 0) {
- cout << i << "\n\t ";
- counter++;
- start++;
- }
- else {
- cout << i << "\t ";
- if ((start + 1) % 7 == 0) {
- counter++;
- }
- start++;
- }
- }
- cout << "\n\n There are " << counter << " weekends this month." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement