Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 20
- #define NB_PRODUIT 20
- typedef struct prod {
- int code;
- char designation[MAX];
- int quantite;
- } Produit;
- typedef enum {
- false,
- true
- }Bool;
- void init_Stock(Produit Stock[]);
- void afficher_menu(void);
- void nouveau_produit(Produit *p);
- void inserer_produit(Produit Stk[]);
- void afficher_stock(Produit Stk[]);
- Bool chercher(Produit Stk[]);
- void calculer_quantites(Produit Stk[]);
- void afficher_quantites(Produit Stk[]);
- int main(void) {
- int menu = -1;
- Produit produit_temp;
- Produit Stock[NB_PRODUIT]; //le stock
- init_Stock(Stock);
- while(menu != 0) {
- afficher_menu();
- scanf("%d", &menu);
- switch (menu) {
- case 0:
- return 0;
- case 1:
- nouveau_produit(&produit_temp);
- break;
- case 2:
- inserer_produit(Stock);
- break;
- case 3:
- afficher_stock(Stock);
- break;
- case 4:
- if(chercher(Stock))
- printf("le produit existe dans le stock.\n\n");
- else
- printf("le produit n'existe pas dans le Stock.\n\n");
- break;
- case 5:
- calculer_quantites(Stock);
- break;
- case 6:
- afficher_quantites(Stock);
- break;
- default:
- printf("\n/!\\ erreur veuillez choisir une autre fois /!\\\n\n");
- break;
- }
- }
- return 0;
- }
- /* affiche le Menu */
- void afficher_menu(void) {
- printf("voila le menu :\n");
- printf("1 -> fonction qui cree un nv produit.\n");
- printf("2 -> fonction qui insere un nv produit.\n");
- printf("3 -> fonction qui affiche.\n");
- printf("4 -> fonction qui cherche.\n");
- printf("5 -> fonction qui calcule la qte totale.\n");
- printf("6 -> fonction qui affiche produit.\n");
- printf("0 -> quitter.\n");
- printf("\nveuillez choisir svp : ");
- return;
- }
- /* crée un nouveau produit */
- void nouveau_produit(Produit *p) {
- printf("donner le code : ");
- scanf("%d", &p->code);
- fflush(stdin);
- printf("donner la designation : ");
- scanf("%s", &p->designation);
- fflush(stdin);
- printf("donner la quantite : ");
- scanf("%d", &p->quantite);
- }
- /* insérer un nouveau produit dans le stock */
- void inserer_produit(Produit Stk[]) {
- static int nb = 0;
- if(nb < NB_PRODUIT) {
- printf("donner le code : ");
- Stk[0].code = 1221;
- scanf("%d", &Stk[nb].code);
- fflush(stdin);
- printf("donner la designation : ");
- scanf("%s", &Stk[nb].designation);
- fflush(stdin);
- printf("donner la quantite : ");
- scanf("%d", &Stk[nb].quantite);
- printf("\n");
- nb++;
- }
- }
- /* init Stock */
- void init_Stock(Produit Stock[]) {
- for(int i = 0; i < NB_PRODUIT; i++) {
- Stock[i].code = 0;
- }
- }
- /* affichage du stock */
- void afficher_stock(Produit Stk[]) {
- if(Stk[0].code == 0) {
- printf("\nle Stock est vide.\n\n");
- return;
- }
- printf("Le Stock :\n");
- for(int i = 0; Stk[i].code != 0; i++) {
- printf("le code : %d | la designation : %s | la quantite : %d\n", Stk[i].code, Stk[i].designation, Stk[i].quantite);
- }
- printf("\n");
- }
- /* chercher par code et designation */
- Bool chercher(Produit Stk[]) {
- int code;
- char designation[MAX];
- printf("donner le code : ");
- scanf("%d", &code);
- fflush(stdin);
- printf("donner la designation : ");
- scanf("%s", &designation);
- for(int i = 0; Stk[i].code != 0; i++) {
- if(Stk[i].code == code && !strcmp(Stk[i].designation, designation))
- return true;
- }
- return false;
- }
- /* calculer les quantites */
- void calculer_quantites(Produit Stk[]) {
- int qnt = 0;
- if(Stk[0].code == 0) {
- printf("\nle Stock est vide.\n\n");
- return;
- }
- for(int i = 0; Stk[i].code != 0; i++) {
- qnt += Stk[i].quantite;
- }
- printf("\nla quantite total est : %d\n\n", qnt);
- }
- /* afficher la liste des produit supérieur a la valeur donnée */
- void afficher_quantites(Produit Stk[]) {
- int valeur;
- if(Stk[0].code == 0) {
- printf("\nle Stock est vide.\n\n");
- return;
- }
- printf("donner une valeur : ");
- scanf("%d", &valeur);
- printf("les produits qui ont la quantites supérieurs de %d sont :\n", valeur);
- for(int i = 0; Stk[i].code != 0; i++) {
- if(Stk[i].quantite > valeur) {
- printf("le code : %d | la designation : %s | la quantite : %d\n", Stk[i].code, Stk[i].designation, Stk[i].quantite);
- }
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement