Uses crt;
const
n = 10;
type
Car = record
DriverName: string[20];
Mark: string[20];
Number: string[6];
Color: string[20];
end;
var
cars: array[1..n] of Car;
i: integer;
function CarToString(c: Car): string;
begin
CarToString := c.DriverName + ' ' + c.Mark + ' ' + c.Number + ' ' + c.Color;
end;
procedure WriteToFile(data, file_name: string);
var
f: text;
begin
Assign(f, file_name);
Rewrite(f);
Write(f, data);
Close(f);
end;
procedure OpenFileToRead(file_name: string; var f: text);
begin
Assign(f, file_name);
Reset(f);
end;
procedure CreateFilesWithData(Drivers, Marks, Numbers, Colors: string);
var
c: Car;
s1, s2, s3, s4: string;
i: integer;
begin
for i := 1 to n do
begin
{c.DriverName := Random(9).ToString;}
write('Имя водителя = ');
readln(c.DriverName);
s1 := s1 + c.DriverName + chr(13);
{c.Mark := Random(9).ToString;}
write('Марка = ');
readln(c.Mark);
s2 := s2 + c.Mark + chr(13);
{c.Number := Random(100, 999).ToString + Random(100, 999).ToString;}
write('Номер = ');
readln(c.Number);
s3 := s3 + c.Number + chr(13);
{c.Color := Random(9).ToString;}
write('Цвет = ');
readln(c.Color);
s4 := s4 + c.Color + chr(13);
end;
WriteToFile(s1, Drivers);
WriteToFile(s2, Marks);
WriteToFile(s3, Numbers);
WriteToFile(s4, Colors);
end;
procedure ReadFiles(Drivers, Marks, Numbers, Colors: string);
var
f1, f2, f3, f4: text;
i: integer;
begin
OpenFileToRead(Drivers, f1);
OpenFileToRead(Marks, f2);
OpenFileToRead(Numbers, f3);
OpenFileToRead(Colors, f4);
i := 0;
while not Eof(f1) do
begin
i := i + 1;
ReadLn(f1, cars[i].DriverName);
ReadLn(f2, cars[i].Mark);
ReadLn(f3, cars[i].Number);
ReadLn(f4, cars[i].Color);
{не учитывается вариант что кол-во строк может быть разным}
end;
Close(f1);
Close(f2);
Close(f3);
Close(f4);
end;
function Query1(mark, color: string): string;
var
s: string;
i: integer;
begin
for i := 1 to n do
if (cars[i].Mark = mark) and (cars[i].Color = color) then
s := s + cars[i].DriverName + ' ' + cars[i].Number + chr(13);
if s = '' then Query1 := 'Ничего не найдено'
else Query1 := s;
end;
function Query2(): string;
var
s: string;
i: integer;
begin
for i := 1 to n do
if (cars[i].Number[1] = cars[i].Number[Length(cars[i].Number)]) then
s := s + cars[i].DriverName + ' ' + cars[i].Mark + ' ' + cars[i].Color + chr(13);
if s = '' then Query2 := 'Ничего не найдено'
else Query2 := s;
end;
var
mark, color: string;
begin
CreateFilesWithData('f1.txt', 'f2.txt', 'f3.txt', 'f4.txt');
ReadFiles('f1.txt', 'f2.txt', 'f3.txt', 'f4.txt');
for i := 1 to n do
writeln(CarToString(cars[i]));
Write('Искомая марка = ');readln(mark);
Write('Искомый цвет = ');readln(color);
writeln(Query1(mark, color));
writeln('Hомера начинаются и заканчиваются одной буквой');
writeln(Query2());
end.