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
| #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <io.h>
#include <stdio.h>
using namespace std;
struct St
{
char FIO[50];
char Group[10];
int mat, phisica, infa;
double sr_ball;
};
void Create(FILE* file);
void PokazatStudents(FILE* file);
void Individ(FILE* file);
void Redact(FILE* file);
void Delete(FILE* file);
void SortFIO(FILE* file);
bool SravnenieBukv(char one[], char two[]);
void Sort_Sr_ball_Vbivanie(FILE* file);
void InfaStudentov(St* s);
void Sort_Sr_ball_Vozrastanie(FILE* file);
void Menu() {
FILE* file = fopen("student.txt", "wb");
fclose(file);
bool menu = 1;
while (menu == 1) {
cout << "1. Создать студента" << endl;
cout << "2. Просмотреть всех студентов" << endl;
cout << "3. Решение индивидуального задания" << endl;
cout << "4. Изменить информацию" << endl;
cout << "5. Удалить студента" << endl;
cout << "6. Сортировка ФИО(по алфавиту)" << endl;
cout << "7. Сортировка по среднему балу(возрастание" << endl;
cout << "8. Сортировка по среднему балу(убывание)" << endl;
cout << "9. Выйти из программы" << endl;
int n;
cin >> n;
switch (n) {
case 1: Create(file); break;
case 2: PokazatStudents(file); break;
case 3: Individ(file); break;
case 4: Redact(file); break;
case 5: Delete(file); break;
case 6: SortFIO(file); break;
case 7:Sort_Sr_ball_Vozrastanie(file); break;
case 8:Sort_Sr_ball_Vbivanie(file); break;
case 9: menu = 0; break;
default: cout << "Такого пункта нет";
}
}
}
int main()
{
setlocale(LC_ALL, "Russian");
Menu();
}
void Create(FILE* file) {
file = fopen("student.txt", "ab");
cout << "Введите фамилию, номер группы, оценки за математику, физику и информатику\n";
St s;
cin >> s.FIO >> s.Group >> s.mat >> s.phisica >> s.infa;
s.sr_ball = (s.mat + s.phisica + s.infa) / 3;
fwrite(&s, sizeof(St), 1, file);
fclose(file);
}
void PokazatStudents(FILE* file) {
file = fopen("student.txt", "rb");
St s;
int kolvo = _filelength(_fileno(file)) / sizeof(St);
for (int i = 0; i < kolvo; i++) {
fread(&s, sizeof(St), 1, file);
InfaStudentov(&s);
}
fclose(file);
}
void InfaStudentov(St* s)
{
cout << "ФИО: " << s->FIO << "\nГруппа: " << s->Group << endl;
cout << "Оценки:\nМатан: " << s->mat << "\nФизика: " << s->phisica << " \nИнфа: " << s->infa << endl;
cout << "Ср балл: " << s->sr_ball << endl << endl;
}
void Individ(FILE* file) {
{
}
fclose(file);
}
void Redact(FILE* file) {
file = fopen("student.txt", "r+b");
cout << "Введите номер студента\n";
int n;
cin >> n;
cout << "Выберите критерий, который хотите изменить \n1) ФИО \n2) Группу \n3) Оценки\n";
int choose;
cin >> choose;
St s;
fseek(file, (int)(sizeof(St)) * n - 1, 0);
fread(&s, sizeof(St), 1, file);
InfaStudentov(&s);
switch (choose)
{
case 1: cin >> s.FIO; break;
case 2: cin >> s.Group; break;
case 3:
{
cin >> s.mat >> s.phisica >> s.infa;
s.sr_ball = (s.infa + s.mat + s.phisica) / 3;
}
fwrite(&s, sizeof(St), 1, file);
}
fclose(file);
}
void Delete(FILE* file) {
file = fopen("student.txt", "r+b");
int kolvo = _filelength(_fileno(file)) / sizeof(St);
int n;
cout << "Введите номер студента";
cin >> n;
cout << "Вы уверены, что хотите удалить студента?\n 1.Да\n 2.Нет\n";
int choose;
cin >> choose;
if (choose == 1)
{
for (int i = n; i < kolvo; i++)
{
St s;
fseek(file, (int)(sizeof(St)) * (i + 1), 0);
fread(&s, sizeof(St), 1, file);
fseek(file, (int)(sizeof(St)) * i, 0);
fwrite(&s, sizeof(St), 1, file);
}
kolvo--;
_chsize(_fileno(file), kolvo * (int)(sizeof(St)));
}
fclose(file);
}
void SortFIO(FILE* file)
{
file = fopen("student.txt", "r+b");
int kolvo = _filelength(_fileno(file)) / sizeof(St);
for (int i = kolvo - 1; i > 0; i--)
for (int j = 0; j < i; j++) {
St s1, s2;
fseek(file, (int)(sizeof(St)) * j, 0);
fread(&s1, sizeof(St), 1, file);
fread(&s2, sizeof(St), 1, file);
if (SravnenieBukv(s1.FIO, s2.FIO)) {
fseek(file, (int)(sizeof(St)) * j, 0);
fwrite(&s2, sizeof(St), 1, file);
fwrite(&s1, sizeof(St), 1, file);
}
}
fclose(file);
}
bool SravnenieBukv(char one[], char two[]) {
for (int i = 0; i < 50; i++)
if (one[i] < two[i])
return true;
return false;
}
void Sort_Sr_ball_Vbivanie(FILE* file) {
file = fopen("student.txt", "r+b");
int kolvo = _filelength(_fileno(file)) / sizeof(St);
for (int i = kolvo - 1; i > 0; i--)
for (int j = 0; j < i; j++) {
St s1, s2;
fseek(file, (int)(sizeof(St)) * j, 0);
fread(&s1, sizeof(St), 1, file);
fread(&s2, sizeof(St), 1, file);
if (s1.sr_ball < s2.sr_ball) {
fseek(file, (int)(sizeof(St)) * j, 0);
fwrite(&s2, sizeof(St), 1, file);
fwrite(&s1, sizeof(St), 1, file);
}
}
fclose(file);
}
void Sort_Sr_ball_Vozrastanie(FILE* file) {
file = fopen("student.txt", "r+b");
int kolvo = _filelength(_fileno(file)) / sizeof(St);
for (int i = kolvo - 1; i > 0; i--)
for (int j = 0; j < i; j++) {
St s1, s2;
fseek(file, (int)(sizeof(St)) * j, 0);
fread(&s1, sizeof(St), 1, file);
fread(&s2, sizeof(St), 1, file);
if (s1.sr_ball > s2.sr_ball) {
fseek(file, (int)(sizeof(St)) * j, 0);
fwrite(&s2, sizeof(St), 1, file);
fwrite(&s1, sizeof(St), 1, file);
}
}
fclose(file);
} |