1 / 18

TP : Fichiers et Tableaux

TP : Fichiers et Tableaux. Séance N°2 Avril 2012. Application de Gestion de stock Partie 1 : les fichiers. Révisons ,,,. 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;

shea
Télécharger la présentation

TP : Fichiers et Tableaux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TP : Fichiers et Tableaux Séance N°2 Avril 2012

  2. Application de Gestion de stockPartie 1 : les fichiers

  3. Révisons ,,,

  4. 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;

  5. Begin • Clrscr; • Assign (F,‘stock.dat’);

  6. rewrite(F); For i:=1 to 20do 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;

  7. 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); whilenot eof(F) do begin read(F, art); writeln(art.ref); end;

  8. close(F); • Readkey; • end.

  9. Application de Gestion de stockPartie 1 : les fichiers

  10. Taille d’un fichier = nombre d’enregistrements Filesize (nom_logique);

  11. 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’enregistrement 1er enregistrement Dernier enregistrement

  12. 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;

  13. Application de Gestion de stockPartie 1 : les fichiers

  14. 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.

  15. 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);

  16. Fin première partie,,, Evaluation next-Time !

  17. Seek (F,1) ; Read(F, art); Art.etat := false; Write (F, art);

  18. Exercice • Supprimer le premier article • Récupérer le deuxième • Afficher les références de tous les articles

More Related