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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int nbadh;
string Vrep;
const int nbmaxadh=4;
int adhsup,Vi,Vj;
struct Tabadh{
string Vnom,Vnum,Vrem;};
Tabadh tab[nbmaxadh];
void Menu()
{
cout<<"1 : Ajout d'un adhérent"<<endl;
cout<<"2 : Affichage d'un adhérent"<<endl;
cout<<"3 : Classer par ordre alphabetique la liste des adhérent"<<endl;
cout<<"4 : Suppression d'un adhérent identifié par son numéro"<<endl;
cout<<"5 : Sauvegarde de la liste"<<endl;
cout<<"6 : Charger la liste des noms"<<endl;
cout<<"0 : Quitter"<<endl;
cout<<"Entrez votre choix"<<endl;
}
//fonction somme
int Somme(int Vsom1)
{
Vsom1=Vsom1+1;
return Vsom1;
}
void AjoutAdh()
{
nbadh=0;
do
{
if (nbadh<nbmaxadh)
{
cout<<"Ajouter le nom de l'adhérent :"<<endl;
cin>>tab[nbadh].Vnom;
cout<<"Ajouter la référence du livre :"<<endl;
cin>>tab[nbadh].Vnum;
//calcul de la somme sans appel de fonction ou procedure
// nbadh = nbadh + 1;
//calcul et appel de la fonction somme
nbadh=Somme(nbadh);
cout<<"Il se trouve maintenant"" "<<nbadh<<" ""adhérent inscrit dans la bibliothéque"<<endl;
}
else
cout<<"Le tableau est plein!"<<endl;
cout<<"Voulez vous ajouter un autre adhérent ?'oui'/'non'"<<endl;
cin>>Vrep;
if(Vrep=="non")
{
cout<<"Fin de la saisie!"<<endl;
}
}
while(Vrep=="oui");
cout<<endl;
}
//Procédure pour afficher les adhérents
void AfficherAdh()
{
if(nbadh!=1)
{
for (Vi=1;Vi<nbadh;Vi++)
{
cout<<Vi<<" "<<tab[Vi].Vnom<<" "<<tab[Vi].Vnum<<endl;
}
}
else cout<<"Le tableau est vide!"<<endl;
cout<<endl;
}
//Procédure pour trier les adhérents
void TriAdh()
{
Tabadh Vrem;
do
{
for (Vi=1;Vi<nbadh-1;Vi++)
{
if(tab[Vi].Vnom>tab[Vi+1].Vnom)
{
Vrem.Vnom=tab[Vi+1].Vnom;
Vrem.Vnum=tab[Vi+1].Vnum;
tab[Vi+1].Vnom=tab[Vi].Vnom;
tab[Vi+1].Vnum=tab[Vi].Vnum;
tab[Vi].Vnom=Vrem.Vnom;
tab[Vi].Vnum=Vrem.Vnum;
}
}
}
while (Vrem.Vnom>tab[Vi].Vnom && Vi<=nbadh);
{
Vi++;
}
cout<<"Liste de la bibliothéque trié!!!"<<endl<<endl;
}
//Procédure pour supprimer un adhérent
void SupprimerAdh()
{
int adhsup;
cout<<"Numero de la personne à supprimer?"<<endl;
cin>>adhsup;
for(int Vi=1;Vi<=nbadh;Vi++)
{
if (adhsup==Vi)
{
for(int Vj=Vi;Vj<nbadh;Vj++)
{
cout<<"Le numero"<<Vi<<" : "<<tab[Vi].Vnom<<" a bien été supprimé!"<<endl;
tab[Vj].Vnom=tab[Vj+1].Vnom;
tab[Vj].Vnum=tab[Vj+1].Vnum;
}
nbadh=nbadh-1;
}
}
}
//Procédure pour sauvergarder les adhérents
void SauvegarderAdh()
{
//Ouverture du fichier
ofstream VFichier("Bibliothéque.txt");
//Si le fichier ne s'ouvre pas convenablement j'affiche un message d'erreur
//Si je saisie et enregistre les élèves
if (!VFichier.is_open())
cout<<"Impossible d'ouvrier le fichier en écriture!"<<endl;
//je saisie et enregistre les noms
else
{
//Ecriture dans le fichier
for (Vi=1;Vi<nbadh;Vi++)
{
VFichier<<tab[Vi].Vnom<<" "<<tab[Vi].Vnum<<endl;
}
}
cout<<"Sauvergarde réussi!"<<endl<<endl;
//Fermeture du fichier
VFichier.close();
}
// Procédure pour charger les adhérents
void ChargerAdh()
{
//Ouverture du fichier
ifstream VFichier("Bibliothéque.txt");
//Si le fichier ne s'ouvre pas convenablement j'affiche un message d'erreur
//Si je saisie et enregistre les élèves
if (!VFichier.is_open())
cout<<"Impossible d'ouvrier le fichier en écriture!"<<endl;
else
{
if (!VFichier.eof())
{
VFichier>>tab[Vi].Vnom>>tab[Vi].Vnum;
while(!VFichier.eof())
{
cout<< tab[Vi].Vnom<<" : "<<tab[Vi].Vnum<<endl;
VFichier>>tab[Vi].Vnom>>tab[Vi].Vnum;
}
cout<<endl;
}
else
cout<< "Le fichier est vide!"<<endl;
}
//Fermeture du fichier
VFichier.close();
}
int main()
{
int choix;
nbadh=1;
Menu();
cin>>choix;
while (choix!=0)
{
switch(choix)
{
case 1 :AjoutAdh();
break;
case 2 :AfficherAdh();
break;
case 3 :TriAdh();
break;
case 4 :SupprimerAdh();
break;
case 5 :SauvegarderAdh();
break;
case 6 :ChargerAdh();
break;
}
Menu();
cin>>choix;
}
return 0;
} |
Partager