LOVEGUN

APP 3 Esprit

Nov 14th, 2021 (edited)
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. typedef struct {
  4.     int jj;
  5.     int mm;
  6.     int aa;
  7. }date;
  8.  
  9. typedef struct {
  10.     char dest[16];
  11.     date d;
  12. }voy;
  13.  
  14. typedef struct {
  15.     int ident;
  16.     char nom [16];
  17.     char pre [16];
  18.     int nbrv;
  19.     voy v[16];
  20. }client;
  21.  
  22. void menu (){
  23.     printf ("1. Remplir un tableau de n clients");
  24.     printf ("\n2. Afficher le tableau des clients");
  25.     printf ("\n3. Trier les voyages des clients selon l'orde décroissant de la date");
  26.     printf ("\n4. Afficher le voyageur le plus fidèle");
  27.     printf ("\n5. Afficher la destination la plus demandée pour un voyageur sachant son identifiant");
  28.     printf ("\n6. Afficher le mois l'année avec le plus grand nombre de réservations\n");
  29. }
  30. void tri_bulle(client t[15],int i)
  31. {
  32.     int passage = 0;
  33.     int j,permut;
  34.     client temp [15];
  35.  
  36.     do {
  37.         permut = 0;
  38.         passage ++;
  39.         for (j=1;j<t[i].nbrv;j++) {
  40.                 printf ("%d",t[i].v[j].d.aa);
  41.             if (
  42.                 (t[i].v[j].d.aa<t[i].v[j+1].d.aa)||
  43.                 ((t[i].v[j].d.aa==t[i].v[j+1].d.aa) && (t[i].v[j].d.mm<t[i].v[j+1].d.mm))||
  44.                 ((t[i].v[j].d.aa==t[i].v[j+1].d.aa) && (t[i].v[j].d.mm==t[i].v[j+1].d.mm) && (t[i].v[j].d.jj<t[i].v[j+1].d.jj))
  45.                  )
  46.             {
  47.                 printf ("ahlaaaaaaaaaaaaaaaaaaa");
  48.                 permut = 1;
  49.                 temp[1].v[1] = t[i].v[j];
  50.                 t[i].v[j] = t[i].v[j+1];
  51.                 t[i].v[j+1] = temp[1].v[1];
  52.             }
  53.         }
  54.     }while (permut==1);
  55. }
  56. void affiche (int n1,client t[15])
  57. {
  58.     int i,j;
  59.     for (i=1;i<=n1;i++)
  60.     {
  61.         printf ("\n\n*****Cleint %d*****",i);
  62.         printf ("\nId: %d",t[i].ident);
  63.         printf ("\nNom: %s",t[i].nom);
  64.         printf ("\nPrenom: %s",t[i].pre);
  65.         printf ("\nNombre de voyages: %d",t[i].nbrv);
  66.         for (j=1;j<=t[i].nbrv;j++)
  67.         {
  68.             printf ("\n-Voyage %d",j);
  69.             printf ("\nDestination: %s",t[i].v[j].dest);
  70.             printf ("\nJour/Mois/Année: %d/%d/%d",t[i].v[j].d.jj,t[i].v[j].d.mm,t[i].v[j].d.aa);
  71.         }
  72.  
  73.     }
  74. }
  75. int main ()
  76. {
  77.     int n,n1,i,j,posmax,ide,r,rmax,pos,k;
  78.     client t[15];
  79.     int t1[30];
  80.     n1=0;
  81.     do{
  82.         printf ("\n\n *****************************************\n");
  83.  
  84.         menu ();
  85.         scanf ("%d",&n);
  86.         switch (n)
  87.         {
  88.             case 1:
  89.                 system("cls");
  90.                 printf ("Combien de clients voulez vous enregistrer?\n");
  91.  
  92.                 scanf ("%d",&n1);
  93.                 for (i=1;i<=n1;i++)
  94.                 {
  95.                     printf ("\nDonner l'id du client %d",n);
  96.                     scanf ("%d",&t[i].ident);
  97.                     printf ("\nDonner le nom du client %d",n);
  98.                     fflush(stdin);
  99.                     gets (t[i].nom);
  100.                     printf ("\nDonner le prénom du client %d",n);
  101.                     fflush(stdin);
  102.                     gets (t[i].pre);
  103.                     printf ("\nDonner le nombre de voyages du client %d",n);
  104.                     scanf ("%d",&t[i].nbrv);
  105.                     for (j=1;j<=t[i].nbrv;j++)
  106.                     {
  107.                         printf ("\nDonner une destination pour le voyage n°%d",j);
  108.                         fflush(stdin);
  109.                         gets (t[i].v[j].dest);
  110.                         printf ("\nDonner le jour du voyage n°%d",j);
  111.                         scanf ("%d",&t[i].v[j].d.jj);
  112.                         printf ("\nDonner le mois du voyage n°%d",j);
  113.                         scanf ("%d",&t[i].v[j].d.mm);
  114.                         printf ("\nDonner l'année du voyage n°%d",j);
  115.                         scanf ("%d",&t[i].v[j].d.aa);
  116.                     }
  117.                 }
  118.             break;
  119.             case 2:
  120.                 system ("cls");
  121.                 if (n1==0)
  122.                 {
  123.                     printf ("Remplir d'abords le tableau ");
  124.                     break;
  125.                 }else
  126.                 {
  127.                     affiche (n1,t);
  128.                 }
  129.                 break;
  130.             case 3:
  131.                 system ("cls");
  132.                 if (n1==0)
  133.                 {
  134.                     printf ("Remplir d'abords le tableau ");
  135.                     break;
  136.                 }else
  137.                 {
  138.                     for (i=1;i<=n1;i++)
  139.                     {
  140.                         tri_bulle(t,i);
  141.                     }
  142.                 }
  143.                 break;
  144.             case 4:
  145.                 system ("cls");
  146.                 if (n1==0)
  147.                 {
  148.                     printf ("Remplir d'abords le tableau ");
  149.                     break;
  150.                 }else
  151.                 {
  152.                     posmax=1;
  153.                     for (i=2;i<=n1;i++)
  154.                         if (t[posmax].nbrv<t[i].nbrv)
  155.                         {
  156.                             posmax=i;
  157.                         }
  158.                     printf ("Le client le plus fidèle est le client %d",posmax);
  159.                 }
  160.                 break;
  161.             case 5:
  162.                 if (n1==0)
  163.                 {
  164.                     printf ("Remplir d'abords le tableau ");
  165.                     break;
  166.                 }else
  167.                 {
  168.                     printf ("Donner un identifiant");
  169.                     scanf ("%d",&ide);
  170.                     for (i=1;i<=n1 && t[i].ident != i;i++)
  171.                         if (t[i].ident==ide)
  172.                             break;
  173.                     posmax=1;
  174.                     rmax=1;
  175.                     for (j=1;j<=t[i].nbrv;j++)
  176.                     {
  177.                         r=0;
  178.                         for (k=j;k<=t[i].nbrv;k++)
  179.                         {
  180.                             if(strcmp(t[i].v[j].dest,t[i].v[k].dest)==0)
  181.                             {
  182.                                 r++;
  183.                             }
  184.                         }
  185.                         if (r>rmax)
  186.                         {
  187.                             rmax=r;
  188.                             posmax=j;
  189.                         }
  190.                     }
  191.                     printf ("La position la plus demandé est %s",t[i].v[posmax].dest);
  192.                 }
  193.                 break;
  194.             case 6:
  195.                 system ("cls");
  196.                 if (n1==0)
  197.                 {
  198.                     printf ("Remplir d'abords le tableau ");
  199.                     break;
  200.                 }else
  201.                 {
  202.                     for (i=1;i<=12;i++)
  203.                     {
  204.                         t1[i]=0;
  205.                     }
  206.                     for (i=1;i<=n1;i++)
  207.                     {
  208.                         for (j=1;j<=t[i].nbrv;j++)
  209.                         {
  210.                             t1[t[i].v[j].d.mm]++;
  211.                         }
  212.                     }
  213.                     posmax=1;
  214.                     for (i=1;i<=12;i++)
  215.                     {
  216.                         if (t1[posmax]<t1[i])
  217.                         {
  218.                             posmax=i;
  219.                         }
  220.                     }
  221.                     printf ("Le mois le plus demandée de l'année est le mois %d",posmax);
  222.                 }
  223.  
  224.                 break;
  225.         }
  226.     }while (n>=1 && n<=6);
  227. }
  228.  
  229.  
  230.  
  231. /*t[1].ident=1111; t[2].ident=2222;
  232.             strcpy(t[1].nom,"Momo");  strcpy(t[2].nom,"Yasmine");
  233.             strcpy(t[1].pre,"ahla");  strcpy(t[2].pre,"test");
  234.             t[1].nbrv=3; t[2].nbrv=2;
  235.             strcpy( t[1].v[1].dest,"Toulouse");  strcpy(t[2].v[1].dest,"Lyon");
  236.             strcpy( t[1].v[2].dest,"Marseille");  strcpy( t[2].v[2].dest,"Toulouse");
  237.             strcpy( t[1].v[3].dest,"Marseille");
  238.             t[1].v[1].d.jj=23; t[2].v[1].d.jj=23;
  239.             t[1].v[1].d.mm=12;   t[2].v[1].d.mm=5;
  240.             t[1].v[1].d.aa=2020; t[2].v[1].d.aa=2021;
  241.             t[1].v[2].d.jj=24; t[2].v[2].d.jj=24;
  242.             t[1].v[2].d.mm=5; t[2].v[2].d.mm=5;
  243.             t[1].v[2].d.aa=2020; t[2].v[2].d.aa=2020;
  244.             t[1].v[3].d.jj=23;
  245.             t[1].v[3].d.mm=12;
  246.             t[1].v[3].d.aa=2021;
  247.             t[2].v[3].d.jj=23;
  248.             t[2].v[3].d.mm=12;
  249.             t[2].v[3].d.aa=2021;*/
  250.  
Add Comment
Please, Sign In to add comment