Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct depot
- {
- int id;
- char ville[100];
- char type[100];
- int nrayons;
- int rayonsfilled;
- int ppr[500];
- char responsable[100];
- };
- int main()
- {
- int n = 0;
- struct depot depots[100];
- while(1)
- {
- printf("\n");
- printf("Select one:\n");
- printf("1-Add Depot:\n");
- printf("2-Fill Rayon :\n");
- printf("3-List depots of type :\n");
- printf("4-Show best depot :\n");
- printf("5-Change Admin :\n");
- printf("6-Calc Depots in Ville :\n");
- printf("7-Depot seuil ect :\n");
- printf("8-Delete first empty :\n");
- printf("Donner votre choix: ");
- int choice;
- char toSearch[100];
- int depotid;
- int j;
- scanf("%d",&choice);
- switch(choice)
- {
- case 0:
- return 0;
- case 1:
- printf("Depot n%d\n", n+1);
- printf("Donner l'identifiant: ");
- scanf("%d",&depots[n].id);
- printf("Donner la ville: ");
- fflush(stdin);
- gets(depots[n].ville);
- 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");
- fflush(stdin);
- gets(depots[n].type);
- 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)));
- printf("nombre de rayons du depot: ");
- scanf("%d",&depots[n].nrayons);
- for(int s=0;s<depots[n].nrayons;s++)
- {
- depots[n].ppr[s] = 0;
- }
- depots[n].rayonsfilled = 0;
- printf("Donner le nom du responsable: ");
- fflush(stdin);
- gets(depots[n].responsable);
- n++;
- break;
- case 2:
- printf("Depot's Id? ");
- scanf("%d",&depotid);
- j = 0;
- while(j < n && depots[j].id != depotid)
- {
- j++;
- }
- if(j == n)printf("Depot doesn't exist\n");
- else
- {
- do
- {
- printf("Donner le nombre du produit du rayon n%d: ",depots[j].rayonsfilled+1);
- scanf("%d",&depots[j].ppr[depots[j].rayonsfilled]);
- }
- while(depots[j].ppr[depots[j].rayonsfilled] < 0 || depots[j].ppr[depots[j].rayonsfilled] > 200);
- depots[j].rayonsfilled++;
- }
- break;
- case 3:
- 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");
- fflush(stdin);
- gets(toSearch);
- strcpy(toSearch, !strcmp(toSearch, "1")?"Vestimentaire":(!strcmp(toSearch, "2")?"Alimentaire":(!strcmp(toSearch, "3")?"Piece de Rechange":toSearch)));
- printf("Searching for type %s:",toSearch);
- for(int s=0;s<n;s++)
- {
- if(strcmp(depots[s].type, toSearch) != 0)continue;
- 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);
- }
- break;
- case 4:
- printf("\n");
- int winner = -1;
- int maxthing = 0;
- for(int s=0;s<n;s++)
- {
- int total = 0;
- for(int i=0;i<depots[s].rayonsfilled;i++)
- {
- total += depots[s].ppr[i];
- }
- if(total > maxthing || winner == -1
- )
- {
- winner = s;
- maxthing = total;
- }
- }
- printf("%s a plus de produit dans %s: %d\n",depots[winner].responsable, depots[winner].ville,maxthing);
- break;
- case 5:
- printf("Depot's Id? ");
- scanf("%d",&depotid);
- j = 0;
- while(j < n && depots[j].id != depotid)
- {
- j++;
- }
- if(j == n)printf("Depot doesn't exist\n");
- else
- {
- printf("Donner le nom du nouveau responsable: ");
- fflush(stdin);
- gets(depots[j].responsable);
- }
- break;
- case 6:
- printf("Donner la ville: ");
- fflush(stdin);
- gets(toSearch);
- int totalvilles=0;
- for(int s=0;s<n;s++)
- {
- if(strcmp(depots[s].ville, toSearch) == 0)totalvilles++;
- }
- printf("Il y'a un total de %d depots dans cette ville\n",totalvilles);
- break;
- case 7:
- printf("Donner le seuil: ");
- int seuil;
- scanf("%d",&seuil);
- printf("Les depots sont: \n");
- for(int s=0;s<n;s++)
- {
- int bad = 0;
- for(int i=0;i<depots[s].rayonsfilled;i++)
- {
- if(depots[s].ppr[i] > seuil){
- bad = 1;
- break;
- }
- }
- 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);
- }
- break;
- case 8:
- printf("\n");
- int foundit = -1;
- for(int s=0;s<n;s++)
- {
- int total = 0;
- for(int i=0;i<depots[s].rayonsfilled;i++)
- {
- total += depots[j].ppr[i];
- }
- if(total == 0){foundit = s;break;}
- }
- if(foundit != -1)
- {
- n--;
- for(int i = foundit;i<n;i++)
- {
- depots[i] = depots[i+1];
- }
- printf("Done\n");
- }
- else
- {
- printf("Aucun depot n'est vide");
- }
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement