no save
Assistance
Achat
News

Forum | programmation
Exercice pascal
foufou, le mar. 13 nov. 2007 à 23:10:40
Bonjour,
j'ai un exercice en langage pascal qui permet d'ajouter des articles et les affichees puis il fait la trie de ces articles selon leurs quantites de stoskes mais le probleme que la trie ne marche pas correctement alors si pouver m'aidee





program ex ;
uses wincrt;
type
article = record
num_art:word;
nom_art:string[20];
dat_appro:string[10];
qt_stk:integer;
pu:real;
end;

fichier = file of article;

var
fiche : fichier;
v:article;
choix:integer;

procedure menu;
begin
clrscr;
writeln('**********************************************************');
writeln('********* MENU GENERAL ***** GESTION DU STOCK ************');
writeln('**********************************************************');
writeln;
writeln;
writeln('-1- Creation du fichier');
writeln('-2- Ajouter les articles');
writeln('-3- Afficher les articles');
writeln('-4- Afficher la valeur du stock');
writeln('-5- Afficher les articles trié par ordre croissant selon la quantité en stock');
writeln('-6- Fin');
write('Tapez votre choix (1,2,3,4): ');
end;

procedure creation(var fiche:fichier);
begin
assign(fiche,'c:\4sig1dc1\articles.fch');
rewrite(fiche);
end;

procedure ajouter(var fiche:fichier);
var v:article;
rep:char;
begin
repeat
clrscr;
writeln('**********************************************************');
writeln('****************** AJOUTER UN ARTICLE ****************');
writeln('**********************************************************');
writeln;
writeln;
write('Donner le numéro de l''article: '); readln(v.num_art);
write('Donner le nom de l''article: '); readln(v.nom_art);
write('Donner la date du dernier approvisionnement: '); readln(v.dat_appro);
write('Donner la quantité en stock: '); readln(v.qt_stk);
write('Donner le prix unitaire: '); readln(v.pu);
write(fiche,v); {*** écriture dans le fichier ***}
writeln;
writeln;
repeat
write('Voulez vous continuer: ');readln(rep);
until upcase(rep) in['O','N'];
until upcase(rep) = 'N';
end;

procedure afficher(var fiche:fichier);
var v:article;
begin
reset(fiche);
while not(EOF(fiche)) do
begin
read(fiche,v); {*** lecture à partir du fichier dans v ***}
{clrscr;}
writeln('**********************************************************');
writeln('**************** AFFICHAGE DES ARTICLES **************');
writeln('**********************************************************');
writeln;
writeln;
writeln('Numéro de l''article: ',v.num_art);
writeln('Nom de l''article: ',v.nom_art);
writeln('Date du dernier approvisionnement: ',v.dat_appro);
writeln('Quantité en stock: ',v.qt_stk);
writeln('Prix unitaire: ',v.pu:7:3);
write('Tapez sur une touche pour passer à l''article suivant'); readln;
end;
end;

function val_stock(var fiche:fichier):real;
var v:article;
i:integer;
val:real;
begin
reset(fiche);
val:=0;
while not(EOF(fiche)) do
begin
read(fiche,v);
val:=val+v.qt_stk;
end;
val_stock:=val;
end;

procedure tri(var fiche:fichier);
var
fiche2:fichier;
v:article;
i,max:integer;
begin
assign(fiche2,'c:\4sig1dc1\temp.fch');
rewrite(fiche2);
reset(fiche);

repeat
max:=-1;


while not(EOF(fiche)) Do {trouver la valeur maximale}
begin
read(fiche,v);
if v.qt_stk>max then
begin
max:=v.qt_stk;
write( v.qt_stk);
end;
end;

if max<>-1 then
begin

while not(EOF(fiche)) Do
begin
read(fiche,v);
if v.qt_stk=max then
begin
write(fiche2,v);
write( v.qt_stk);
end;
end;
end;
until max=-1;
{ close(fiche); }
rewrite(fiche);
reset(fiche2);

while not(EOF(fiche2)) Do
begin
read(fiche2,v);
write(fiche,v);
end;
close(fiche2);

end;

begin {***** PROGRAMME PRINCIPAL ******}
repeat
menu;
readln(choix);
case choix of
1: begin
creation(fiche);
clrscr;
writeln('*** fichier crée avec succés ***');
write('*** appuyer sur une touche pour revenir au MENU GENERAL ***');
readln;
end;
2: ajouter(fiche);
3: afficher(fiche);
4: begin
clrscr;
writeln('********************************************************');
writeln('********* AFFICHAGE DE LA VALEUR DU STOCK **************');
writeln('********************************************************');
writeln;
writeln;
writeln('La valeur du stock est: ',val_stock(fiche):7:3);
write('Tapez sur une touche pour revenir au MENU GENERAL'); readln;
end;
5: begin
tri(fiche);
afficher(fiche);
readln;
end;
6:close(fiche);
end;
until choix=6;
end. Configuration: Windows XP
Internet Explorer 6.0


tarek_dotzero
nov. 07
Suivant
REPONSES
tarek_dotzero
nov. 07
mohamed
janv. 08
marocco
févr. 08
dali
mars 08
mahmoud007
mars 08
Sou007
avr. 08
mias23
avr. 08
Jade
avr. 08
tarek_dotzero
avr. 08
mina19
25 mars
Version Web
Réalisé par RedShift
no save