bonjour ,
Enoncé :
ecrire un programme permettant de creer une bibliothèque avec le menu suivant:
1-ajouter un auteur avec ses livres ou sans livres
2-ajouter un livre à un auteur
3-supprimer un auteur s'il possède 0 livre
4-supprimer un livre
ce que j'ai fais
d'abord variables ; tableau et types
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 program test; uses wincrt; type book = record num_isbn:string[20]; title:string[20]; paru:integer; edition:string[20]; end; bookee = array[1..99]of book; cpt = array[1..99]of integer; type personne = record num_id:integer; nom:string[15]; prenom:string[15]; nation:string[20]; date_dec:integer; etat:string[20]; nbre_ouvr:integer; list_ouvr:bookee; end; fp=file of personne;
ensuite procedure pour ajouter
une autre procedure pour afficher
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 procedure add(var f:fp); var r,i,j,d,num,n:integer; begin //pour verification du fichier assign (f, 'E:\auteur.dat'); {$i-} reset (f); {$i+} if ioresult<>0 then rewrite(f); //debut writeln('how many of records'); readln(r); for i:=1 to r do begin num:=filesize(f); writeln(' Num ID',num); readln(author[i].num_id); writeln(' Name',num); readln(author[i].nom); writeln(' prenom',num); readln(author[i].prenom); writeln(' Nation',num); readln(author[i].nation); writeln('entrez le nombre d''oeuvres '); readln(n); author[i].nbre_ouvr:=0; for j:=1 to n do begin author[i].nbre_ouvr := author[i].nbre_ouvr + 1; writeln('# entrez le numero ID'); readln(author[i].list_ouvr[j].num_isbn); writeln(' entrez le titre'); readln(author[i].list_ouvr[j].title); writeln(' entrez l''annee de parution '); readln(author[i].list_ouvr[j].paru); writeln(' entrez le nom de la maison d''edition : '); readln(author[i].list_ouvr[j].edition); writeln;writeln; write(f,author[i]); end; end; close(f); end;
et pour ajouter un livre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 procedure see(var f:fp); var j:integer; isbn:string[20]; begin writeln('entrez le numero ISBN'); readln(isbn); assign (f, 'E:\auteur.dat'); reset(f); j:=1; while not (EOF(f)) do begin read(f,author[j]); if ( author[j].list_ouvr[j].num_isbn = isbn) then begin writeln(j,' .Name:', author[j].nom,'prenom :', author[j].prenom); writeln(' .Numero ISBN :', author[j].list_ouvr[j].num_isbn ,'LE TITRE :', author[j].list_ouvr[j].title); writeln('Nombre d''ouvrages : ',author[j].nbre_ouvr); inc(j); end; end; if j=1 then writeln('Aucun resultat '); close(f); end;
le soucis je ne comprend pas pourquoi quand j'affiche l'auteur après avoir ajouté une nouvelle oeuvre j'ai toujours pas le nombre correcte.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 procedure add_livre(var f:fp); var id,j,e:integer; d:longint; begin writeln('entrez le numero ID de l''auteur'); readln(id); assign (f, 'E:\auteur.dat'); reset(f); j:=1; while not (EOF(f)) do begin read(f,author[j]); if ( author[j].num_id = id) then begin author[j].nbre_ouvr := author[j].nbre_ouvr +1; e:= author[j].nbre_ouvr; writeln(' entrez le numero ID'); readln(author[j].list_ouvr[e].num_isbn); writeln(' entrez le titre'); readln(author[j].list_ouvr[e].title); writeln(' entrez l''annee de parution '); readln(author[j].list_ouvr[e].paru); writeln(' entrez le nom de la maison d''edition : '); readln(author[j].list_ouvr[e].edition); write(f,author[j]); inc(j); end; end; if j = 1 then writeln('Aucun resultat '); close(f); end;
si l'auteur a 5 oeuvres quand j'ajoute un oeuvre c'est toujours 5
programme complet dans un fichier text
program.txt
merci d'avance pour votre aide
Partager