Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.13 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7.  
  8. void main()
  9. {
  10. int choix,j,i,x, nb,g,test,nbamis,nbfamille,nbcollegue,position, r,choix2,ooredoo,telecom,orange,maxop,indice,abonnee,unique,count,conti,o,autre,nbnum,k;
  11. long tab [100], numerosupprime;
  12. char matrice [100][30], personne[28],aux[28],nouvellecat;
  13. char* nom ;
  14.  
  15.  
  16. printf("MENU:\n");
  17. printf("1- remplir le repertoire\n");
  18. printf("2- afficher le repertoire trie par ordre alphabetique\n");
  19. printf("3-rechercher un contact\n");
  20. printf("4-supprimer un contact\n");
  21. printf("5-afficher le nombre de contact par categorie\n");
  22. printf("6-afficher la liste d'amis et leur nombre par operateur telephonique\n");
  23. printf("7-afficher l'operateur telephonique ayant le max d'abonnés et leur nombre\n");
  24. printf("8-les noms de personnes ayant plus qu'un numero de telephone\n");
  25. printf("9-quitter\n");
  26. do
  27. {
  28.  
  29.  
  30. do
  31. {
  32. printf("choisir un numero de 1 a 9: ");
  33. scanf("%i",&choix);
  34. } while ((choix <1)||(choix>9));
  35.  
  36.  
  37.  
  38. switch(choix)
  39. {
  40. case 1: printf (" REMPLISSAGE DU REPERTOIRE \n");
  41. printf("saisir le nombre des numeros a saisir dans la repertoire: ");
  42. scanf("%d",&nb ) ;
  43.  
  44. for(i=0;i<nb;i++)
  45. {
  46.  
  47.  
  48. do {
  49.  
  50. printf("saisir un numero de telephone ");
  51. scanf("%li",&tab[i]);
  52.  
  53. x=tab[i]/pow(10,7);
  54. unique=0;
  55. for (o=0;o<=i-1;o++)
  56. {
  57. if (tab[o]==tab[i])
  58. unique=1;
  59. }
  60. } while(( (x!= 2) && (x!= 5) && (x != 9))||(unique!=0));
  61.  
  62.  
  63. do{
  64. printf("saisir son nom ");
  65. getchar() ;
  66. gets(matrice[i]);
  67.  
  68. } while (strlen(matrice[i])>28);
  69.  
  70.  
  71. do {
  72. printf("saisir son categorie ");
  73. scanf("%c",&matrice[i][29]) ;
  74. fflush(stdin);
  75.  
  76.  
  77. } while (( toupper(matrice[i][29])!='A') && ( toupper(matrice[i][29])!='F')&& ( toupper(matrice [i][29])!= 'C'));
  78.  
  79. }
  80. break;
  81. case 2:
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. do
  89. { conti=1;
  90. for (i=0; i<nb-1; i++ )
  91. {
  92. if ( strcmpi(matrice[i],matrice[i+1])>0 )
  93. {
  94. strcpy (aux,matrice[i]) ;
  95. strcpy (matrice[i], matrice[i+1]);
  96. strcpy (matrice[i+1], aux) ;
  97.  
  98. nouvellecat=matrice [i][29] ;
  99. matrice [i][29]=matrice [i+1][29];
  100. matrice [i+1][29]=nouvellecat ;
  101.  
  102. autre=tab[i];
  103. tab[i]=tab[i+1] ;
  104. tab[i+1]=autre ;
  105. conti=0;
  106. }
  107. }
  108. }while (conti==0);
  109. printf(" le nouveau repertoire trie est : \n ");
  110. for (i=0;i<nb;i++)
  111. { printf("%s\n",matrice[i]);
  112. printf ("%li\n",tab[i]);
  113. printf ("%c\n ",matrice[i][29]) ;
  114. }
  115.  
  116.  
  117.  
  118. break;
  119.  
  120. case 3:
  121. printf(" RECHERCHE D'UNE PERSONNE DANS CE REPERTOIRE \n");
  122. printf("donner le nom du personne a chercher\n");
  123. scanf("%s",personne);
  124.  
  125. test=0;
  126. for(k=0;k<28;k++)
  127.  
  128. { if(strncmp(personne,matrice[k],28)==0)
  129. {test=1;
  130. printf("cette personne est enregistree sous le numero: %li\n",tab[k]);
  131. }
  132. }
  133.  
  134. if (test==0)
  135. printf("-1\n");
  136. break;
  137. case 4:
  138. printf (" SUPPRESSION D'UN CONTACT \n");
  139. printf("donner le numero a supprimer ");
  140. scanf("%li",&numerosupprime);
  141. i=0;
  142. r=0;
  143. printf("------verification de l'existence de ce num dans le repertoire------\n");
  144. do
  145. {
  146. if (tab[i]==numerosupprime)
  147. {
  148.  
  149. printf("oui, existe\n");
  150. position=i;
  151. r=1;
  152. }
  153. else
  154. i++;
  155.  
  156. } while ((i<=nb)&&(r!=1));
  157.  
  158. if (r==0) printf("non,n'exsite pas\n");
  159.  
  160. printf("tapez 0 si vous voulez voir le nouvel repertoire: ");
  161. scanf("%i",&choix2);
  162. do{
  163. if (r==1)
  164. { for (i=position;i<nb-1;i++)
  165. {tab[i]=tab[i+1];
  166. strcpy(matrice[i],matrice[i+1]);
  167. }
  168. nb--;
  169. }
  170. printf("le nouvel repertoire est : \n");
  171.  
  172. for (i=0;i<nb;i++)
  173. {printf ("%li\n",tab[i]);
  174. printf("%s\n",matrice[i]);
  175. fflush (stdin) ;
  176. printf ("%c\n ",matrice[i][29]) ;
  177. }
  178.  
  179.  
  180. } while (choix2!=0);
  181.  
  182. break;
  183.  
  184. case 5:
  185.  
  186. nbfamille=0;
  187. nbcollegue=0;
  188. nbamis=0;
  189. printf(" LE NOMBRE DE CONTACTS PAR CATEGORIE \n");
  190. for (i=0;i<nb;i++)
  191. {
  192. if (toupper(matrice[i][29])=='A')
  193. nbamis++;
  194. else if (toupper(matrice[i][29])=='F')
  195. nbfamille++ ;
  196.  
  197. else nbcollegue++ ;
  198.  
  199.  
  200. }
  201. printf(" - Amis: %i \n",nbamis);
  202. printf(" - Membres de la famille : %i \n",nbfamille);
  203. printf(" - collegues: %i \n",nbcollegue);
  204.  
  205.  
  206. break;
  207.  
  208. case 6:
  209. printf(" LA LISTE D'AMIS ET LEUR NOMBRE PAR OPERATEUR \n");
  210. ooredoo=0;
  211. telecom=0;
  212. orange=0;
  213. for (i=0;i<nb;i++)
  214. {
  215. if (toupper(matrice[i][29])=='A')
  216.  
  217. {
  218. x=tab[i]/pow(10,7);
  219.  
  220. if (x==2)
  221. ooredoo++;
  222. else if (x==9)
  223. telecom++;
  224. else orange++;
  225. }
  226. }
  227. printf("le nbre des numeros ooredoo : ");
  228. printf("%i\n",ooredoo);
  229.  
  230. for (i=0;i<nb;i++)
  231. {x=tab[i]/pow(10,7);
  232.  
  233. if ((x==2)&&(toupper(matrice[i][29])=='A'))
  234. {
  235. printf("%s\n",matrice[i]);
  236. printf("%li\n",tab[i]);
  237. }
  238. }
  239. printf("Le nbre des numeros telecom : ");
  240. printf("%i\n",telecom);
  241.  
  242. for (i=0;i<nb;i++)
  243. { x=tab[i]/pow(10,7);
  244.  
  245. if ((x==9)&&(toupper(matrice[i][29])=='A'))
  246. {
  247. printf("%s\n",matrice[i]);
  248. printf("%li\n",tab[i]);
  249. }
  250. }
  251.  
  252. printf("le nbre des numeros orange : ");
  253. printf("%i\n",orange);
  254. for (i=0;i<nb;i++)
  255. {x=tab[i]/pow(10,7);
  256.  
  257. if ((x==5)&&(toupper(matrice[i][29])=='A'))
  258. {
  259. printf("%s\n",matrice[i]);
  260. printf("%li\n",tab[i]);
  261. }
  262. }
  263. break;
  264. case 7:
  265. printf(" L 'OPERATEUR TELEPHONIQUE AYANT LE MAX D'ABONNEES EST : \n");
  266. ooredoo=0;
  267. telecom=0;
  268. orange=0;
  269. for (i=0;i<nb;i++)
  270. { x=tab[i]/pow(10,7);
  271. if (x==2)
  272. ooredoo++;
  273. else if (x==9)
  274. telecom++;
  275. else orange++;
  276. }
  277. if ((ooredoo==telecom)&&(telecom==orange))
  278. printf("tous les operateurs ont le meme nbre d'abonnees\n ");
  279. else
  280. { maxop=ooredoo;
  281. if (telecom>maxop)
  282. { maxop=telecom;
  283. printf(" telecom avec %i abonnees\n ",telecom);}
  284. else
  285. if (orange>maxop)
  286. {maxop=orange;
  287. printf(" orange avec %i abonnees\n ",orange);}
  288. else printf(" ooredoo avec %i abonnees\n ",ooredoo);}
  289. break;
  290.  
  291. case 8:
  292.  
  293.  
  294. do {
  295. nom = matrice [i] ;
  296. g =i ;
  297. count=0;
  298. do
  299. {
  300. count ++;
  301. g++;
  302. } while ( strcmp ( matrice [ g ] , nom ) ) ;
  303. if ( count > 1 )
  304. printf("nom:% s, compte:% d" , nom ,count);
  305.  
  306. (i =i+g );
  307. } while ( i <nb );
  308. break ;
  309.  
  310. } while (choix!=9);
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement