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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
| program пппп;
procedure punct1;
type
Car = record
Brand: string;
VIN: string;
end;
var
ClientBase: array of Car;
procedure DisplayMenu;
begin
writeln('Меню:');
writeln('1. Посмотреть список автомобилей и их VIN');
writeln('2. Добавить автомобиль и его VIN');
writeln('3. Сохранить базу данных в файл');
writeln('4. Загрузить базу данных из файла');
writeln('5. Выход');
end;
procedure ShowCarList;
var
i: integer;
begin
writeln('Список автомобилей и их VIN:');
for i := 0 to High(ClientBase) do
writeln(ClientBase[i].Brand, ': ', ClientBase[i].VIN);
end;
procedure AddCar;
var
NewCar: Car;
begin
writeln('Введите марку автомобиля:');
readln(NewCar.Brand);
writeln('Введите VIN автомобиля:');
readln(NewCar.VIN);
SetLength(ClientBase, Length(ClientBase) + 1);
ClientBase[High(ClientBase)] := NewCar;
writeln('Автомобиль успешно добавлен в базу.');
end;
procedure SaveToFile(FileName: string);
var
i: integer;
FileHandle: TextFile;
begin
AssignFile(FileHandle, FileName);
Rewrite(FileHandle);
for i := 0 to High(ClientBase) do
writeln(FileHandle, ClientBase[i].Brand, ',', ClientBase[i].VIN);
CloseFile(FileHandle);
writeln('База данных успешно сохранена в файле ', FileName);
end;
procedure LoadFromFile(FileName: string);
var
Brand, VIN: string;
FileHandle: TextFile;
begin
AssignFile(FileHandle, FileName);
Reset(FileHandle);
SetLength(ClientBase, 0);
while not Eof(FileHandle) do
begin
ReadLn(FileHandle, Brand, VIN);
SetLength(ClientBase, Length(ClientBase) + 1);
ClientBase[High(ClientBase)].Brand := Brand;
ClientBase[High(ClientBase)].VIN := VIN;
end;
CloseFile(FileHandle);
writeln('База данных успешно загружена из файла ', FileName);
end;
procedure MainLoop;
var
Choice: integer;
FileName: string;
begin
repeat
DisplayMenu;
readln(Choice);
case Choice of
1: ShowCarList;
2: AddCar;
3: begin
writeln('Введите имя файла для сохранения базы данных:');
readln(FileName);
SaveToFile(FileName);
end;
4: begin
writeln('Введите имя файла для загрузки базы данных:');
readln(FileName);
LoadFromFile(FileName);
end;
5: writeln('До свидания!');
else
writeln('Неверный выбор. Попробуйте еще раз.');
end;
until Choice = 5;
end;
procedure punct2;
type
Car = record
Name: string;
Mileage: integer;
end;
// Функция для отображения меню и получения выбора пользователя
function DisplayMenu: integer;
begin
Writeln('Меню:');
Writeln('1. Добавить ваш автомобиль с пробегом');
Writeln('2. Просмотреть список пробега');
Writeln('3. Сохранить список пробега в файл');
Writeln('4. Загрузить список пробега из файла');
Writeln('5. Выход');
Write('Введите ваш выбор: ');
Readln(Result);
end;
// Процедура для сохранения списка пробега в файл
procedure SaveMileageListToFile(const Cars: array of Car; const FileName: string);
var
F: TextFile;
i: integer;
begin
AssignFile(F, FileName);
Rewrite(F);
try
for i := 0 to High(Cars) do
Writeln(F, Cars[i].Name, ',', Cars[i].Mileage);
finally
CloseFile(F);
end;
end;
// Процедура для загрузки списка пробега из файла
procedure LoadMileageListFromFile(var Cars: array of Car; const FileName: string);
var
F: TextFile;
CarRecord: Car;
Line: string;
begin
AssignFile(F, FileName);
Reset(F);
SetLength(Cars, 0);
try
while not Eof(F) do
begin
Readln(F, Line);
CarRecord.Name := Copy(Line, 1, Pos(',', Line) - 1);
CarRecord.Mileage := StrToInt(Copy(Line, Pos(',', Line) + 1, Length(Line)));
SetLength(Cars, Length(Cars) + 1);
Cars[High(Cars)] := CarRecord;
end;
finally
CloseFile(F);
end;
end;
var
Cars: array of Car;
Choice, i: integer;
FileName: string;
begin
SetLength(Cars, 0);
FileName := 'mileage.txt'; // Определение имени файла по умолчанию для сохранения и загрузки
repeat
Choice := DisplayMenu;
case Choice of
1: begin
SetLength(Cars, Length(Cars) + 1);
Write('Введите название автомобиля: ');
Readln(Cars[High(Cars)].Name);
Write('Введите пробег автомобиля: ');
Readln(Cars[High(Cars)].Mileage);
end;
2: begin
Writeln('Список пробега автомобилей:');
for i := 0 to High(Cars) do
Writeln(Cars[i].Name, ': ', Cars[i].Mileage);
end;
3: begin
SaveMileageListToFile(Cars, FileName);
Writeln('Список пробега сохранен в файле ', FileName);
end;
4: begin
LoadMileageListFromFile(Cars, FileName);
Writeln('Список пробега загружен из файла ', FileName);
end;
5: Writeln('Завершение программы...');
else
Writeln('Неверный выбор. Пожалуйста, попробуйте снова.');
end;
until Choice = 5;
end;
procedure punct3;
type
Car = record
Brand: string; // Марка
Year: integer; // Год выпуска
LastServiceYear: integer; // Год последнего обслуживания
end;
var
CurrentYear: integer; // Текущий год
Cars: array of Car; // Массив автомобилей
FileName: string = 'car_data.txt'; // Имя файла данных
procedure AddCar(var Cars: array of Car; Brand: string; Year: integer; LastServiceYear: integer);
begin
SetLength(Cars, Length(Cars) + 1);
Cars[High(Cars)].Brand := Brand;
Cars[High(Cars)].Year := Year;
Cars[High(Cars)].LastServiceYear := LastServiceYear;
end;
procedure DisplayCarList(Cars: array of Car);
var
i: integer;
begin
writeln('Список автомобилей, требующих обслуживания:');
for i := 0 to High(Cars) do
begin
if (CurrentYear - Cars[i].LastServiceYear) >= 3 then
begin
writeln(i + 1, '.', Cars[i].Brand, ' (Год выпуска: ', Cars[i].Year, ')');
writeln('Требуется обслуживание');
end;
end;
end;
procedure EditCar(var Cars: array of Car);
var
Number: integer;
NewYear: integer;
begin
writeln('Введите номер автомобиля для редактирования:');
readln(Number);
if (Number >= 1) and (Number <= Length(Cars)) then
begin
writeln('Введите новый год выпуска для ', Cars[Number - 1].Brand, ':');
readln(NewYear);
Cars[Number - 1].Year := NewYear;
Cars[Number - 1].LastServiceYear := NewYear;
writeln('Информация об автомобиле обновлена.');
end
else
writeln('Неверный номер автомобиля.');
end;
procedure UserInputCar(var Cars: array of Car);
var
Brand: string;
Year: integer;
LastServiceYear: integer;
begin
writeln('Введите марку вашего автомобиля:');
readln(Brand);
writeln('Введите год выпуска вашего автомобиля:');
readln(Year);
writeln('Введите год последнего обслуживания вашего автомобиля:');
readln(LastServiceYear);
AddCar(Cars, Brand, Year, LastServiceYear);
end;
procedure SaveToFile(FileName: string; Cars: array of Car);
var
i: integer;
FileHandle: TextFile;
begin
AssignFile(FileHandle, FileName);
Rewrite(FileHandle);
for i := 0 to High(Cars) do
writeln(FileHandle, Cars[i].Brand, '|', Cars[i].Year, '|', Cars[i].LastServiceYear);
CloseFile(FileHandle);
writeln('Данные об автомобилях успешно сохранены в файл ', FileName);
end;
procedure LoadFromFile(FileName: string; var Cars: array of Car);
var
TextFile: Text;
Brand, Line: string;
Year, LastServiceYear: integer;
begin
AssignFile(TextFile, FileName);
Reset(TextFile);
while not EOF(TextFile) do
begin
readln(TextFile, Line);
// Разделение строки на марку, год выпуска и год последнего обслуживания
Brand := Copy(Line, 1, Pos('|', Line) - 1);
Delete(Line, 1, Pos('|', Line));
Year := StrToInt(Copy(Line, 1, Pos('|', Line) - 1));
Delete(Line, 1, Pos('|', Line));
LastServiceYear := StrToInt(Line);
AddCar(Cars, Brand, Year, LastServiceYear);
end;
CloseFile(TextFile);
writeln('Данные об автомобилях успешно загружены из файла ', FileName);
end;
procedure MainMenu(var Cars: array of Car);
var
Choice: integer;
begin
repeat
writeln;
writeln('Меню:');
writeln('1. Ввести данные автомобиля');
writeln('2. Показать список автомобилей');
writeln('3. Редактировать информацию об автомобиле');
writeln('4. Сохранить данные автомобилей в файл');
writeln('5. Загрузить данные автомобилей из файла');
writeln('6. Выход');
writeln('Выберите опцию:');
readln(Choice);
case Choice of
1: UserInputCar(Cars);
2: DisplayCarList(Cars);
3: EditCar(Cars);
4: SaveToFile(FileName, Cars);
5: LoadFromFile(FileName, Cars);
end;
until Choice = 6;
end;
procedure writemenu(var h: integer);
{Процедура для подсвечивания пунктов меню}
const
menu: array[1..6] of string =
('Пункт 1',
'Пункт 2',
'Пункт 3',
'Пункт 4',
'Пункт 5',
'Выход');
var
item: integer;
pressedkey: char;
begin
for item:= 1 to length(menu) do
begin
if item = h
then
begin
TextBackground(Blue);
TextColor(White);
end
else
begin
TextBackground(Black);
TextColor(White);
end;
writeln(item,'.',menu[item]);
end;
TextBackground(black);
TextColor(White);
pressedkey:= ReadKey();
if pressedkey = char(13)
then
exit;
if pressedkey <> char(0)
then
begin
writemenu(h);
exit;
end;
pressedkey:= readkey();
if pressedkey = char(72)
then
h:= h-1;
if pressedkey = char(80)
then
h:= h+1;
if h > length(menu)
then
h:= 1
else
if h < 1
then
h:= length(menu);
writemenu(h);
end;
var
h: integer;
begin
h:= 1;
while true do
begin
writemenu(h);
clrscr();
case h of
1: begin
punct1;
end;
2: begin
punct2;
end;
3: begin
punct3;
end;
4: begin
punct4;
end;
5: begin
punct5;
end;
6: exit;
end;
writeln;
writeln('Нажмите "Enter" чтобы вернуться в меню.');
ReadLn();
end;
end;
begin
MainLoop;
FileName := 'mileage.txt';
CurrentYear := 2024; // Установка текущего года
end;
begin
end. |