Advertisement
Guest User

Untitled

a guest
May 28th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.72 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "stdlib.h" //en cas d'appels system
  3. #include "string.h" //en cas de chaînes
  4. #include "ctype.h" //pour toupper
  5.  
  6. struct Gus
  7. {
  8.     char *pnom;
  9.     int indv;
  10.     int dep;
  11.     char tel[13];
  12. };
  13. struct Ville
  14. {
  15.     char *pville;
  16.     int nbgus;
  17. };
  18.  
  19. void main()
  20. {
  21.     Gus *TG[50];
  22.     Ville *TV[50];
  23.     int nbp=0; //nombre de personnes
  24.     int nbv=0; //nombre de villes
  25.     char code;
  26.     char zl[16]; //zone de lecture pour nom, ville et tel
  27.     int Tind[50]; //Tableau d'indice
  28.     int i,j,c,ipp;
  29.     int RECHNOM(char[],Gus*[],int);
  30.     int RECHVIL(char[],Ville*[],int);
  31.     void LIBER(Ville*[],Gus*[],int,int);
  32.     printf("*****************************************\n\n");
  33.     printf("* REPERTOIRE TELEPHONIQUE METROPOLITAIN *\n\n");
  34.     printf("*****************************************\n\n");
  35.     printf("VEUILLEZ SAISIR UN CODE EVENEMENT :\n\n");
  36.     printf("I - INSCRIPTION D'UNE PERSONNE\n");
  37.     printf("S - SUPPRESSION D'UNE PERSONNE\n");
  38.     printf("C - CONSULTATION CONCERNANT UNE PERSONNE\n");
  39.     printf("V - VISUALISATION DES VILLES REFERENCEES\n");
  40.     printf("A - AFFICHAGE DU REPERTOIRE\n");
  41.     printf("Q - ARRET DU PROGRAMME\n");
  42.     fflush(stdin);
  43.     code=toupper(getchar());
  44.     system("cls");
  45.     while (code!='Q')
  46.     {
  47.         switch(code)
  48.         {
  49.             case 'I':
  50.                 printf("ENTREZ UN NOM :\n");
  51.                 fflush(stdin);
  52.                 gets(zl);
  53.                 for(i=0;i<strlen(zl);i++)
  54.                     zl[i]=toupper(zl[i]);
  55.                 i=RECHNOM(zl,TG,nbp);
  56.                 if(i==-1)   //nouveau
  57.                 {
  58.                     for(c=nbp-1;(c>=0)&&strcmp(zl,TG[c]->pnom)<0;c=c-1)
  59.                         TG[c+1]=TG[c];
  60.                     c+=1;
  61.                     TG[c]=(Gus*)malloc(sizeof(Gus));
  62.                     TG[c]->pnom=strdup(zl);
  63.                     printf("ENTREZ UNE VILLE :\n");
  64.                     fflush(stdin);
  65.                     gets(zl);
  66.                     for(i=0;i<strlen(zl);i++)
  67.                         zl[i]=toupper(zl[i]);
  68.                     j=RECHVIL(zl,TV,nbv);
  69.                     if(j==-1)
  70.                     {
  71.                         printf("\n- NOUVELLE VILLE -\n\n");
  72.                         TV[nbv]=(Ville*)malloc(sizeof(Ville));
  73.                         TV[nbv]->pville=strdup(zl);
  74.                         TV[nbv]->nbgus=1;
  75.                         TG[c]->indv=nbv;
  76.                         nbv++;
  77.                     }
  78.                     else
  79.                     {
  80.                         TV[j]->nbgus+=1;
  81.                         TG[c]->indv=j;
  82.                     }
  83.                     printf("ENTREZ UN DEPARTEMENT :\n");
  84.                     scanf("%d",&TG[c]->dep);
  85.                     printf("ENTREZ UN NUMERO DE TELEPHONE :\n");
  86.                     fflush(stdin);
  87.                     gets(zl);
  88.                     strcpy(TG[c]->tel,zl);
  89.                     printf("\n- INSCRIPTION EFFECTUEE -\n\n");
  90.                     nbp++;
  91.                 }
  92.                 else
  93.                 {
  94.                     printf("\n- NOM DEJA ENREGISTRE -\n\n");
  95.                 }
  96.                 system("pause");
  97.                 system("cls");
  98.                 break;
  99.             case 'S':
  100.                 printf("ENTREZ UN NOM :\n");
  101.                 fflush(stdin);
  102.                 gets(zl);
  103.                 for(i=0;i<strlen(zl);i++)
  104.                     zl[i]=toupper(zl[i]);
  105.                 i=RECHNOM(zl,TG,nbp);
  106.                 if(i==-1)
  107.                 {
  108.                     printf("\n- NOM INCONNU -\n\n");
  109.                     break;
  110.                 }
  111.                 TV[TG[i]->indv]->nbgus--;
  112.                 if(TV[TG[i]->indv]->nbgus==0)
  113.                     printf("\n- CETTE VILLE : %s NE SERA PLUS REFERENCEE -\n\n",TV[TG[i]->indv]->pville);
  114.                 free(TG[i]->pnom);
  115.                 free(TG[i]);
  116.                 while(i<nbp)
  117.                 {
  118.                     TG[i]=TG[i+1];
  119.                     i++;
  120.                 }
  121.                 printf("\n- SUPPRESSION EFFECTUEE : %s -\n\n",zl);
  122.                 nbp--;
  123.                 system("pause");
  124.                 system("cls");
  125.                 break;
  126.             case 'C':
  127.                 printf("ENTREZ UN NOM :\n");
  128.                 fflush(stdin);
  129.                 gets(zl);
  130.                 for(i=0;i<strlen(zl);i++)
  131.                     zl[i]=toupper(zl[i]);
  132.                 i=RECHNOM(zl,TG,nbp);
  133.                 if(i==-1)
  134.                 {
  135.                     printf("\n- NOM INCONNU -\n\n");
  136.                     break;
  137.                 }
  138.                 printf("\nNom : %s\nVille : %s\nDepartement : %d\nNumero de telephone : %s\n\n",TG[i]->pnom,TV[TG[i]->indv]->pville,TG[i]->dep,TG[i]->tel);
  139.                 system("pause");
  140.                 system("cls");
  141.                 break;
  142.             case 'V':
  143.                 if(nbp==0)
  144.                 {
  145.                     printf("\n- REPERTOIRE VIDE -\n\n");
  146.                     break;
  147.                 }
  148.                 for(c=0,j=0;j<nbv;j++)
  149.                 {
  150.                     if(TV[j]->nbgus>0)
  151.                     {
  152.                     Tind[c]=j;
  153.                     c++;
  154.                     }
  155.                 }
  156.                 for(i=0;i<c;i++)
  157.                 {
  158.                     for(ipp=i,j=i+1;j<c;j++)
  159.                     {
  160.                         if(strcmp(TV[Tind[j]]->pville,TV[Tind[ipp]]->pville)<0)
  161.                             ipp=j;
  162.                     }
  163.                     printf("\n%s avec %d personnes y residant\n\n",TV[Tind[ipp]]->pville,TV[Tind[ipp]]->nbgus);
  164.                     Tind[ipp]=Tind[i];
  165.                 }
  166.                 system("pause");
  167.                 system("cls");
  168.                 break;
  169.             case 'A':
  170.                 if(nbp==0)
  171.                 {
  172.                     printf("\n- REPERTOIRE VIDE -\n\n");
  173.                     break;
  174.                 }
  175.                 i=0;
  176.                 printf("NOM :      VILLE :         DEPARTEMENT :    NUMERO DE TELEPHONE :\n");
  177.                 printf("_________________________________________________________________\n");
  178.                 printf("- %c :\n",TG[i]->pnom[0]);
  179.                 printf("%-10s %-15s %-16d %-12s\n",TG[i]->pnom,TV[TG[i]->indv]->pville,TG[i]->dep,TG[i]->tel);
  180.                 for(i+=1;i<nbp;i++)
  181.                 {
  182.                     if(TG[i]->pnom[0]==TG[i-1]->pnom[0])
  183.                         printf("%-10s %-15s %-16d %-12s\n",TG[i]->pnom,TV[TG[i]->indv]->pville,TG[i]->dep,TG[i]->tel);
  184.                     else
  185.                     {
  186.                         printf("- %c :\n",TG[i]->pnom[0]);
  187.                         printf("%-10s %-15s %-16d %-12s\n",TG[i]->pnom,TV[TG[i]->indv]->pville,TG[i]->dep,TG[i]->tel);
  188.                     }
  189.                 }
  190.                 system("pause");
  191.                 system("cls");
  192.                 break;
  193.         }
  194.         printf("\nVEUILLEZ SAISIR UN CODE EVENEMENT :\n\n");
  195.         printf("I - INSCRIPTION D'UNE PERSONNE\n");
  196.         printf("S - SUPPRESSION D'UNE PERSONNE\n");
  197.         printf("C - CONSULTATION CONCERNANT UNE PERSONNE\n");
  198.         printf("V - VISUALISATION DES VILLES REFERENCEES\n");
  199.         printf("A - AFFICHAGE DU REPERTOIRE\n");
  200.         printf("Q - ARRET DU PROGRAMME\n");
  201.         fflush(stdin);
  202.         code=toupper(getchar());
  203.         system("cls");
  204.     }
  205.     LIBER(TV,TG,nbv,nbp);
  206. }
  207. int RECHNOM(char nom[],Gus *TG[],int nbp)
  208. {
  209.     int i;
  210.     for(i=0;i<nbp;i++)
  211.     {
  212.         if(strcmp(nom,TG[i]->pnom)==0)
  213.             return i;
  214.     }
  215.     return -1;
  216. }
  217.  
  218. int RECHVIL(char ville[],Ville *TV[],int nbv)
  219. {
  220.     int j;
  221.     for(j=0;j<nbv;j++)
  222.     {
  223.         if(strcmp(ville,TV[j]->pville)==0)
  224.             return j;
  225.     }
  226.     return -1;
  227. }
  228. void LIBER(Ville *TV[],Gus *TG[],int nbv,int nbp)
  229. {
  230.     int i;
  231.     for(i=0;i<nbp;i++)
  232.     {
  233.         free(TG[i]->pnom);
  234.         free(TG[i]);
  235.     }
  236.     for(i=0;i<nbv;i++)
  237.     {
  238.         free(TV[i]->pville);
  239.         free(TV[i]);
  240.     }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement