-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendarPracticalWork7.cpp
232 lines (201 loc) · 4.99 KB
/
CalendarPracticalWork7.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include <iostream>
#include <map>
using namespace std;
enum Month
{
January = 1,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};
map<Month, string> _coloredMonths
{
{January, "\x1b[94mЯнварь\x1b[0m\n"},
{February, "\x1b[94mФевраль\x1b[0m\n"},
{March, "\x1b[92mМарт\x1b[0m\n"},
{April, "\x1b[92mАпрель\x1b[0m\n"},
{May, "\x1b[92mМай\x1b[0m\n"},
{June, "\x1b[91mИюнь\x1b[0m\n"},
{July, "\x1b[91mИюль\x1b[0m\n"},
{August, "\x1b[91mАвгуст\x1b[0m\n"},
{September, "\x1b[93mСентябрь\x1b[0m\n"},
{October, "\x1b[93mОктябрь\x1b[0m\n"},
{November, "\x1b[93mНоябрь\x1b[0m\n"},
{December, "\x1b[94mДекабрь\x1b[0m\n"}
};
string getSelectedMonth(short monthIndex);
short getSelectedDay(short monthIndex, short dayIndex);
void printStartInterface() {
for (const auto& month : _coloredMonths)
cout << "[" << (short)month.first << "] " << month.second;
}
void userInput() {
short monthIndex;
short dayIndex;
cout << "\nВыберете номер месяца (от 1 до 12): ";
cin >> monthIndex;
if (monthIndex < 1 || monthIndex > 12) {
cout << "\x1b[31mНе правильно введен номер месяца!\x1b[0m\n";
return;
}
string selectedMonthString = getSelectedMonth(monthIndex);
cout << "\n[+] Выбран месяц - " << selectedMonthString;
cout << "\nВыберете день месяца: ";
cin >> dayIndex;
short selectedDayString = getSelectedDay(monthIndex, dayIndex);
system("cls");
cout << "\n[+] Календарь: " << selectedDayString << " " << selectedMonthString;
}
string getSelectedMonth(short monthIndex) {
switch (monthIndex)
{
case Month::January:
return _coloredMonths[January];
case Month::February:
return _coloredMonths[February];
case Month::March:
return _coloredMonths[March];
case Month::April:
return _coloredMonths[April];
case Month::May:
return _coloredMonths[May];
case Month::June:
return _coloredMonths[June];
case Month::July:
return _coloredMonths[July];
case Month::August:
return _coloredMonths[August];
case Month::September:
return _coloredMonths[September];
case Month::October:
return _coloredMonths[October];
case Month::November:
return _coloredMonths[November];
case Month::December:
return _coloredMonths[December];
}
return "";
}
short getSelectedDay(short monthIndex, short dayIndex) {
switch (monthIndex) {
case Month::January:
if (dayIndex > 0 && dayIndex < 32)
return dayIndex;
else {
cout << "\nВведите число от 1 до 31";
break;
}
case Month::February:
if (dayIndex > 0 && dayIndex < 29)
return dayIndex;
else {
cout << "\nВведите число от 1 до 28";
break;
}
case Month::March:
if (dayIndex > 0 && dayIndex < 32)
return dayIndex;
else {
cout << "\nВведите число от 1 до 31";
break;
}
case Month::April:
if (dayIndex > 0 && dayIndex < 31)
return dayIndex;
else {
cout << "\nВведите число от 1 до 30";
break;
}
case Month::May:
if (dayIndex > 0 && dayIndex < 32)
return dayIndex;
else {
cout << "\nВведите число от 1 до 31";
break;
}
case Month::June:
if (dayIndex > 0 && dayIndex < 31)
return dayIndex;
else {
cout << "\nВведите число от 1 до 30";
break;
}
case Month::July:
if (dayIndex > 0 && dayIndex < 32)
return dayIndex;
else {
cout << "\nВведите число от 1 до 31";
break;
}
case Month::August:
if (dayIndex > 0 && dayIndex < 32)
return dayIndex;
else {
cout << "\nВведите число от 1 до 31";
break;
}
case Month::September:
if (dayIndex > 0 && dayIndex < 31)
return dayIndex;
else {
cout << "\nВведите число от 1 до 30";
break;
}
case Month::October:
if (dayIndex > 0 && dayIndex < 32)
return dayIndex;
else {
cout << "\nВведите число от 1 до 31";
break;
}
case Month::November:
if (dayIndex > 0 && dayIndex < 31)
return dayIndex;
else {
cout << "\nВведите число от 1 до 30";
break;
}
case Month::December:
if (dayIndex > 0 && dayIndex < 32)
return dayIndex;
else {
cout << "\nВведите число от 1 до 31";
break;
}
}
return 0;
}
bool checkStopUserInput() {
cout << "\nВведите \x1b[91m\"+\"\x1b[0m, чтобы перезапустить календарь или \x1b[91m\"-\"\x1b[0m, чтобы завершить программу.\n";
char userInpuntChar;
cin >> userInpuntChar;
while (userInpuntChar == '+' || userInpuntChar == '-') {
switch (userInpuntChar) {
case '+':
system("cls");
return true;
case '-':
return false;
default:
cout << "\nВведён некорректный символ, повторите ввод.";
break;
}
}
return true;
}
int main() {
setlocale(0, "");
do {
printStartInterface();
userInput();
} while (checkStopUserInput());
return 0;
}