Код на паскале
program CarSales;
var
choice: Integer;
procedure CreateCarFile;
var
f: TextFile;
begin
AssignFile(f, 'cars.txt');
Rewrite(f);
WriteLn(f, 'Toyota;Red;2020');
WriteLn(f, 'BMW;Black;2019');
WriteLn(f, 'Audi;White;2021');
WriteLn(f, 'Ford;Blue;2022');
CloseFile(f);
WriteLn('Файл cars.txt создан с данными об автомобилях.');
end;
procedure ReplaceCarBrandInFile(oldBrand, newBrand: string; year: Integer);
var
fOld, fNew: TextFile;
line: string;
begin
AssignFile(fOld, 'cars.txt');
AssignFile(fNew, 'cars_new.txt');
Reset(fOld);
Rewrite(fNew);
while not Eof(fOld) do
begin
ReadLn(fOld, line);
var carBrand := Copy(line, 1, Pos(';', line) - 1);
var carColor := Copy(line, Pos(';', line) + 1, Length(line));
carColor := Copy(carColor, 1, Pos(';', carColor) - 1);
var carYear := StrToInt(Copy(line, LastDelimiter(';', line) + 1, Length(line)));
if (carBrand = oldBrand) and (carYear > year) then
begin
carBrand := newBrand; // Меняем марку только для нужного автомобиля
end;
WriteLn(fNew, carBrand + ';' + carColor + ';' + IntToStr(carYear));
end;
CloseFile(fOld);
CloseFile(fNew);
// Заменяем старый файл новым
Rename(fNew, 'cars.txt');
end;
procedure ViewFilteredCars(year: Integer);
var
f: TextFile;
line: string;
carBrand, carColor: string;
carYear: Integer;
begin
AssignFile(f, 'cars.txt');
Reset(f);
WriteLn('Автомобили, выпущенные после ', year, ':');
while not Eof(f) do
begin
ReadLn(f, line);
carBrand := Copy(line, 1, Pos ';', line) - 1);
Delete(line, 1, Pos(';', line));
carColor := Copy(line, 1, Pos(';', line) - 1);
Delete(line, 1, Pos(';', line));
carYear := StrToInt(line);
if (carYear > year) then
WriteLn(carBrand + ';' + carColor + ';' + IntToStr(carYear));
end;
CloseFile(f);
end;
begin
repeat
WriteLn('Меню:');
WriteLn('1. Создание текстового файла cars.txt');
WriteLn('2. Замена марки автомобиля в файле cars.txt');
WriteLn('3. Просмотр автомобилей по году выпуска');
WriteLn('4. Выход');
Write('Выберите пункт меню: ');
ReadLn(choice);
case choice of
1: CreateCarFile;
2:
begin
var oldBrand, newBrand: string;
var year: Integer;
Write('Введите марку автомобиля для замены: ');
ReadLn(oldBrand);
Write('Введите новую марку автомобиля: ');
ReadLn(newBrand);
Write('Введите год для сравнения: ');
ReadLn(year);
ReplaceCarBrandInFile(oldBrand, newBrand, year);
end;
3:
begin
var year: Integer;
Write('Введите год для фильтрации: ');
ReadLn(year);
ViewFilteredCars(year);
end;
end;
until choice = 4;
WriteLn('Выход из программы.');
end.
Программу (причем, далеко не оптимально сгенерированный нейронкой код) вижу. А вот в чем суть вопроса - загадка. Поэтому, т.к. вопрос задан некорректно, увы, но тут помочь ничем невозможно.
И что надо делать