Advertisement
iyed

Untitled

Oct 27th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct depot
  5. {
  6.     int id;
  7.     char ville[100];
  8.     char type[100];
  9.     int nrayons;
  10.     int rayonsfilled;
  11.     int ppr[500];
  12.     char responsable[100];
  13. };
  14. int main()
  15. {
  16.  
  17.     int n = 0;
  18.     struct depot depots[100];
  19.  
  20.     while(1)
  21.     {
  22.         printf("\n");
  23.         printf("Select one:\n");
  24.         printf("1-Add Depot:\n");
  25.         printf("2-Fill Rayon :\n");
  26.         printf("3-List depots of type :\n");
  27.         printf("4-Show best depot :\n");
  28.         printf("5-Change Admin :\n");
  29.         printf("6-Calc Depots in Ville :\n");
  30.         printf("7-Depot seuil ect :\n");
  31.         printf("8-Delete first empty :\n");
  32.         printf("Donner votre choix: ");
  33.         int choice;
  34.         char toSearch[100];
  35.         int depotid;
  36.         int j;
  37.         scanf("%d",&choice);
  38.         switch(choice)
  39.         {
  40.             case 0:
  41.             return 0;
  42.             case 1:
  43.  
  44.                 printf("Depot n%d\n", n+1);
  45.                 printf("Donner l'identifiant: ");
  46.                 scanf("%d",&depots[n].id);
  47.                 printf("Donner la ville: ");
  48.                 fflush(stdin);
  49.                 gets(depots[n].ville);
  50.                 printf("Donner le type des produits: \n    1-Vestimentaire \n    2-Alimentaire\n    3-Piece de Rechange\n    Or you can write another type\n");
  51.                 fflush(stdin);
  52.                 gets(depots[n].type);
  53.                 strcpy(depots[n].type, !strcmp(depots[n].type, "1")?"Vestimentaire":(!strcmp(depots[n].type, "2")?"Alimentaire":(!strcmp(depots[n].type, "3")?"Piece de Rechange":depots[n].type)));
  54.                 printf("nombre de rayons du depot: ");
  55.                 scanf("%d",&depots[n].nrayons);
  56.                 for(int s=0;s<depots[n].nrayons;s++)
  57.                 {
  58.                     depots[n].ppr[s] = 0;
  59.                 }
  60.                 depots[n].rayonsfilled = 0;
  61.                 printf("Donner le nom du responsable: ");
  62.                 fflush(stdin);
  63.                 gets(depots[n].responsable);
  64.                 n++;
  65.                 break;
  66.             case 2:
  67.                 printf("Depot's Id? ");
  68.                 scanf("%d",&depotid);
  69.                 j = 0;
  70.                 while(j < n && depots[j].id != depotid)
  71.                 {
  72.                     j++;
  73.                 }
  74.                 if(j == n)printf("Depot doesn't exist\n");
  75.                 else
  76.                 {
  77.                     do
  78.                     {
  79.                     printf("Donner le nombre du produit du rayon n%d: ",depots[j].rayonsfilled+1);
  80.                     scanf("%d",&depots[j].ppr[depots[j].rayonsfilled]);
  81.                     }
  82.                     while(depots[j].ppr[depots[j].rayonsfilled] < 0 || depots[j].ppr[depots[j].rayonsfilled] > 200);
  83.                     depots[j].rayonsfilled++;
  84.                 }
  85.                 break;
  86.             case 3:
  87.                 printf("Donner le type a lister: \n    1-Vestimentaire \n    2-Alimentaire\n    3-Piece de Rechange\n    Or you can write another type\n");
  88.  
  89.                 fflush(stdin);
  90.                 gets(toSearch);
  91.                 strcpy(toSearch, !strcmp(toSearch, "1")?"Vestimentaire":(!strcmp(toSearch, "2")?"Alimentaire":(!strcmp(toSearch, "3")?"Piece de Rechange":toSearch)));
  92.                 printf("Searching for type %s:",toSearch);
  93.                 for(int s=0;s<n;s++)
  94.                 {
  95.                     if(strcmp(depots[s].type, toSearch) != 0)continue;
  96.                     printf("Depot d'id %d dans %s a %d rayons et %d rayon remplis, responsable: %s\n",depots[s].id, depots[s].ville, depots[s].nrayons,depots[s].rayonsfilled, depots[s].responsable);
  97.                 }
  98.                 break;
  99.             case 4:
  100.                 printf("\n");
  101.                 int winner = -1;
  102.                 int maxthing = 0;
  103.                 for(int s=0;s<n;s++)
  104.                 {
  105.                     int total = 0;
  106.                     for(int i=0;i<depots[s].rayonsfilled;i++)
  107.                     {
  108.                         total += depots[s].ppr[i];
  109.                     }
  110.                     if(total > maxthing || winner == -1
  111.                        )
  112.                     {
  113.                         winner = s;
  114.                         maxthing = total;
  115.                     }
  116.                 }
  117.                 printf("%s a plus de produit dans %s: %d\n",depots[winner].responsable, depots[winner].ville,maxthing);
  118.                 break;
  119.             case 5:
  120.                 printf("Depot's Id? ");
  121.                 scanf("%d",&depotid);
  122.                 j = 0;
  123.                 while(j < n && depots[j].id != depotid)
  124.                 {
  125.                     j++;
  126.                 }
  127.                 if(j == n)printf("Depot doesn't exist\n");
  128.                 else
  129.                 {
  130.  
  131.                     printf("Donner le nom du nouveau responsable: ");
  132.                     fflush(stdin);
  133.                     gets(depots[j].responsable);
  134.                 }
  135.                 break;
  136.             case 6:
  137.                 printf("Donner la ville: ");
  138.                 fflush(stdin);
  139.                 gets(toSearch);
  140.                 int totalvilles=0;
  141.                 for(int s=0;s<n;s++)
  142.                 {
  143.                     if(strcmp(depots[s].ville, toSearch) == 0)totalvilles++;
  144.                 }
  145.                 printf("Il y'a un total de %d depots dans cette ville\n",totalvilles);
  146.                 break;
  147.             case 7:
  148.                 printf("Donner le seuil: ");
  149.                 int seuil;
  150.                 scanf("%d",&seuil);
  151.                 printf("Les depots sont: \n");
  152.                 for(int s=0;s<n;s++)
  153.                 {
  154.                                     int bad = 0;
  155.  
  156.                     for(int i=0;i<depots[s].rayonsfilled;i++)
  157.                     {
  158.                         if(depots[s].ppr[i] > seuil){
  159.                             bad = 1;
  160.                             break;
  161.                         }
  162.                     }
  163.                     if(!bad)printf("Depot d'id %d dans %s a %d rayons et %d rayon remplis, responsable: %s\n",depots[s].id, depots[s].ville, depots[s].nrayons,depots[s].rayonsfilled, depots[s].responsable);
  164.  
  165.                 }
  166.                 break;
  167.             case 8:
  168.                 printf("\n");
  169.                 int foundit = -1;
  170.                 for(int s=0;s<n;s++)
  171.                 {
  172.                     int total = 0;
  173.                     for(int i=0;i<depots[s].rayonsfilled;i++)
  174.                     {
  175.                         total += depots[j].ppr[i];
  176.                     }
  177.                     if(total == 0){foundit = s;break;}
  178.                 }
  179.                 if(foundit != -1)
  180.                 {
  181.                     n--;
  182.                     for(int i = foundit;i<n;i++)
  183.                     {
  184.                         depots[i] = depots[i+1];
  185.                     }
  186.                     printf("Done\n");
  187.                 }
  188.                 else
  189.                 {
  190.                     printf("Aucun depot n'est vide");
  191.                 }
  192.                 break;
  193.         }
  194.  
  195.     }
  196.  
  197.     return 0;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement