tp : fichiers et tableaux séance n°2 avril 2012. application de gestion de stock partie 1 : les...
TRANSCRIPT
![Page 1: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/1.jpg)
TP : Fichiers et TableauxSéance N°2
Avril 2012
![Page 2: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/2.jpg)
Application de Gestion de stockPartie 1 : les fichiers
1
Création d’un fichier de 20 articles
![Page 3: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/3.jpg)
Révisons ,,,
![Page 4: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/4.jpg)
Program TP;uses CRT;
Type
Article = record Ref: Byte;Etat: boolean;Nom : string[20];qte: Byte;Stck_min: Byte;Prix_uni: Word;Prix_total: Word;
end;
Var F: file of article;
![Page 5: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/5.jpg)
Begin
Clrscr;
Assign (F,‘stock.dat’);
![Page 6: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/6.jpg)
rewrite(F); For i:=1 to 20 do Begin
Readln (art.Ref);art.etat := True ;Readln (art.nom);
Readln (art.qte);
Readln (art.Stck_min);
Readln (art.Prix_uni);
Readln (art.Prix_total);
Write(F , art); End;
![Page 7: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/7.jpg)
Seek(F,0); Read(F, art); art.Etat:= false; write(F,art);
Seek(F,1); Read(F, art); art.Etat:= True; write(F,art);
reset (F);while not eof(F) do
begin read(F, art); writeln(art.ref);
end;
![Page 8: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/8.jpg)
close(F); Readkey; end.
![Page 9: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/9.jpg)
Application de Gestion de stockPartie 1 : les fichiers
1
Création d’un fichier de 20 articles
2
Ajout de trois articles à la fin du fichier
![Page 10: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/10.jpg)
Taille d’un fichier = nombre d’enregistrements
Filesize (nom_logique);
![Page 11: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/11.jpg)
Accès direct à un enregistrement dans un fichier
Seek (nom_logique, expression_entière)
Exemples:
Seek(F, 0)
Seek(F, FileSize(F)-1)
Numéro d’enregistremen
t 1er
enregistrement
Dernier enregistrement
![Page 12: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/12.jpg)
Seek(F, FileSize(F));
For i:=1 to 3 do Begin
Readln(art.Ref);art.etat := True;Readln(art.nom);
Readln(art.qte);
Readln(art.Stck_min);
Readln(art.Prix_uni);
Readln(art.Prix_total);
Write(F , art); End;
![Page 13: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/13.jpg)
Application de Gestion de stockPartie 1 : les fichiers
1
Création d’un fichier de 20 articles
2
Ajout de trois articles à la fin du fichier
3
Suppression du deuxième article
![Page 14: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/14.jpg)
Suppression d’un enregistrement
La suppression se fait logiquement (Cas1) et
physiquement (Cas2):
Cas1: Par l'utilisation d'un champ dédié (exemple
état (string) = '1' si présent ou '0' sinon)
Cas2: Par l'utilisation d'un fichier (de même
structure) pour copier les enregistrements de notre
fichier sauf celui à supprimer.
![Page 15: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/15.jpg)
Utilisons la première méthode Ajouter le champ Etat dans le record :
Etat: Boolean; Ajouter l’instruction suivante dans toutes les
opérations d’ajout:art.Etat:= True;
Ajouter à la fin du programme le bloc suivant:
Seek(F,1); Read(F, art); art.Etat:= True; write(F,art);
![Page 16: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/16.jpg)
Fin première partie,,,
Evaluation next-Time !
![Page 17: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/17.jpg)
Seek (F,1) ; Read(F, art);Art.etat := false;Write (F, art);
![Page 18: TP : Fichiers et Tableaux Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers 1 Création dun fichier de 20 articles](https://reader036.vdocuments.fr/reader036/viewer/2022082806/551d9da2497959293b8d2dad/html5/thumbnails/18.jpg)
Exercice
Supprimer le premier article Récupérer le deuxième Afficher les références de tous les
articles