structure compte { numéro: entier nom: chaîne de 20 caractères adresse: chaîne de 100 caractères solde: réel } fonction saisirCompte(): compte { c: compte Répéter Afficher("Entrez le numéro du compte :") Saisir(c.numéro) jusqu'à (c.numéro > 0) Répéter Afficher("Entrez le nom :") Saisir(c.nom) jusqu'à (c.nom != "") Répéter Afficher("Entrez l'adresse :") Saisir(c.adresse) jusqu'à (c.adresse != "") afficher("Entrez le solde :") saisir(c.solde) retourner c } Algorithme Clearstream { variable c : compte f : Fichier i : entier constante chaine nomfichier <-- "comptes.dat" constante entier N <-- 100 Créer(nomfichier,f) Ouvrir(f,écriture) Pour i allant de 1 à N { c <-- saisirCompte() Ecrire(f,c) } Fermer(f) } procedure ajouterCompte(E fc :Fichier) { variable c : compte Decaler(fc,Fin_Fichier,0) c <-- saisirCompte() Ecrire(fc,c) } procedure ajouterCompte2(E fc :Fichier) { variable c : compte Tantque ( NON(Fin(fc))) // Permet aussi de se positionner a la fin { Lire(fc,c) } c <-- saisirCompte() Ecrire(fc,c) } fonction afficherComptes(E fc : Fichier) : entier { variable c : compte nb : entier nb <-- 0 Decaler(fc, debut_fichier, 0) Tantque ( NON(Fin(fc))) { Lire(fc,c) AfficherCompte(c) nb<-- nb+1 //Afficher(c.numero, " : ", c.nom, " :", c.adresse," :", c.solde, "euros\n") // on ne pouvait pas faire // Afficher(c) } retourner nb } procedure AfficherCompte(E c :compte) { Afficher(c.numero, " : ", c.nom, " :", c.adresse," :", c.solde, "euros\n") } procedure trierComptes(E fc :Fichier) { constante entier MAX <-- 100 variable t : tableau de MAX compte nb : entier tmp, cmin :compte i,j,imin :entier nb <-- 0 Decaler(fc, debut_fichier, 0) // on remplit le tableau Tantque ( NON(Fin(fc))) { Lire(fc,t[nb]) nb<-- nb+1 } // on trie Pour j allant de 0 à nb-2 { cmin <-- t[j] imin <-- j Pour i allant de j+1 à nb-1 { Si (cmin.solde > t[i].solde) alors { cmin <-- t[i] imin <-- i } } Si (imin != j)alors { tmp <-- t[imin] t[imin] <-- t[j] t[j] <-- tmp } } Pour j allant de 0 à nb-1 { AfficherCompte(t[j]) } } procedure majCompte(E numero : entier, E f: Fichier) { variable c : compte trouve : booleen reponse : entier trouve <-- FAUX; Decaler(f, debut_fichier, 0) Tantque (NON (Fin(f)) && NON(trouve)) { Lire(f,c) Si (c.numero=numero) alors { trouve <-- VRAI } } Si (trouve) alors // equivalent à ecrire "Si (trouve = VRAI) alors" { Repeter { Afficher("1: Mettre à jour le solde\n") Afficher("2: Mettre à jour l'adresse\n") Afficher("0: Fin des mises à jour\n") Saisir(reponse) Selon (reponse) { 0: Afficher("Vous avez fini les mises à jour \n") 1 : Afficher("Le solde courant est de ", c.solde, "\n") Afficher("Veuillez saisir le nouveau solde") Saisir(c.solde) 2: Afficher("L'adresse actuelle est ", c.adresse, "\n") Afficher("Veuillez saisir la nouvelle adresse") Saisir(c.adresse) sinon : Afficher("Vous vous êtes trompé dans votre choix\n") } } jusqu'à (reponse = 0) Decaler(f, Position_courante, -1) Ecrire(f,c) } } Algorithme HSBC { variable f : Fichier reponse,nb,num : entier constante chaine nomfichier <-- "comptes.dat" Designer(nomfichier,f) Ouvrir(f,Lecture/Ecrire) Repeter { Afficher("0: Pour sortir\n") Afficher("1: Pour ajouter un compte\n") Afficher("2: Pour afficher les comptes\n") Afficher("3: Pour trier les comptes\n") Afficher("4: Pour mettre à jour un compte\n") Saisir(reponse) Selon (reponse) { 0: Afficher("Au revoir !\n") 1: ajouterCompte(f) 2: nb <-- afficherComptes(f) Afficher("Il y a ", nb, "comptes dans le fichier\n") 3: trierComptes(f) 4: Afficher("Veuillez saisir le numero du compte à mettre à jour\n") Saisir(num) majCompte(num,f) sinon : Afficher("Vous vous êtes trompé dans votre choix\n") } } jusqu'à (reponse = 0) Fermer(f) }