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
|
// Repertoire.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
struct pers //declaration de la structure repertoire
{
char *pnom; //nom dans le repertoire
char tel[13]; // n° de tel
int dpt; // n° departement
int indv; //indice de la ville
};
struct ville //declaration de la structure ville
{
char *pville; //nom de la ville
int occ; //nombre d'occurence d'une ville
};
void main()
{
pers *tp[50];
ville *tv[50];
int tabc[50]; // tableau d'indice servant au tri alphabetique des noms de ville.
int n=0; // nombre de nom
int v=0; // nombre de ville
int i,r,t,rep; // rep (0:nouveau;1= trouvé)
int rechnom(char[],pers *[],int,int *);
int creer(char[],pers *[],int,int,int);
void affcode();
void affrep(int,pers *[],ville *[]);
void menage(pers *[],ville *[],int,int);
char zl[11]; // zone de lecture
char zlv[16];
char code;
system ("cls"); // nettoie l ecran
printf ("\n*****************************************\n\n");
printf ("* REPERTOIRE TELEPHONIQUE METROPOLITAIN *\n\n");
printf ("*****************************************\n\n\n");
affcode();
code=getchar();
while(code != 'q' && code != 'Q')
{
switch(code)
{
case'i':
case'I':
{
system ("cls");
printf("\nVeuillez saisir le nom: \n");
fflush(stdin);
gets(zl);
r= rechnom(zl,tp,n,&rep);
if (rep==0)
{
printf("\nVeuillez saisir la ville: \n");
gets(zlv);
int rechville(char[],ville *[],int);
t= rechville(zlv,tv,v);
if (t!=-1)
{
tv[t]=(ville *)malloc(sizeof(ville));
tv[t]->pville=strdup(zlv);
tv[t]->occ=1;
v++;
}
n = creer (zl,tp,n,r,t);
if (tv[t]->occ==1)
{
printf("\nNOUVELLE VILLE : %-15s\n",tv[t]->pville);
}
}
else
{
//fflush(stdin);
/*system("cls");
printf("\n NOM DEJA ENREGISTRE\n");*/
}
}
break;
case'a':
case'A':
{
system ("cls");
affrep(n,tp,tv);
}
fflush(stdin);
break;
}
affcode();
code=getchar();
}
menage(tp,tv,n,v);
}
int rechnom(char zl[],pers *tp[],int n,int *rep) //Fonction RECHNOM
{
int i;
int comp = 1;
for(i=0;i<n&&(comp = strcmp(zl,tp[i]->pnom))>0;i++)
if (comp==0)
*rep = 1;
else
*rep = 0;
printf("%d\n",*rep);
printf("%d\n",i);
printf("%d\n",n);
printf("%d\n",comp);
printf("%s\n",zl);
return (i);
}
int creer (char zl[],pers *tp[],int n,int r,int t)
{
void inserer (pers *,pers *[],int,int);
pers *per;
char zlt[12];
per=(pers*)malloc(sizeof(pers));
per->pnom=strdup(zl);
per->indv=t;
printf("\nVeuillez saisir le department: \n");
fflush(stdin);
scanf("%d",&per->dpt);
printf("\nVeuillez saisir le numero de telephone: \n");
gets(zlt);
strcpy(per->tel,zlt);
inserer (per,tp,n,r);
system ("cls");
printf("\nINSCRIPTION EFFECTUEE : %-10s\n",per->pnom);
return(n+1);
}
int rechville(char zlv[],ville *tv[],int v) //Fonction RECHVILLE
{
int i;
for (i=0;i<v && strcmp(zlv,tv[i]->pville)!=0;i++);
if (i<v)
{//trouvé
tv[i]->occ++;
return(-1);
}
return (i);
}
void affcode()
{
printf ("\n\nI - Inscription d'une personne\n\n");
printf ("S - Suppression d'une personne\n\n");
printf ("C - Consultation concernant une personne\n\n");
printf ("V - Visualisation des villes referencees\n\n");
printf ("A - Affichage du repertoire\n\n");
printf ("Q - Arret du progamme\n\n\n\n\n");
printf ("VEUILLEZ SAISIR LA LETTRE CORRESPONDANT\n A L'EVENEMENT SOUHAITE ET CLIQUER SUR ENTRER: \n\n\n");
}
void inserer(pers *per,pers *tp[],int n,int r)
{
int i;
for (i=n;i>r;i--)
tp[i]=tp[i-1];
tp[i]=per;
}
void affrep(int n,pers *tp[],ville *tv[])
{
if(n!=0)
{
char lettre=tp[0]->pnom[0];
printf("%c :\n\n",lettre);
printf("\nnom : %-10s\n",tp[0]->pnom);
printf("ville : %-15s\n",tv[tp[0]->indv]->pville);
printf("departement : %d\n",tp[0]->dpt);
printf("numero de telephone : %-12s\n\n",tp[0]->tel);
int i;
for (i=1;i<n;i++)
{
if (lettre != tp[i]->pnom[0])
{
lettre=tp[i]->pnom[0];
printf("%c :\n\n",lettre);
}
printf("\nnom : %-10s\n",tp[i]->pnom);
printf("ville : %-15s\n",tv[tp[i]->indv]->pville);
printf("departement : %d\n",tp[i]->dpt);
printf("numero de telephone : %-12s\n",tp[i]->tel);
}
}
else
{
printf("\n\n LE REPERTOIRE EST VIDE \n\n");
}
}
void menage(pers *tp[],ville *tv[],int n,int v)
{
int i;
for (i=0;i<n;i++)
{
free (tp[i]->pnom);
free (tp[i]);
}
for (i=0;i<v;i++)
{
free (tv[i]->pville);
free (tv[i]);
}
} |
Partager