Advertisement
yanni_yagami

Untitled

Jun 27th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX 20
  5. #define NB_PRODUIT 20
  6.  
  7. typedef struct prod {
  8.     int code;
  9.     char designation[MAX];
  10.     int quantite;
  11. } Produit;
  12.  
  13. typedef enum {
  14.     false,
  15.     true
  16. }Bool;
  17.  
  18. void init_Stock(Produit Stock[]);
  19. void afficher_menu(void);
  20. void nouveau_produit(Produit *p);
  21. void inserer_produit(Produit Stk[]);
  22. void afficher_stock(Produit Stk[]);
  23. Bool chercher(Produit Stk[]);
  24. void calculer_quantites(Produit Stk[]);
  25. void afficher_quantites(Produit Stk[]);
  26.  
  27. int main(void) {
  28.     int menu = -1;
  29.     Produit produit_temp;
  30.     Produit Stock[NB_PRODUIT]; //le stock
  31.  
  32.     init_Stock(Stock);
  33.     while(menu != 0) {
  34.         afficher_menu();
  35.         scanf("%d", &menu);
  36.  
  37.         switch (menu) {
  38.         case 0:
  39.             return 0;
  40.         case 1:
  41.             nouveau_produit(&produit_temp);
  42.             break;
  43.  
  44.         case 2:
  45.             inserer_produit(Stock);
  46.             break;
  47.  
  48.         case 3:
  49.             afficher_stock(Stock);
  50.         break;
  51.  
  52.         case 4:
  53.             if(chercher(Stock))
  54.                 printf("le produit existe dans le stock.\n\n");
  55.             else
  56.                 printf("le produit n'existe pas dans le Stock.\n\n");
  57.         break;
  58.  
  59.         case 5:
  60.             calculer_quantites(Stock);
  61.         break;
  62.  
  63.         case 6:
  64.             afficher_quantites(Stock);
  65.         break;
  66.  
  67.         default:
  68.             printf("\n/!\\ erreur veuillez choisir une autre fois /!\\\n\n");
  69.             break;
  70.         }
  71.     }
  72.  
  73.     return 0;
  74. }
  75.  
  76. /* affiche le Menu */
  77. void afficher_menu(void) {
  78.     printf("voila le menu :\n");
  79.     printf("1 -> fonction qui cree un nv produit.\n");
  80.     printf("2 -> fonction qui insere un nv produit.\n");
  81.     printf("3 -> fonction qui affiche.\n");
  82.     printf("4 -> fonction qui cherche.\n");
  83.     printf("5 -> fonction qui calcule la qte totale.\n");
  84.     printf("6 -> fonction qui affiche produit.\n");
  85.     printf("0 -> quitter.\n");
  86.     printf("\nveuillez choisir svp : ");
  87.     return;
  88. }
  89.  
  90. /* crée un nouveau produit */
  91. void nouveau_produit(Produit *p) {
  92.     printf("donner le code : ");
  93.     scanf("%d", &p->code);
  94.     fflush(stdin);
  95.     printf("donner la designation : ");
  96.     scanf("%s", &p->designation);
  97.     fflush(stdin);
  98.     printf("donner la quantite : ");
  99.     scanf("%d", &p->quantite);
  100. }
  101.  
  102. /* insérer un nouveau produit dans le stock */
  103. void inserer_produit(Produit Stk[]) {
  104.     static int nb = 0;
  105.     if(nb < NB_PRODUIT) {
  106.         printf("donner le code : ");
  107.         Stk[0].code = 1221;
  108.         scanf("%d", &Stk[nb].code);
  109.         fflush(stdin);
  110.         printf("donner la designation : ");
  111.         scanf("%s", &Stk[nb].designation);
  112.         fflush(stdin);
  113.         printf("donner la quantite : ");
  114.         scanf("%d", &Stk[nb].quantite);
  115.         printf("\n");
  116.         nb++;
  117.     }
  118. }
  119.  
  120. /* init Stock */
  121. void init_Stock(Produit Stock[]) {
  122.     for(int i = 0; i < NB_PRODUIT; i++) {
  123.         Stock[i].code = 0;
  124.     }
  125. }
  126.  
  127. /* affichage du stock */
  128. void afficher_stock(Produit Stk[]) {
  129.     if(Stk[0].code == 0) {
  130.         printf("\nle Stock est vide.\n\n");
  131.         return;
  132.     }
  133.  
  134.     printf("Le Stock :\n");
  135.     for(int i = 0; Stk[i].code != 0; i++) {
  136.         printf("le code : %d | la designation : %s | la quantite : %d\n", Stk[i].code, Stk[i].designation, Stk[i].quantite);
  137.     }
  138.     printf("\n");
  139. }
  140.  
  141. /* chercher par code et designation */
  142. Bool chercher(Produit Stk[]) {
  143.     int code;
  144.     char designation[MAX];
  145.     printf("donner le code : ");
  146.     scanf("%d", &code);
  147.     fflush(stdin);
  148.     printf("donner la designation : ");
  149.     scanf("%s", &designation);
  150.  
  151.     for(int i = 0; Stk[i].code != 0; i++) {
  152.         if(Stk[i].code == code && !strcmp(Stk[i].designation, designation))
  153.             return true;
  154.     }
  155.     return false;
  156. }
  157.  
  158. /* calculer les quantites */
  159. void calculer_quantites(Produit Stk[]) {
  160.     int qnt = 0;
  161.  
  162.     if(Stk[0].code == 0) {
  163.         printf("\nle Stock est vide.\n\n");
  164.         return;
  165.     }
  166.  
  167.     for(int i = 0; Stk[i].code != 0; i++) {
  168.         qnt += Stk[i].quantite;
  169.     }
  170.  
  171.     printf("\nla quantite total est : %d\n\n", qnt);
  172. }
  173.  
  174. /* afficher la liste des produit supérieur a la valeur donnée */
  175. void afficher_quantites(Produit Stk[]) {
  176.     int valeur;
  177.  
  178.     if(Stk[0].code == 0) {
  179.         printf("\nle Stock est vide.\n\n");
  180.         return;
  181.     }
  182.  
  183.     printf("donner une valeur : ");
  184.     scanf("%d", &valeur);
  185.     printf("les produits qui ont la quantites supérieurs de %d sont :\n", valeur);
  186.     for(int i = 0; Stk[i].code != 0; i++) {
  187.         if(Stk[i].quantite > valeur) {
  188.             printf("le code : %d | la designation : %s | la quantite : %d\n", Stk[i].code, Stk[i].designation, Stk[i].quantite);
  189.         }
  190.     }
  191.         printf("\n");
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement