Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

vlad / TURBO P / tp7 / BIN / ZAHOROV - копия

.PAS
Скачиваний:
3
Добавлен:
12.02.2016
Размер:
4.7 Кб
Скачать
program a1;
uses crt;
type auto=record
name_auto:string;
price:real;
power:real;
end;{record}
f1=file of auto;
var f:f1;
user_case:byte;
{----------------}
procedure Fill (var fz:f1);
var y_n:char;
el:auto;
i,k,nom:integer;
BEGIN
assign(fz,'file1.txt');
reset(fz);
if ioresult <>0 then
begin
rewrite(fz);
writeln('File created');
end;
writeln ('File is opening');
writeln('Do you wish to create new file(1) or rewrite (2)?:');
writeln('Do you wish not to do anything(0)?:');
readln(y_n);
if y_n='1' then
begin
seek(fz,filesize(fz));
writeln('Input the number of the new records: ');
readln(k);
for i:=1 to k do
begin
with el do
begin
write('Input the name of the auto ');
readln(name_auto);
write('Input the price ');
readln(price);
writeln('Input the power of auto ');
readln(power);
end;
write(fz,el);
end;

end
else
if y_n='2' then
begin
writeln('Input the number of the current record ');
readln(nom);
seek(fz,nom-1);
with el do
begin
write ('Input the name of the auto ');
readln(name_auto);
writeln('Input the price ');
readln(price);
writeln('Input the power of the auto ');
readln(power);
end;
write(fz,el);
end;
End;
{-----------------------}
procedure Tabl;
begin
writeln('|---------------|---------------|---------------|');
writeln('| Auto | Price | Power |');
writeln('|---------------|---------------|---------------|');
end;
{-----------------------}
procedure Rfail(var fz:f1);
var el:auto;
Begin
tabl;
seek(fz,0);
while not eof(fz) do
begin
read(fz,el);
with el do
writeln('||',name_auto:14,'||',price:8:2,'||',power:10:2,'||');
end;
writeln('||______________||_____________||______________||');
end;
{------------------------------}
procedure d1(var fz:f1);
var el:auto;
name:string;
Begin
writeln('Input the name:');
readln(name);
writeln;
tabl;
seek(fz,0);
while not eof(fz) do
begin
read(fz,el);
if el.name_auto=name then
begin
with el do
writeln('||',name_auto:14,'||',price:8:2,'||',power:10:2,'||');
end;
writeln('||_______________||_______________||_______________||');
end;
End;
{----------------------------}
procedure d2(var fz:f1);
var el:auto;
pricex:real;
Begin
writeln('Input the price of the auto');
readln(pricex);
writeln('The autos with this price:');
writeln;
tabl;
seek(fz,0);
while not eof(fz) do
begin
read(fz,el);
if (el.price=pricex) then
begin
with el do
writeln('||',name_auto:14,'||',price:8:2,'||',power:10:2,'||');
end;
writeln('||_______________||_______________||_______________||');
end;
end;
{---------------------}
procedure d3(var fz:f1);
var el:auto;
powerx:real;
Begin
writeln('Input the power of the auto');
readln(powerx);
writeln('The autos with entered power:');
writeln;
tabl;
seek(fz,0);
while not eof (fz) do
begin
read(fz,el);
if (el.power=powerx) then
begin
with el do
writeln('||',name_auto:14,'||',price:8:2,'||',power:10:2,'||');
end;
writeln('||_______________||_______________||_______________||');
end;
end;
{----------------------}
BEGIN
clrscr;
Fill(f);
repeat clrscr;
writeln('Select 1..5 submenus');
writeln('Input the number of the item and press <Enter>');
writeln;
writeln('1 - All file information');
writeln('2 - The autos with selected name');
writeln('3 - The autos with selected price');
writeln('4 - The autos with selected power');
writeln('5 - Exit');
readln(user_case);
case user_case of
1: begin
clrscr;
Rfail(f);
end;
2: begin clrscr;
d1(f);
end;
3: begin clrscr;
d2(f);
end;
4: begin clrscr;
d3(f);
end;
5: halt;
end;{case}
writeln;readln;
until user_case=5;
readln;
End.


Соседние файлы в папке BIN