Voici un ti exp pr les fichiers en pascal pr un parking des voitures
program parking;
LABEL a,b,d;
const n=60;
type voiture = record
mat:string[10];
typ,cst:string[15];
crb,col:string[10];
suiv,n_p,n_r:integer;
option:string;
end;
table=array[1..n]of voiture;
var t : table;
m,k : char;
i,y,j :integer;
cle : string[10];
(******** hachage*****)
function h(cle:string):integer ;
var c,a:integer;
BEGIN
y:= 0;
for i :=1 to 9 do
begin
val(cle[i],c,a);
y:= c*i + y;
end;
h:=y mod 50;
END;
(****initialisation*****)
procedure init;
var i:integer ;
BEGIN
for i:= 1 to n do
begin
t[i].mat:='';
t[i].suiv:=-1;
end
END;
(*****insertion****)
procedure ins;
BEGIN
j:=1;
while(j=1) do
begin
k:= 'o';
while k='o' do
Begin
write('le matricule : ');
readln(cle);
if not(len(cle)) then writeln('Erreur')
else k:= 'n';
End;
y := h(cle) + 1;
if t[y].mat ='' then
begin
t[y].mat := cle ;
t[y].suiv := -1;
j:=0;
end else
begin
if (compr(t[y].mat,cle)=1) then
begin
writeln('Ce matricule existe deja !');
end else
begin
i:=51;
while (t[i].mat <> '') and (i<=60) do i := i +1;
if i > 60 then
begin
writeln ('espace des collisions insufisant');
j:=0;
end else
begin
t[i].mat := cle;
t[i].suiv := t[y].suiv;
t[y].suiv := i;
j:=0;
y:=i;
end;
end;
end;
end;
if (j=0) and (i<=60) then
begin
with t[y] do
begin
write('Le constructeur : '); readln(cst);
write('Le type : '); readln(typ);
write('Le couleur : '); readln(col);
write('Nomnre de places : '); readln(n_p);
write('Nombre portes : '); readln(n_r);
write('Carburant : '); readln(crb);
writeln('Les options : '); readln(option);
end;
end;
END;
(*****affichage*****)
procedure aff;
Begin
for i:= 1 to 60 do
begin
if t[i].mat<>'' then
begin
with t[i] do
begin
writeln('-------------------------');
writeln('Le matricule : ',mat);
writeln('Le constructeur : ',cst);
writeln('Le type : ',typ);
writeln('Le couleur : ',col);
writeln('Nomnre de places : ',n_p);
writeln('Nombre portes : ',n_r);
writeln('Carburant : ',crb);
writeln('Les options : ',option);
writeln('-------------------------');
end;
end;
end;
End;
(*****recherche****)
procedure recherche;
var nbr : integer;
BEGIN
j:=0;
nbr:=1;
write('Que vous voulez chercher?');
readln(cle);
y:= h(cle) + 1;
if t[y].mat='' then writeln('---1pas de resultat')
else
begin
while (compr(t[y].mat,cle)=0) and (t[y].suiv<>-1) do
begin
y:=t[y].suiv;
inc(nbr);
end;
if compr(t[y].mat,cle)=1 then
begin
with t[y] do
begin
writeln('---------------------------');
writeln('Le matricule : ',mat);
writeln('Le type : ',typ);
writeln('Le constucteur : ',cst);
writeln('Le couleur : ',col);
writeln('Nombres de places : ',n_p);
writeln('Nombres de portes : ',n_r);
writeln('Le carburant : ',crb);
writeln('Les options : ',option);
j:=1;
writeln('nombre d''acce au tableau : ',nbr);
writeln('---------------------------');
end;
end;
if (t[y].suiv=-1) and (j=0) then writeln('----3pas de resultat');
end;
END;
(*****spprimer****)
procedure supr;
var ins : boolean;
Begin
ins := false;
write('Donnez moi le matricule : '); readln(cle);
y := h(cle) +1;
if t[y].mat ='' then writeln('Erreur')
else
begin
while not(ins) do
begin
if (compr(t[y].mat,cle)=1)then
begin
if t[y].suiv<> -1 then
begin
i:=t[y].suiv;
with t[y] do
begin
mat:=t[i].mat;
cst:=t[i].cst;
typ:=t[i].typ;
col:=t[i].col;
n_p:=t[i].n_p;
n_r:=t[i].n_r;
crb:=t[i].crb;
option:=t[i].option;
suiv:=t[i].suiv;
ins := true;
t[i].mat:='';
t[i].suiv:=-1;
end;
end else
begin t[y].mat := ''; t[y].suiv:=-1; ins := true; end;
end else
begin
if t[y].suiv = -1 then writeln ('pas trouver!')
else y:= t[y].suiv;
end;
end;
end;
End;
(***** le programme****)
BEGIN
a : writeln(' Bien venue');
writeln('Ajouter 1');
writeln('Rechercher 2');
writeln('Suprimer 3');
writeln('Pourcentage 4');
writeln('Afficher 5');
writeln('Initialisation 6');
writeln('Quitter 7');
readln(m);
case m of
'1' :
begin k:= 'o';
while (k='o') do
begin
begin
ins;
d : writeln('voulez vous ajouter une autre voiture o/n? ');
readln(k);
if k='n' then
else begin
if k='o' then
else
begin
writeln ('erreur');
goto d;
end;
end;
end;
end;
end;
'2' : recherche;
'3' : supr ;
'5' : aff;
'6' : init;
'7' : exit;
else
begin
writeln('erreur');
goto a;
end;
end;
goto a;
END.