-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dop2.cpp
244 lines (216 loc) · 4.91 KB
/
Dop2.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
233
234
235
236
237
238
239
240
241
242
243
244
#include <iostream>
#include <Windows.h>
#include <conio.h>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
using namespace std;
//////////
void randArr(int arr[], const int N, int a, int b);
void temperatura(int arr[], const int N);
void studenti(int arr_2[], const int M);
void sportmean(int arr_3[], const int B);
void printArr(int arr[], const int N);
//////////
int main()
{
const int N = 30;
const int M = 20;
const int B = 9;
int arr[N];
int arr_2[M];
int arr_3[B];
srand(6);
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
while (true)
{
int num;
cout << "\t\t\t\tMenu:" << endl << endl;
cout << "\t1 - гçíèöÿ òåìïåðàòóð ì³æ íàéñïåêîòí³øèì òà íàéõîëîäí³øèì äíåì òðàâíÿ." << endl;
cout << "\t2 - ʳëüê³ñòü ãðóï ç íàéìåíøîþ ÷èñåëüí³ñòþ ñòóäåíò³â òà íîìåð ïåðøî¿ ç íèõ." << endl;
cout << "\t3 - Påçóëüòàòè 10 ñïîðòñìåí³â, ÿê³ ïðèéìàëè ó÷àñòü ó çàá³ãó íà 10 ìåòð³â." << endl;
cout << "\t4 - Âèõ³ä." << endl;
cout << endl << "\tÂâåä³òü ñâ³é âèá³ð: ";
cin >> num;
system("cls");system("cls");
switch (num)
{
case 1:
temperatura(arr, N);
break;
case 2:
studenti(arr_2, M);
break;
case 3: sportmean(arr_3, M);
break;
case 4: exit(0);
default:cout << "Error" << endl;
system("pause"); break;
}
system("cls");
}
}
void printArr(int arr[], const int N)
{
cout << endl << "\t";
for (int i = 0; i < N * 3 + 2; i++)
{
cout << "-";
}
cout << endl << "\t|";
for (int i = 0; i < N; i++)
{
cout << arr[i] << " ";
}
cout << "|" << endl << "\t";
for (int i = 0; i < N * 3 + 2; i++)
{
cout << "-";
}
cout << endl << endl;
}
void randArr(int arr[], const int N, int a, int b)
{
for (int i = 0; i < N; i++)
{
arr[i] = a + rand() % (b - a + 1);
}
}
void temperatura(int arr[], const int N)
{
randArr(arr, N, 18, 31);
int n;
while (true)
{
printArr(arr, N);
int max = arr[0], max_index = 0;
int min = arr[0], min_index = 0;
for (int i = 1; i < N; i++) {
if (arr[i] > max)
{
max = arr[i];
max_index = i;
}
if (arr[i] < min)
{
min = arr[i];
min_index = i;
}
}
cout << "\tгçíèöÿ òåìïåðàòóð ì³æ íàéñïåêîòí³øèì(" << max_index + 1 << ") òà íàéõîëîäí³øèì äíåì(" << min_index + 1 << ") òðàâíÿ - " << max - min << "°" << endl;
cout << endl << "n/N - return to menu" << endl;
n = _getch();
if (n == 78 || n == 110 || n == 210 || n == 242) break;
system("cls");
}
}
void studenti(int arr_2[], const int M)
{
randArr(arr_2, M, 20, 25);
int n;
while (true)
{
int min = arr_2[0], perMin = 0, kilkist = 0, j = 0;
printArr(arr_2, M);
for (int i = 0; i < M; i++) {
if (arr_2[i] < min)
{
min = arr_2[i];
}
}
for (int i = 0; i < M; i++) {
if (arr_2[i] == min)
{
if (j == 0)
{
perMin = i;
j++;
}
kilkist++;
}
}
cout << "ʳëüê³ñòü ãðóï ç íàéìåíøîþ ÷èñåëüí³ñòþ ñòóäåíò³â - " << kilkist << " (íîìåð ïåðøî¿ ç íèõ - " << perMin + 1 << ") " << endl;
cout << endl << "n/N - return to menu" << endl;
n = _getch();
if (n == 78 || n == 110 || n == 210 || n == 242) break;
system("cls");
}
}
void sportmean(int arr_3[], const int B)
{
randArr(arr_3, B, 5, 15);
int top1 = arr_3[0], top1_count = 0;
int top2 = arr_3[0], top2_count = 0;
int n;
while (true)
{
for (int i = 1; i < B; i++) {
if (arr_3[i] < top1)
{
top1 = arr_3[i];
}
if (arr_3[i] < top2 && arr_3[i] > top1)
{
top2 = arr_3[i];
}
}
for (int i = 1; i < B; i++) {
if (arr_3[i] == top1)
{
top1_count++;
}
if (arr_3[i] == top2)
{
top2_count++;
}
}
int j = 0;
int* top1Index = new int[top1_count];
int* top2Index = new int[top2_count];
for (int i = 1; i < B; i++)
{
if (arr_3[i] == top1)
{
top1Index[j] = i;
j++;
}
if (arr_3[i] == top2)
{
top2Index[j] = i;
}
}
if (top1_count == 1)
{
cout << "Ïåðøå ì³ñöå çàéìຠñïîðòñìåí ï³ä íîìåðîì " << top1Index[0] + 1 << " ç ðåçóëüòàòîì â " << arr_3[top1Index[0]] << " ñåêóíä." << endl;
}
else
{
cout << "Ïåðøå ì³ñöå çàéìàþòü ñïîðòñìåíè ï³ä íîìåðîì: ";
for (int i = 0; i < top1_count; i++)
{
cout << top1Index[i] << " ";
}
cout << " ç ðåçóëüòàòîì â " << arr_3[top1Index[0]] << " ñåêóíä." << endl;
}
if (top2_count == 1)
{
cout << "Äðóãå ì³ñöå çàéìຠñïîðòñìåí ï³ä íîìåðîì " << top2Index[0] + 1 << " ç ðåçóëüòàòîì â " << arr_3[top2Index[0]] << " ñåêóíä." << endl;
}
else
{
cout << "Äðóãå ì³ñöå çàéìàþòü ñïîðòñìåíè ï³ä íîìåðîì: ";
for (int i = 0; i < top2_count; i++)
{
cout << top2Index[i] << " ";
}
cout << " ç ðåçóëüòàòîì â " << arr_3[top2Index[0]] << " ñåêóíä." << endl;
}
delete[] top1Index;
delete[] top2Index;
cout << endl << "n/N - return to menu" << endl;
n = _getch();
if (n == 78 || n == 110 || n == 210 || n == 242) break;
system("cls");
}
}