From 5d6ee0881d1e43f4a5db20da6eacb66f6fd172fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Math=C3=A9o=20Hersan?= Date: Tue, 31 Oct 2023 15:51:49 +0100 Subject: [PATCH] better code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathéo Hersan --- app | Bin 52176 -> 52400 bytes donnee/client.txt | 2 +- src/app/core_logic/client.c | 147 +++++++++++++++++---------- src/app/core_logic/client.h | 52 +++++++++- src/app/interface/interface_client.c | 25 +++-- src/app/interface/interface_client.h | 2 + 6 files changed, 156 insertions(+), 72 deletions(-) diff --git a/app b/app index 4ad0d038a63a4e0002f4fd0e6a7307d4e2336b8f..cfb49ba55316b08b2aaaab78651dae70c093f124 100755 GIT binary patch delta 7788 zcmbtZdt8)N`akcy@5l@w$VG?y3<83H2wss427y2`xg;t|jtHZSTxCF0u)%Q6(ppZ3 zR=0I)Ol=2sTU;!e0vE$Brdva~rKvS&mqD$iwzlE768oI@Lcq`d`Tbr#@6375b2-m> z&hvfFnS*UV+xC05+2(CdMurg0+i{y&hBpd?rSI9ScK}4TAGx{!vT5jH_wc3l3)qXet z_Z9o%8(|)J_XL=#4q3sH4Tax_ksCRas^X#+;=ANZYKrWpt7J2N&O+Shidt?A536|T z^!xF3ps7#PAIHOtLkE#qqwVTjsqLb^M>EKJ3!)M&M}tvbh{UA(E5C*aWhhX~ z3bHtTrRld2rxci}{V;?3Zo1$bvl)EB1+^rN>l*}(x#Ri_O4Je$ef(;*$Z$0H%SVhI zJL5>`ccf{pklvg5^p=gJw|W5GVR4Y8_^*-W=R@u9N|G}IR<*%IWp2`$ zj#}?eIZflEnW zrXL4MT|$O3wG)vi&H+gp=PV_UuXR~U4)ilfMb<%iqbCkl5|71dxx*9tD#@(HvqRG- z;R&J&pE^yWG63w#lw|kf6n8%_{4FFPHT)InU990wdEuMn$HjZNC~w?Nb}rGlReR&p zq6k^HI-J;+C?|D$<5uY7;|m%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C)9_=28U||Tw7~B#DfhcL$bCA>Npu1Gt)H0WsNBl}qX8zSs9|5>UU!tH}o zk=uD8ew#tN z6zTckPx8waU0lu#Tn4ku4tQ$WG3{=s*6n3_h+TdgC#QT!zLD_$f*$qMr2wg^8_GxS$iCz867L^YeB z;G>cW8i`ENt&)jPNj{~if=FlQl}1l;*Wiun>NGRNnc}i)b5)h8B5{aFHGxFitEFCi zEHEVlQ^uxE=7J(qg}BvJDdtyHnG5JZF^TFAtq9XTGoh~tojx?dG_oaAhHER>YBrTt zJ*({XiqPR3K2;HJ8BzxeGG)_2Syox0d6OATt1eY6dyX%aF1n?x8um%qq$L&WpW61+ z9Xp?Mhd0s$ic8FuRVJ~}-3M(;DvxrUNFG*&aXZN4>Il+Xqa$h65)#Rd>UcIENzTio zDdabmQQm4(2Pfh4camu#;&5MwY^4f(-TStS;BwQT8X5)1Q7D=_a#T4`XJgmQV*Z2_w766JZa zpVXc+`n7&ULGLF_tev>dWvIJPP_XYbNj@KyaQHe^m0z*hgwCkS%sUp9LauDeFEF7S zDgkw0rK~sh(9b9DlU?V>%;*3of%IJLgL{OUCw03FpbUajAqWW&8*jL5&6N zR|Mclp?VL?cbyYDKR9CTU^0&Qd z|NiRKn%s-i&uDIMsA=PWUR7{#;)>jtd^~y_>-eKIJlw?KqyZ^zvrQxcm+QsiUs@i_h DMCO3> diff --git a/donnee/client.txt b/donnee/client.txt index e542074..ab28f6f 100644 --- a/donnee/client.txt +++ b/donnee/client.txt @@ -1,4 +1,4 @@ 32 0.00 0 -660 11.03 0 +660 57.03 0 5079 75.50 0 8043 50.50 1 diff --git a/src/app/core_logic/client.c b/src/app/core_logic/client.c index 963261b..27d64e4 100644 --- a/src/app/core_logic/client.c +++ b/src/app/core_logic/client.c @@ -3,7 +3,6 @@ * @brief Fonctions liées à la gestion des clients et de leur panier. */ -#include #include "client.h" #define MAX_ARTICLES 100 @@ -43,6 +42,69 @@ int charger_clients(int numeros[], float cagnottes[], int suspendues[], int tPhy return i; } +/** + * @brief Sauvegarde les données clients dans un fichier. + * + * Cette fonction permet de sauvegarder les données clients, y compris les numéros de clients, les cagnottes, + * et les états de suspension, dans un fichier texte. + * + * @param numeros - Tableau des numéros de clients. + * @param cagnottes - Tableau des cagnottes des clients. + * @param suspendus - Tableau des états de suspension des clients. + * @param nombreClients - Nombre de clients. + */ +void sauvegarde_clients(int numeros[], float cagnottes[], int suspendus[], int nombreClients) { + FILE *fe; + fe = fopen("donnee/client.txt", "w"); + if (fe == NULL) { + perror("fopen"); + return; + } + for (int i = 0; i < nombreClients; i++) { + fprintf(fe, "%d %.2f %d\n", numeros[i], cagnottes[i], suspendus[i]); + } + fclose(fe); +} + +/** + * @brief Recherche l'index de l'article dans le tableau des références. + * + * Cette fonction recherche l'index de l'article avec la référence donnée dans le tableau des références. + * + * @param reference - Référence de l'article à rechercher. + * @param references - Tableau des références des articles. + * @param nombreArticles - Nombre d'articles disponibles. + * @return L'index de l'article s'il est trouvé, sinon -1. + */ +int trouver_index_article(int reference, int references[], int nombreArticles) { + for (int i = 0; i < nombreArticles; i++) { + if (references[i] == reference) { + return i; + } + } + return -1; +} + +/** + * @brief Trouve l'index d'un client dans le tableau des numéros de clients. + * + * Cette fonction recherche le numéro du client dans le tableau des numéros de clients + * et retourne l'index du client s'il est trouvé. + * + * @param numeroClient - Numéro du client à rechercher. + * @param numeros - Tableau des numéros de clients. + * @param nombreClients - Nombre de clients dans le tableau. + * @return L'index du client s'il est trouvé, -1 sinon. + */ +int trouver_index_client(int numeroClient, int numeros[], int nombreClients) { + for (int i = 0; i < nombreClients; i++) { + if (numeros[i] == numeroClient) { + return i; // Retourne l'index du client si trouvé + } + } + return -1; // Retourne -1 si le client n'est pas trouvé +} + /** * @brief Ajoute un article au panier du client. @@ -84,24 +146,10 @@ void ajouter_article_au_panier(int numeroClient, int references[], float poids[] } while (getchar() != '\n'); - int articleIndex = -1; - for (int i = 0; i < nombreArticles; i++) { - if (references[i] == reference) { - articleIndex = i; - break; - } - } + int articleIndex = trouver_index_article(reference, references, nombreArticles); if (articleIndex == -1) { printf("Article non trouvé. Veuillez entrer une référence valide.\n"); - return; - } - - for (int i = 0; i < *taillePanier; i++) { - if (panier[i] == reference) { - printf("Cet article est déjà dans le panier.\n"); - return; - } } float poidsTotal = poids[articleIndex] * quantite; @@ -114,13 +162,7 @@ void ajouter_article_au_panier(int numeroClient, int references[], float poids[] } else { float montantTotal = prixUnitaire[articleIndex] * quantite; - int clientIndex = -1; - for (int i = 0; i < nombreClients; i++) { - if (numeros[i] == numeroClient) { - clientIndex = i; - break; - } - } + int clientIndex = trouver_index_client(numeroClient, numeros, nombreClients); if (clientIndex != -1) { cagnottes[clientIndex] += 0.1 * montantTotal; @@ -171,13 +213,7 @@ void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanie } while (getchar() != '\n'); - int articleIndex = -1; - for (int i = 0; i < *taillePanier; i++) { - if (panier[i] == reference) { - articleIndex = i; - break; - } - } + int articleIndex = trouver_index_article(reference, panier, *taillePanier); if (articleIndex == -1) { printf("Article non trouvé dans le panier. Veuillez entrer une référence valide.\n"); @@ -194,11 +230,11 @@ void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanie printf("Article supprimé du panier avec succès.\n"); } - /** * @brief Affiche un récapitulatif du contenu du panier. * - * Cette fonction permet d'afficher un récapitulatif du contenu du panier. + * Cette fonction permet d'afficher un récapitulatif détaillé du contenu du panier du client, y compris les références des articles, + * les quantités, les poids, les volumes, les prix unitaires, les totaux de poids, de volume, de prix, et la cagnotte du client. * * @param panier - Tableau des références des articles dans le panier. * @param taillePanier - Taille du panier. @@ -207,25 +243,30 @@ void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanie * @param volume - Tableau des volumes des articles. * @param prixUnitaire - Tableau des prix unitaires des articles. * @param quantites - Tableau des quantités de chaque article dans le panier. + * @param cagnottes - Tableau des cagnottes des clients. + * @param numeroClient - Numéro du client. + * @param numeros - Tableau des numéros de clients. + * @param nombreClients - Nombre de clients. + * @param volumeCoffre - Volume total du coffre. + * @param chargeMaximale - Charge maximale du coffre. */ void affiche_recap_panier(int panier[], int taillePanier, int references[], float poids[], float volume[], - float prixUnitaire[], int quantites[]) { + float prixUnitaire[], int quantites[], float cagnottes[], int numeroClient, + int numeros[], int nombreClients, float volumeCoffre, float chargeMaximale) { + printf("Contenu du panier : "); + for (int i = 0; i < taillePanier; i++) { + printf("%d ", panier[i]); + } + printf("\n"); + + printf("Récap :\n"); printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot\n"); + float poidsTotal = 0, volumeTotal = 0, montantTotal = 0; + for (int i = 0; i < taillePanier; i++) { int reference = panier[i]; - int articleIndex = -1; - for (int j = 0; j < MAX_ARTICLES; j++) { - if (references[j] == reference) { - articleIndex = j; - break; - } - } - - if (articleIndex == -1) { - printf("Article non trouvé. Veuillez entrer une référence valide.\n"); - return; - } + int articleIndex = trouver_index_article(reference, references, MAX_ARTICLES); float poidsArticle = poids[articleIndex]; float volumeArticle = volume[articleIndex]; @@ -241,9 +282,14 @@ void affiche_recap_panier(int panier[], int taillePanier, int references[], floa montantTotal += prixArticle * quantite; } + int clientIndex = trouver_index_client(numeroClient, numeros, nombreClients); + printf("Prix total à payer: %.2f euros\n", montantTotal); + printf("Cagnotte totale : %.2f euros\n", cagnottes[clientIndex]); printf("Volume utilise : %.2f litres\n", volumeTotal); + printf("Volume restant : %.2f litres\n", volumeCoffre - volumeTotal); printf("Charge Actuelle: %.2f kg\n", poidsTotal); + printf("Charge restante: %.2f kg\n", chargeMaximale - poidsTotal); } /** @@ -336,15 +382,4 @@ void deduire_cagnotte(int numeroClient, float montant, int numeros[], float cagn } cagnottes[clientIndex] -= montant; - - FILE *fe; - fe = fopen("donnee/client.txt", "w"); - if (fe == NULL) { - perror("fopen"); - return; - } - for (int i = 0; i < nombreClients; i++) { - fprintf(fe, "%d %.2f %d\n", numeros[i], cagnottes[i], suspendus[i]); - } - fclose(fe); } \ No newline at end of file diff --git a/src/app/core_logic/client.h b/src/app/core_logic/client.h index 2aa3ff8..20ac047 100644 --- a/src/app/core_logic/client.h +++ b/src/app/core_logic/client.h @@ -20,6 +20,20 @@ */ int charger_clients(int numeros[], float cagnottes[], int suspendues[], int tPhysique); + +/** + * @brief Sauvegarde les données clients dans un fichier. + * + * Cette fonction permet de sauvegarder les données clients, y compris les numéros de clients, les cagnottes, + * et les états de suspension, dans un fichier texte. + * + * @param numeros - Tableau des numéros de clients. + * @param cagnottes - Tableau des cagnottes des clients. + * @param suspendus - Tableau des états de suspension des clients. + * @param nombreClients - Nombre de clients. + */ +void sauvegarde_clients(int numeros[], float cagnottes[], int suspendus[], int nombreClients); + /** * @brief Ajoute un article au panier du client. * @@ -55,6 +69,9 @@ void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanie /** * @brief Affiche un récapitulatif du contenu du panier. * + * Cette fonction permet d'afficher un récapitulatif détaillé du contenu du panier du client, y compris les références des articles, + * les quantités, les poids, les volumes, les prix unitaires, les totaux de poids, de volume, de prix, et la cagnotte du client. + * * @param panier - Tableau des références des articles dans le panier. * @param taillePanier - Taille du panier. * @param references - Tableau des références des articles. @@ -62,10 +79,16 @@ void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanie * @param volume - Tableau des volumes des articles. * @param prixUnitaire - Tableau des prix unitaires des articles. * @param quantites - Tableau des quantités de chaque article dans le panier. + * @param cagnottes - Tableau des cagnottes des clients. + * @param numeroClient - Numéro du client. + * @param numeros - Tableau des numéros de clients. + * @param nombreClients - Nombre de clients. + * @param volumeCoffre - Volume total du coffre. + * @param chargeMaximale - Charge maximale du coffre. */ void affiche_recap_panier(int panier[], int taillePanier, int references[], float poids[], float volume[], - float prixUnitaire[], int quantites[]); - + float prixUnitaire[], int quantites[], float cagnottes[], int numeroClient, + int numeros[], int nombreClients, float volumeCoffre, float chargeMaximale); /** * @brief Modifie la quantité d'un article dans le panier du client. * @@ -96,4 +119,29 @@ void reinitialiser_panier(int panier[], int quantites[], int *taillePanier); */ void deduire_cagnotte(int numeroClient, float montant, int numeros[], float cagnottes[], int nombreClients, int suspendus[]); +/** + * @brief Recherche l'index de l'article dans le tableau des références. + * + * Cette fonction recherche l'index de l'article avec la référence donnée dans le tableau des références. + * + * @param reference - Référence de l'article à rechercher. + * @param references - Tableau des références des articles. + * @param nombreArticles - Nombre d'articles disponibles. + * @return L'index de l'article s'il est trouvé, sinon -1. + */ +int trouver_index_article(int reference, int references[], int nombreArticles); + +/** + * @brief Trouve l'index d'un client dans le tableau des numéros de clients. + * + * Cette fonction recherche le numéro du client dans le tableau des numéros de clients + * et retourne l'index du client s'il est trouvé. + * + * @param numeroClient - Numéro du client à rechercher. + * @param numeros - Tableau des numéros de clients. + * @param nombreClients - Nombre de clients dans le tableau. + * @return L'index du client s'il est trouvé, -1 sinon. + */ +int trouver_index_client(int numeroClient, int numeros[], int nombreClients); + #endif // SAE_101_CLIENT_H diff --git a/src/app/interface/interface_client.c b/src/app/interface/interface_client.c index 92ffa6c..a235948 100644 --- a/src/app/interface/interface_client.c +++ b/src/app/interface/interface_client.c @@ -4,9 +4,6 @@ */ #include "interface_client.h" -#include "app/core_logic/client.h" -#include "app/core_logic/responsable.h" - #define MAX_ARTICLES 100 #define MAX_CLIENTS 100 @@ -19,15 +16,15 @@ void affiche_client() { printf("|| Bonjour ! ||\n"); printf("+-------------+\n"); printf("\n"); - printf("+-----------------------------------------------------------------+\n"); - printf("|| Que voulez-vous faire ?\t\t\t\t\t\t\t||\n"); - printf("||\t1 : Afficher le récapitulatif du panier.\t\t\t||\n"); - printf("||\t2 : Ajouter un article au panier.\t\t\t\t||\n"); - printf("||\t3 : Supprimer un article du panier.\t\t\t\t||\n"); - printf("||\t4 : Modifier la quantité d'un article du panier.\t||\n"); - printf("||\t5 : Réinitialiser le panier.\t\t\t\t\t||\n"); - printf("||\t9 : Quitter.\t\t\t\t\t\t\t\t\t||\n"); - printf("+-----------------------------------------------------------------+\n"); + printf("+----------------------------------------------------------------+\n"); + printf("|| Que voulez-vous faire ?\t\t\t\t\t||\n"); + printf("||\t1 : Afficher le récapitulatif du panier.\t \t||\n"); + printf("||\t2 : Ajouter un article au panier. \t\t\t||\n"); + printf("||\t3 : Supprimer un article du panier. \t\t\t||\n"); + printf("||\t4 : Modifier la quantité d'un article du panier. \t||\n"); + printf("||\t5 : Réinitialiser le panier.\t\t\t\t||\n"); + printf("||\t9 : Quitter.\t\t\t\t\t\t||\n"); + printf("+----------------------------------------------------------------+\n"); } /** @@ -111,7 +108,8 @@ void global_client() { switch (choix) { case 1: - affiche_recap_panier(panier, taillePanier, references, poids, volume, prixUnitaire, quantites); + affiche_recap_panier(panier, taillePanier, references, poids, volume, prixUnitaire, quantites, cagnottes, + numeroClient, numeros, nombreClients, volumeCoffre, chargeMaximale); break; case 2: ajouter_article_au_panier(numeroClient, references, poids, volume, prixUnitaire, numeros, cagnottes, @@ -140,6 +138,7 @@ void global_client() { printf("Le montant a été déduit de votre cagnotte.\n"); } + sauvegarde_clients(numeros, cagnottes, suspendus, nombreClients); printf("Au revoir !\n"); return; default: diff --git a/src/app/interface/interface_client.h b/src/app/interface/interface_client.h index 2885394..2ae7dc7 100644 --- a/src/app/interface/interface_client.h +++ b/src/app/interface/interface_client.h @@ -4,6 +4,8 @@ */ #include +#include "../core_logic/client.h" +#include "../core_logic/responsable.h" /** * @brief Affiche le menu principal de l'interface client.