Advertisement
mmouhib

balti.pj

Nov 30th, 2021 (edited)
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.22 KB | None | 0 0
  1. #include "stdio.h"
  2.  
  3. // affichage des menus selon le choix de l'utilisateur
  4. void afficherMenu(int choix)
  5. {
  6.    
  7.     switch (choix)
  8.     {
  9.     case 1:
  10.         printf("Gestion des voitures: \n\n");
  11.         printf("1. Ajouter une nouvelle voiture \n");
  12.         printf("2. Ajouter un ensemble de voitures \n");
  13.         printf("3. Afficher l’ensemble des voitures enregistrées triés par ordre croissant \n");
  14.         printf("4. Rechercher une voiture \n");
  15.         printf("5. Supprimer une voiture \n");
  16.         printf("6. Retourner au menu principal \n");
  17.         printf("7. Quitter \n\n");
  18.         break;
  19.  
  20.     case 2:
  21.         printf("Gestion des Agences \n\n");
  22.         printf("1. Ajouter une nouvelle agence \n");
  23.         printf("2. Afficher l’ensemble des agences enregistrées triés par ordre croissant \n");
  24.         printf("3. Rechercher une agence \n");
  25.         printf("4. Modifier l’indice d’une agence \n");
  26.         printf("5. Supprimer une agence \n");
  27.         printf("6. Retourner au menu principal \n");
  28.         printf("7. Quitter \n\n");
  29.         break;
  30.  
  31.     default:
  32.         printf("Gestion des affectations \n\n");
  33.         printf("1. Affecter une voiture à une agence \n");
  34.         printf("2. Afficher l’ensemble des voitures disponibles \n");
  35.         printf("3. Afficher l’affectation d’une voiture \n");
  36.         printf("4. Afficher l’affectation d’une\n");
  37.         printf("5. Afficher le nombre de voitures par agence \n");
  38.         printf("6. Afficher l’agence ayant le maximum de voitures \n");
  39.         printf("7. Libérer une voiture \n");
  40.         printf("8. Afficher le taux d’occupation des voitures \n");
  41.         printf("9. Quitter \n\n");
  42.     }
  43. }
  44.  
  45. // affichage du tableau
  46. void afficherTab(int t[50], int n)
  47. {
  48.     printf("\n");
  49.     for (int i = 0; i < n; i++)
  50.     {
  51.         printf("** element %d: %d\n", i+1, t[i]);
  52.     }
  53. }
  54.  
  55. // affichage du tableau triee
  56. void afficherTabTriee(int t[50], int n)
  57. {
  58.     int d, c, swap;
  59.     for (c = 0; c < n - 1; c++)
  60.     {
  61.         for (d = 0; d < n - c - 1; d++)
  62.         {
  63.             if (t[d] > t[d + 1])
  64.             {
  65.                 swap = t[d];
  66.                 t[d] = t[d + 1];
  67.                 t[d + 1] = swap;
  68.             }
  69.         }
  70.     }
  71.     // appel d'affichage normal apres le tri
  72.     afficherTab(t, n);
  73. }
  74.  
  75.  
  76. void afficherTabTrieeAgence(int t[50], int n)
  77. {
  78.     int d, c;
  79.     char swap;
  80.     for (c = 0; c < n - 1; c++)
  81.     {
  82.         for (d = 0; d < n - c - 1; d++)
  83.         {
  84.             if (t[d] > t[d + 1])
  85.             {
  86.                 swap = t[d];
  87.                 t[d] = t[d + 1];
  88.                 t[d + 1] = swap;
  89.             }
  90.         }
  91.     }
  92.     // appel d'affichage normal apres le tri
  93.     afficherTab(t, n);
  94. }
  95.  
  96. // recherche du voiture dans le tableau
  97. int rechercherVoiture(int t[50], int n, int voiture)
  98. {
  99.     for (int i = 0; i < n; i++)
  100.     {
  101.         if (t[i] == voiture)
  102.         {
  103.             return 1;
  104.         }
  105.     }
  106.     return 0;
  107. }
  108.  
  109. // recherche d'agence dans le tableau
  110. int rechercherAgence(char t[50], int n, char agence)
  111. {
  112.     for (int i = 0; i < n; i++)
  113.     {
  114.         if (t[i] == agence)
  115.         {
  116.             return 1;
  117.         }
  118.     }
  119.     return 0;
  120. }
  121.  
  122. void ajoutSequenceVoiture(int t[50], int n, int x)
  123. {
  124.     int i = x, a;
  125.     while (1)
  126.     {
  127.         int ajout;
  128.         printf("ahouter ? (1 pour oui et 0 pour non)");
  129.         scanf("%d", &a);
  130.         if (a != 0)
  131.         {
  132.             printf("t[%d]:", i);
  133.             scanf("%d", t[i]);
  134.             i++;
  135.         }
  136.         else
  137.         {
  138.             break;
  139.         }
  140.     }
  141.     // le role de cette boucle est de se debuter de l'indexe du dernier ajout fait dans le tableau et dire a l'utilisateur d'entrer une valeur si non quitter
  142. }
  143.  
  144.  
  145. void ajoutVoiture(int *t[50], int n){
  146.         printf("\n");
  147.     for (int i = 0; i < n; i++){
  148.         printf("Voiture N° %d => ",i+1);
  149.         scanf("%d", &t[i]);
  150.     }
  151. }
  152.  
  153. void ajoutAgence(char *t[50], int n){
  154.     for (int i = 0; i < n; i++){
  155.         printf("Agence N° %d",i);
  156.         scanf("%c", &t[i]);
  157.     }
  158. }
  159.  
  160. void supprimerElement(int *t[50], int n, int position){
  161.     for (int i = position - 1; i < n - 1; i++){
  162.         t[i] = t[i+1];
  163.     }
  164. }
  165.  
  166. void changerIndiceAgence(char *t[50],int n,int oldPos,int newPos){
  167.     char temp = t[oldPos];
  168.     t[oldPos] = t[newPos];
  169.     t[newPos] = temp;
  170.    
  171. }
  172.  
  173.  
  174.  
  175. // main
  176. void main()
  177. {
  178.  
  179.     // declaration des tableaux
  180.     int tv[50], tf[50][50];
  181.     int choix = 0;
  182.     int nv, na;
  183.     char ta[50];
  184.  
  185.     debut:
  186.     printf("---------------------------------------\n");
  187.     printf("1 => Gestion des voitures\n");
  188.     printf("2 => Gestion des Agences\n");
  189.     printf("3 => Gestion des affectations\n\n");
  190.  
  191.     printf("\n\n");
  192.  
  193.    
  194.     do
  195.     {
  196.         printf("\nton choix: ");
  197.         scanf("%d", &choix);
  198.     } while ((choix < 1) || (choix > 3));
  199.  
  200.     printf("\n\n");
  201.     afficherMenu(choix);
  202.  
  203.     int choix2 = 0;
  204.  
  205.     switch (choix){
  206.         case 1:
  207.             do
  208.             {
  209.                 printf("choix du premiere menu: ");
  210.                 scanf("%d", &choix2);
  211.             } while ((choix < 1) || (choix > 7));
  212.             break;
  213.         default:
  214.             do
  215.             {
  216.                 printf("choix du premiere menu: ");
  217.                 scanf("%d", &choix2);
  218.             } while ((choix < 1) || (choix > 9));
  219.             break;
  220.     }
  221.    
  222.     if (choix == 1){
  223.         switch (choix2){
  224.             case 1:
  225.                 ajoutVoiture(tv,1);
  226.                 break;
  227.             case 2:
  228.                 printf("Nombre de voitures a ajouter: ");
  229.                 scanf("%d", &nv);
  230.                 ajoutVoiture(tv,nv);
  231.                 break;
  232.             case 3:
  233.                 afficherTabTriee(tv,nv);
  234.                 break;
  235.             case 4:
  236.                 int voit;
  237.                 printf("\n Voiture a rechercher: ");
  238.                 scanf("%d", &voit);
  239.                 if (rechercherVoiture(tv, nv, voit) == 0)
  240.                 {
  241.                     printf("Voiture introuvable");
  242.  
  243.                 }
  244.                 else{
  245.                     printf("Voiture trouvee");
  246.                 }
  247.                 break;
  248.            
  249.             case 5:
  250.                 int i;
  251.                 printf("Indice pour supprimer: ");
  252.                 scanf("%d",&i);
  253.                 if (i>nv){
  254.                     printf("indice > au taille du tableau");
  255.                 }
  256.                 else{
  257.                     supprimerElement(tv,nv,i);
  258.                 }
  259.                 break;
  260.             case 6:
  261.                 goto debut;
  262.                 break;
  263.             case 7:
  264.                 return;
  265.         }
  266.         printf("\n\n\n");
  267.         goto debut;
  268.        
  269.     }
  270.  
  271.     if (choix == 2){
  272.         switch (choix2){
  273.             case 1:
  274.                 printf("Nombre d'agences a ajouter: ");
  275.                 scanf("%d", &na);
  276.                 ajoutAgence(ta,na);
  277.                 break;
  278.             case 2:
  279.                 afficherTabTrieeAgence(ta,na);
  280.                 break;
  281.             case 3:
  282.                 char agence;
  283.                 printf("\n Voiture a rechercher: ");
  284.                 scanf("%d", &agence);
  285.                 if (rechercherVoiture(ta, na, agence) == 0){
  286.                     printf("agence introuvable");
  287.                 }
  288.                 else{
  289.                     printf("agence trouvee");
  290.                 }
  291.                 break;
  292.             case 4:
  293.                 int old, new;
  294.                 printf("\n indice a changer: ");
  295.                 scanf("%d", &old);
  296.                 printf("\n Nouveau indice: ");
  297.                 scanf("%d", &new);
  298.                 changerIndiceAgence(ta, na, old, new);
  299.                 break;
  300.             case 5:
  301.                 int i;
  302.                 printf("Indice pour supprimer: ");
  303.                 scanf("%d",&i);
  304.                 if (i>nv){
  305.                     printf("indice > au taille du tableau");
  306.                 }
  307.                 else{
  308.                     supprimerElement(tv,nv,i);
  309.                 }
  310.                 break;
  311.             case 6:
  312.                 goto debut;
  313.                 break;
  314.             case 7:
  315.                 return;
  316.         }
  317.         printf("\n\n\n");
  318.         goto debut;
  319.        
  320.     }
  321.    
  322. }
  323.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement