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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
| #include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <iomanip>
#include <cstring>
#include "fstream"
#include <conio.h>
#include <Windows.h>
#include <string>
using namespace std;
string menu[] = { "МЕНЮ", "1 задача", "2 задача", "ВЫХОД" };
string menu1[] = { "МЕНЮ задачи 1", "1. Создать журнал", "2. Очистка файла", "3. Удаление", "4. Вывод в файл", "Возврат с основное меню" };
string menu2[] = { "МЕНЮ задачи 2", "1. Ввод с клавиатуры", "2. Ввод рандом", "3. Обработка", "4. Вывод в файл", "Возврат с основное меню" };
int code, l,l1;
COORD position; // Объявление необходимой структуры
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Получение дескриптора устройства стандартного вывода
void AddInfo();
void Searchname(char *Predmet);
/*ОПИСЫВАЕМАЯ СТРУКТУРА*/
struct Journal
{
char Group[70];
char Student[70];
char Predmet[70];
char Ocenka[10];
char Nomer[10];
char Date[11];
};
/*ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ, ИЩУТ МАКСИМАЛЬНЫЕ СТРОКИ ДЛЯ КАЖДОЙ КОЛОНКИ*/
int get_max_caption(Journal* M, int N){
int maximum = strlen(M[0].Group);
int temp;
for (int i = 1; i<N; i++){
temp = strlen(M[i].Group);
if (temp > maximum) maximum = temp;
}
return maximum;
}
int get_max_student(Journal* M, int N){
int maximum = strlen(M[0].Student);
int temp;
for (int i = 1; i<N; i++){
temp = strlen(M[i].Student);
if (temp > maximum) maximum = temp;
}
return maximum;
}
int get_max_predmet(Journal* M, int N){
int maximum = strlen(M[0].Predmet);
int temp;
for (int i = 1; i<N; i++){
temp = strlen(M[i].Predmet);
if (temp > maximum) maximum = temp;
}
return maximum;
}
int get_max_ocenka(Journal* M, int N){
int maximum = strlen(M[0].Ocenka);
int temp;
for (int i = 1; i<N; i++){
temp = strlen(M[i].Ocenka);
if (temp > maximum) maximum = temp;
}
return maximum;
}
/*КОНЕЦ ВСПОМОГАТЕЛЬНЫХ ФУНКЦИЙ*/
/*ФУНКЦИЯ ОБЕСПЕЧИВАЕТ ВЫВОД ДАННЫХ НА ЭКРАН*/
void ShowData(Journal *M, int N)
{
cout << "\n\n";
cout << "Журнал\n";
struct ColumnWidth{ //Вспомогательная структура поможет обрабатывать промежуточные данные
int Group;
int Student;
int Prepodav;
int Predmet;
int Ocenka;
} ColumnWidth;
int temp; //Переменная для хранения подходящей ширины
/*ПОДСЧЁТ НУЖНОЙ ШИРИНЫ КОЛОНКАМ*/
ColumnWidth.Group = strlen("ГРУППА") + 1;
temp = get_max_caption(M, N) + 1;
if (ColumnWidth.Group < temp) ColumnWidth.Group = temp;
ColumnWidth.Student = strlen("Студент") + 1;
temp = get_max_caption(M, N) + 1;
if (ColumnWidth.Student < temp) ColumnWidth.Student = temp;
ColumnWidth.Predmet = strlen("Дисциплина") + 1;
temp = get_max_predmet(M, N) + 1;
if (ColumnWidth.Predmet < temp) ColumnWidth.Predmet = temp;
ColumnWidth.Ocenka = strlen("Оценка") + 1;
temp = get_max_caption(M, N) + 1;
if (ColumnWidth.Ocenka < temp) ColumnWidth.Ocenka = temp;
/*КОНЕЦ РАСЧЁТА*/
/*ЯЧЕЙКИ-ЗАГОЛОВКИ*/
//1
//ofstream journal("journal.txt");
cout << "ГРУППА" << setw(ColumnWidth.Group - strlen("ГРУППА")) << '|';
//2
cout << setw(6) << "НОМЕР" << '|';
//3
cout << setw(ColumnWidth.Student) << "СТУДЕНТ" << '|';
//3
cout << setw(ColumnWidth.Predmet) << "ДИСЦИПЛИНА" << '|';
//4
cout <<setw(4) <<"ОЦЕНКА" << setw(11 - strlen("ОЦЕНКА")) << '|';
//6
cout << setw(10) << "ДАТА" << '|';
/*КОНЕЦ ЯЧЕЕК-ЗАГОЛОВКОВ*/
cout << '\n';
/*ВЫВОДИМ МАССИВ СТРУКТУР ПОСТРОЧНО*/
for (int i = 0; i<N; i++){
//1
cout << M[i].Group << setw(ColumnWidth.Group - strlen(M[i].Group)) << '|';
//2
cout << setw(6) << M[i].Nomer << '|';
//3
cout << setw(ColumnWidth.Student) << M[i].Student << '|'; cout.width(10);
//4.3
cout << setw(ColumnWidth.Predmet) << M[i].Predmet << '|'; cout.width(10);
//5
(cout << setprecision(2) << fixed << M[i].Ocenka <<'|').width(10);
//6
cout << setw(10) << M[i].Date << '|';
cout << '\n';
}
/*КОНЕЦ ПОСТРОЧНОГО ВЫВОДА*/
cout << '\n';
}
/*ФУНКЦИЯ ЗАНОСИТ ДАННЫЕ В СТРУКТУРУ*/
void GetData(Journal *M, int N)
{
ofstream journal("journal.txt");
for (int i = 0; i<N; i++)
{
cout << "\n";
cout << "ГРУППА: ";
cin.getline(M[i].Group, sizeof(M[i].Group));
cout << "Номер ";
cin >> M[i].Nomer; cin.ignore();
cout << "Студент: ";
cin.getline(M[i].Student, sizeof(M[i].Student));
cout << "Дисциплина: ";
cin.getline(M[i].Predmet, sizeof(M[i].Predmet));
cout << "Оценка: ";
cin >> M[i].Ocenka;
cin.ignore();
cout << "ДАТА ";
cin >> M[i].Date; cin.ignore();
//journal<<endl;
for (int i = 0; i<N; i++)
{
journal<<"группа "<<M[i].Group<<endl<<"Номер "<< M[i].Nomer<<endl<<"Cтудент "<< M[i].Student<<endl<<" предмет "<< M[i].Predmet<<endl<<" оценка "<< M[i].Ocenka<<endl<<" дата "<< M[i].Date<<endl<<endl;
//fin<<M[i].Group<<" "<< M[i].Nomer<<" "<< M[i].Student<< " "<< M[i].Predmet<<" "<< M[i].audit<<" "<< M[i].Date;
//fin<<endl;
}
}
}
//void Searchname(char *Predmet)
//{
// for(int i=0; i<co l;i++){
// if (_stricmp(Predmet, M[i].Predmet)==0){
// cout<<"Название предмета: "<<Predmet[i].name<<"\n";
// cout<<"##########################\n";
// }
// else
// cout<<" не найден\n";
// }
//
//}
//void AddInfo()
//{
// int N;
// cout<<"Введите кол-во записей:\n";
// cin>>N;
// for (int i=0; i<N; i++){
// cout<<"Введите группу["<<i<<"]:\n";
// cin>>M[i].Group;
// cout<<"Введите номер студента["<<i<<"]:\n";
// cin>>M[i].Nomer;
// cout<<"Введите студента["<<i<<"]:\n";
// cin>>M[i].Student;
// cout<<"Введите предмет"<<i<<"]:\n";
// cin>>M[i].Predmet;
// cout<<"Введите дату["<<i<<"]:\n";
// cin>>M[i].Date;
//
// }
//}
int ochist()
{
ofstream journal;
journal.open("journal.txt", ofstream::out | ofstream::trunc);
journal.close();
return 0;
}
int del()
{
remove("journal.txt");
return 0;
}
/*ГЛАВНАЯ ФУНКЦИЯ*/
int osnova()
{
setlocale(LC_ALL, "");
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
system("CLS");
int N;
cout << "Введите N: ";
(cin >> N).ignore();
Journal *M = new Journal[N];
GetData(M, N); //Ввод данных в массив структур
ShowData(M, N); //Вывод массива структур на экран
delete[]M;
system("PAUSE");
return 0;
}
int print_menu(string menu[], int l)
{
char ch;
int i,m;
system("cls");
position.X = 5; // Установка координаты X
position.Y = 1; // Установка координаты Y
SetConsoleCursorPosition(hConsole, position); // Перемещение каретки по заданным координатам
cout<<menu[0]; // Вывод сообщения
position.X = 3;
for (i = 1; i <l; i++)
{
position.Y=i+1
;
SetConsoleCursorPosition(hConsole, position);
cout<<menu[i];
}
position.X = 2;
do
{
ch = _getch();
code = static_cast<int>(ch);
SetConsoleCursorPosition(hConsole, position);
puts(" ");
switch (code){
case 80: if (position.Y<l) position.Y++;
else position.Y = 2;
SetConsoleCursorPosition(hConsole, position);
puts(">");
break;
case 72: if (position.Y>2) position.Y--;
else position.Y = l;
SetConsoleCursorPosition(hConsole, position);
puts(">");
break;
}
} while (code != 13);
return position.Y;
}
int main()
{
setlocale(LC_ALL, "rus");
do
{
l=print_menu(menu,4);
do
{
switch (l)
{
case 2: l1 = print_menu(menu1, 6);
switch (l1)
{
case 2: position.X = 40;
osnova();
SetConsoleCursorPosition(hConsole, position);
break;
case 3: position.X = 40;
ochist();
SetConsoleCursorPosition(hConsole, position);
break;
case 4: position.X = 40;
del();
SetConsoleCursorPosition(hConsole, position);
break;
case 5: position.X = 40;
SetConsoleCursorPosition(hConsole, position); puts("1 out_file()");
break;
default:
break;
}
break;
case 3: l1 = print_menu(menu2, 6);
switch (l1)
{
case 2: position.X = 40;
SetConsoleCursorPosition(hConsole, position); puts("2 vvod_kb()");
break;
case 3: position.X = 40;
SetConsoleCursorPosition(hConsole, position); puts("2 vvod_file()");
break;
case 4: position.X = 40;
SetConsoleCursorPosition(hConsole, position); puts("2 obrabotka()");
break;
case 5: position.X = 40;
SetConsoleCursorPosition(hConsole, position); puts("2 out_file()");
break;
default:
break;
}
break;
//default: l = 6;
// break;
}_getch();
} while (l1 != 6);
} while (l != 4);
} |