Support Forums

Full Version: help in program in pascal please
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wrote the program language Pascal, stores information students (record) and save it in the file .and requested that the file is not open only from within the program think of type (.dat or .pas) I do not know, this first problem .. The program contains procedures for adding and scanning, display and other... the problem, that the program works, but procedure of display(afficher) and deletions do not work and did not know where is the problem???
Code:
[b][size=medium]program TP02 ;
uses crt;
type
student= Record
nb : integer ;
nom : string[20];
pnom :string[20];
date:string[10];
ville:string[20];
moy:0..20;

end ;
var
f: file of student ;
stud : student;
c: integer;
                          { creĆ©r new file procedure 1}
Procedure creer;
begin
assign(f,'students.dat');
rewrite(f);
end;                                    { ajouter new student procedure 2}
Procedure rempler(var stud : student);
var i,n : integer;
begin
assign(f,'students.dat');
rewrite(f);
write('svp!.entrez le nombres des etudiants vou voulez ajoutee:');
readln(n);
for i:= 1 to n Do
begin
write('entrez le numero de etudiant ',i,':');readln(stud.nb);
write('entrez le nom de etudiant ',i,':');readln(stud.nom);
write('entrez le prenom de etudiant ',i,':');readln(stud.pnom);
write('entrez la date de naissance de etudiant ',i,':');readln(stud.date);
write('entrez le lieu de naiss de etudiant ',i,':');readln(stud.ville);
write('entrez la note de etudiant ',i,':');readln(stud.moy);
write(f,stud);
end;
close(f);
end;
                         {procedure 3 chercer for student }
Procedure recherche(var stud : student);
var
s,a:integer;
b:string;
t:boolean;
begin
write('vous voulez recherchez par numero(1) ou par nom(2)? 1 ou 2 :');
readln(s);
reset(f);
t:= true;
if s=1 then
begin
write('entrez le numero :');readln(a);
while not eof(f) and t=true DO
begin
read(f,stud);
if stud.nb =a then t:= false ;

end;
if t=false then
begin
writeln ('le numero de etudiqnt est;',stud.nb);
writeln ('le numero de etudiqnt est;',stud.nom);
writeln ('le numero de etudiqnt est;',stud.pnom);
writeln ('le numero de etudiqnt est;',stud.date);
writeln ('le numero de etudiqnt est;',stud.ville);
writeln ('le numero de etudiqnt est;',stud.moy);
end
else writeln('le numero il n''existe pqs !!');
end
else
begin
write('entrez le num :');readln(b);
while not eof(f) and t=true DO
begin
read(f,stud);
if stud.nom =b then t:= false ;
end;
if t=false then
begin
writeln ('le numero de etudiqnt est;',stud.nb);
writeln ('le numero de etudiqnt est;',stud.nom);
writeln ('le numero de etudiqnt est;',stud.pnom);
writeln ('le numero de etudiqnt est;',stud.date);
writeln ('le numero de etudiqnt est;',stud.ville);
writeln ('le numero de etudiqnt est;',stud.moy);
end
else writeln('le numero il n''existe pas !!');
end;
close(f);
end;
Procedure suprimer(var stud : student);     { supprimer student procedure 4}
var
s,a,r:integer;
b:string;
t:boolean;
begin
write('vous voulez suprimez par numero(1) ou par nom(2)? 1 ou 2 :');
readln(s);
rewrite(f);
t:= true;
r:=0;
if s=1 then
begin
write('entrez le numero :');readln(a);
while not eof(f) and t=true DO
begin
read(f,stud);
r:=r+1;
if stud.nb =a then t:= false ;

end;
if t=false then
begin
seek(f,r);
Truncate(f);
writeln ('le numero de etudiqnt est suprimee');
end
else writeln('le numero il n''existe pqs !!');
end
else
begin
write('entrez le num :');readln(b);
while not eof(f) and t=true DO
begin
read(f,stud);
r:=r+1;
if stud.nom =b then t:= false ;
end;
if t=false then
begin
seek(f,r);
Truncate(f);
writeln ('le numero de etudiqnt est suprimee');
end
else writeln('le numero il n''existe pas !!');
end;
close(f);
end;
                           {procedure 5  afficher l'information of students}
Procedure afficher(var stud : student);
begin
assign(f,'fille.dat');
reset(f);
while not eof(f) do
begin
read(f,stud);
write (stud.nb);
write (stud.nom);
write (stud.pnom);
write (stud.date);
write (stud.ville);
write (stud.moy);
end;
close(f);
end;

               {program principale}
begin
clrscr ;
assign(f,'fille.dat');
rewrite(f);
repeat
begin
writeln('1\creer');
writeln('2\rempler');
writeln('3\recherche');
writeln('4\suprimer');
writeln('5\afficher');
writeln('0\creer');
writeln('entrew votre choix:');readln(c);
case c of
1 : creer;
2 : rempler (stud);
3 : recherche(stud);
4 : suprimer (stud);
5 : afficher(stud);
end;
end ;
UNTIL c=0;
end.[/size][/b]
I've never even heard of this language before?! I'm going to learn about this now on google. :p