Ficha nº3
Program estacionamento;
type popo=record
marca:string;
matricula:string;
tempo:integer;
tipo:string;
end;
var fich: file of popo;
i,n,cont,maior,op:integer;
mat,matri:string;
parque:popo;
procedure criar_ficheiro;
begin
assign(fich,'estacionar');
rewrite(fich);
end;
procedure dados;
begin
reset(fich);
writeln('Quantos ve¡culos?');
readln(n);
seek(fich, filesize(fich));
for i:=1 to n do
begin
writeln('Introduza a marca do ve¡culo');
Readln(parque.marca);
Writeln('Introduza a matr¡cula do ve¡culo');
readln(parque.matricula);
writeln('Tempo de estacionamento');
readln(parque.tempo);
writeln('Introduza o tipo de ve¡culo - ligeiro, pesado, moto');
readln(parque.tipo);
Writeln('*************************************');
writeln('*************************************');
write(fich,parque);
end;
close(fich);
end;
procedure listar;
begin
reset(fich);
cont:=0;
If filesize(fich)=0 then
Write('NÆo h registos no ficheiro')
Else
Begin
while not eof (fich) do
begin
read(fich,parque);
Writeln('Matricula: ',parque.matricula);
Writeln('Tempo de estacionamento: ', parque.tempo);
Writeln('Tipo de veiculo: ', parque.tipo);
writeln('****************************************');
writeln('****************************************');
cont:=cont+parque.tempo;
end;
writeln('Tempo m‚dio: ', cont/filesize(fich));
seek(fich,0);
read(fich,parque);
maior:=parque.tempo;
mat:=parque.matricula;
while not eof (fich) do
begin
read(fich,parque);
if maior<parque.tempo then
begin
maior:=parque.tempo;
mat:=parque.matricula;
end;
end;
writeln('Autom¢vel com mais tempo:',mat,'Tempo= ',maior);
end;
close(fich);
end;
procedure alterar;
begin
writeln('Introduza a matr¡cula a alterar dados');
read(matri);
reset(fich);
while not eof (fich) do
begin
read(fich,parque);
if parque.matricula=matri then
begin
Writeln('MARCA');readln();
readln(parque.marca);
writeln('Matr¡cula');
readln(parque.matricula);
writeln('Tempo estacionado');
readln(parque.tempo);
seek(fich,filepos(fich)-1);
write(fich,parque);
end
else
writeln('Matr¡cula nÆo encontrada');
end;
close(fich);
end;
procedure relatorio;
begin
reset(fich);
while not eof (fich) do
begin
read(fich, parque);
if parque.tipo='moto' then
begin
Writeln('Matr¡cula: ', parque.matricula);
writeln('Tempo: ', parque.tempo);
writeln('Valor pago: ', (0.04*parque.tempo)*0.2);
writeln('*********************************************');
writeln('*********************************************');
end;
if parque.tipo='ligeiro' then
begin
Writeln('Matrícula: ', parque.matricula);
writeln('Tempo: ', parque.tempo);
writeln('Valor pago: ', (0.08*parque.tempo)*0.2);
writeln('*********************************************');
writeln('*********************************************');
end;
if parque.tipo='pesado' then
begin
Writeln('Matrícula: ', parque.matricula);
writeln('Tempo: ', parque.tempo);
writeln('Valor pago: ', (0.1*parque.tempo)*0.2);
writeln('*********************************************');
writeln('*********************************************');
end;
end;
close(fich);
end;
procedure apagar;
begin
rewrite(fich);
end;
Begin
repeat
writeln('Escolha uma das opções');
Writeln('*1-Criar ficheiro');
Writeln('*2-Introduzir registos');
writeln('*3-Apresentar dados');
writeln('*4-Alterar dados');
writeln('*5-Relat¢rio de contas');
writeln('*6-Limpar dados');
writeln('*7-Sair');
readln(op);
case op of
1:criar_ficheiro;
2:dados;
3:listar;
4:alterar;
5:relatorio;
6:apagar;
end;
until(op=7);
End.
Refleção
ResponderEliminareu neste programa que colocei no blogger fiquei a saber o significa e o que falaz o filesize e o filepos