diff --git a/app b/app deleted file mode 100755 index ce451de..0000000 Binary files a/app and /dev/null differ diff --git a/donnee/client.txt b/donnee/client.txt index 9edf4e1..e542074 100644 --- a/donnee/client.txt +++ b/donnee/client.txt @@ -1,4 +1,4 @@ -32 0 0 -660 30.00 0 -5079 75.50 0 -8043 50.50 1 +32 0.00 0 +660 11.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 9f3da5a..d871d19 100644 --- a/src/app/core_logic/client.c +++ b/src/app/core_logic/client.c @@ -34,10 +34,20 @@ void ajouter_article_au_panier(int numeroClient, int references[], float poids[] int numeros[], float cagnottes[], int suspendues[], int nombreArticles, int nombreClients, float volumeCoffre, float chargeMaximale, int panier[], int quantites[], int *taillePanier) { int reference, quantite; + printf("Entrez la référence de l'article : "); - scanf("%d", &reference); + while (scanf("%d", &reference) != 1) { + while (getchar() != '\n'); + printf("ERREUR : Veuillez entrer une référence valide (nombre) : "); + } + while (getchar() != '\n'); + printf("Entrez la quantité : "); - scanf("%d", &quantite); + while (scanf("%d", &quantite) != 1) { + while (getchar() != '\n'); + printf("ERREUR : Veurillez entrer une quantité valide (nombre) : "); + } + while (getchar() != '\n'); int articleIndex = -1; for (int i = 0; i < nombreArticles; i++) { @@ -107,10 +117,14 @@ void ajouter_article_au_panier(int numeroClient, int references[], float poids[] } } -void supprimer_article_du_panier(int panier[], int *taillePanier) { +void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanier) { int reference; printf("Entrez la référence de l'article à supprimer : "); - scanf("%d", &reference); + while (scanf("%d", &reference) != 1) { + while (getchar() != '\n'); + printf("ERREUR : Veuillez entrer une référence valide (nombre) : "); + } + while (getchar() != '\n'); int articleIndex = -1; for (int i = 0; i < *taillePanier; i++) { @@ -127,6 +141,7 @@ void supprimer_article_du_panier(int panier[], int *taillePanier) { for (int i = articleIndex; i < (*taillePanier - 1); i++) { panier[i] = panier[i + 1]; + quantites[i] = quantites[i + 1]; } (*taillePanier)--; @@ -170,4 +185,77 @@ void affiche_recap_panier(int panier[], int taillePanier, int references[], floa printf("Prix total à payer: %.2f euros\n", montantTotal); printf("Volume utilise : %.2f litres\n", volumeTotal); printf("Charge Actuelle: %.2f kg\n", poidsTotal); +} + +void modifier_quantite_article_panier(int panier[], int quantites[], int *taillePanier) { + int reference, quantite; + + printf("Entrez la référence de l'article : "); + while (scanf("%d", &reference) != 1) { + while (getchar() != '\n'); + printf("ERREUR : Veuillez entrer une référence valide (nombre) : "); + } + while (getchar() != '\n'); + + int articleIndex = -1; + for (int i = 0; i < *taillePanier; i++) { + if (panier[i] == reference) { + articleIndex = i; + break; + } + } + + if (articleIndex == -1) { + printf("Article non trouvé dans le panier. Veuillez entrer une référence valide.\n"); + return; + } + + printf("Entrez la quantité : "); + while (scanf("%d", &quantite) != 1) { + while (getchar() != '\n'); + printf("ERREUR : Veuillez entrer une quantité valide (nombre) : "); + } + while (getchar() != '\n'); + + quantites[articleIndex] = quantite; + + printf("Quantité modifiée avec succès.\n"); +} + +void reinitialiser_panier(int panier[], int quantites[], int *taillePanier) { + *taillePanier = 0; + printf("Panier réinitialisé avec succès.\n"); +} + +void deduire_cagnotte(int numeroClient, float montant, int numeros[], float cagnottes[], int nombreClients, int suspendus[]) { + int clientIndex = -1; + for (int i = 0; i < nombreClients; i++) { + if (numeros[i] == numeroClient) { + clientIndex = i; + break; + } + } + + if (clientIndex == -1) { + printf("Client non trouvé. Impossible de déduire la cagnotte.\n"); + return; + } + + if (cagnottes[clientIndex] < montant) { + printf("Cagnotte insuffisante. Impossible de déduire la cagnotte.\n"); + return; + } + + 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 aabe5c8..c7d8bfa 100644 --- a/src/app/core_logic/client.h +++ b/src/app/core_logic/client.h @@ -12,7 +12,11 @@ int charger_clients(int numeros[], float cagnottes[], int suspendues[], int tPhy void ajouter_article_au_panier(int numeroClient, int references[], float poids[], float volume[], float prixUnitaire[], int numeros[], float cagnottes[], int suspendues[], int nombreArticles, int nombreClients, float volumeCoffre, float chargeMaximale, int panier[], int quantites[], int *taillePanier); -void supprimer_article_du_panier(int panier[], int *taillePanier); +void supprimer_article_du_panier(int panier[], int quantites[], int *taillePanier); void affiche_recap_panier(int panier[], int taillePanier, int references[], float poids[], float volume[], float prixUnitaire[], int quantites[]); +void modifier_quantite_article_panier(int panier[], int quantites[], int *taillePanier); +void reinitialiser_panier(int panier[], int quantites[], int *taillePanier); +void deduire_cagnotte(int numeroClient, float montant, int numeros[], float cagnottes[], int nombreClients, int suspendus[]); + #endif //SAE_101_CLIENT_H diff --git a/src/app/interface/interface_client.c b/src/app/interface/interface_client.c index 0e23ffa..54c0f29 100644 --- a/src/app/interface/interface_client.c +++ b/src/app/interface/interface_client.c @@ -5,7 +5,7 @@ #define MAX_ARTICLES 100 #define MAX_CLIENTS 100 -void affiche_client(int a) { +void affiche_client() { printf("\n"); printf("+-------------+ \n"); printf("|| Bonjour ! ||\n"); @@ -14,7 +14,7 @@ void affiche_client(int a) { 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 du panier. \t \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"); @@ -25,13 +25,12 @@ void affiche_client(int a) { /* * Sert à lancer le menu et faire choisir l'utilisateur */ -void menu_client(int *choix, int jour) { - affiche_client(jour); +void menu_client(int *choix) { + affiche_client(); printf("Vous choisissez: "); while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9) { while (getchar() != '\n'); - affiche_client(jour); - printf("Veuillez entrer un choix valide : "); + printf("ERREUR : Veuillez entrer un choix valide : "); } } @@ -55,13 +54,22 @@ void global_client() { nombreClients = charger_clients(numeros, cagnottes, suspendus, MAX_CLIENTS); printf("Veuillez saisir la taille disponible du véhicule (en litres) : "); - scanf("%f", &volumeCoffre); + while (scanf("%f", &volumeCoffre) != 1 || volumeCoffre <= 0) { + while (getchar() != '\n'); + printf("ERREUR : Veuillez entrer une taille de coffre valide (en litres) : "); + } printf("Veuillez saisir la charge maximale autorisée (en kg) : "); - scanf("%f", &chargeMaximale); + while (scanf("%f", &chargeMaximale) != 1 || chargeMaximale <= 0) { + while (getchar() != '\n'); + printf("ERREUR : Veuillez entrer une charge maximale valide (en kg) : "); + } printf("Veuillez saisir votre numéro de client : "); - scanf("%d", &numeroClient); + while (scanf("%d", &numeroClient) != 1) { + while (getchar() != '\n'); + printf("ERREUR : Veuillez entrer un numéro de client valide : "); + } int indexClient = -1; for (int i = 0; i < nombreClients; i++) { @@ -82,7 +90,7 @@ void global_client() { } do{ - menu_client(&choix, jour); + menu_client(&choix); switch (choix) { case 1: @@ -93,9 +101,28 @@ void global_client() { suspendus, nombreArticles, nombreClients, volumeCoffre, chargeMaximale, panier, quantites, &taillePanier); break; case 3: - supprimer_article_du_panier(panier, &taillePanier); + supprimer_article_du_panier(panier, quantites, &taillePanier); + break; + case 4: + modifier_quantite_article_panier(panier, quantites, &taillePanier); + break; + case 5: + reinitialiser_panier(panier, quantites, &taillePanier); break; case 9: + printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : "); + int choixCagnotte; + scanf("%d", &choixCagnotte); + if (choixCagnotte == 1) { + float montant; + printf("Entrez le montant à déduire de votre cagnotte : "); + scanf("%f", &montant); + + deduire_cagnotte(numeroClient, montant, numeros, cagnottes, nombreClients, suspendus); + + printf("Le montant a été déduit de votre cagnotte.\n"); + } + printf("Au revoir !\n"); return; default: @@ -103,4 +130,5 @@ void global_client() { break; } }while(choix != 9); -} \ No newline at end of file +} + diff --git a/src/app/interface/interface_client.h b/src/app/interface/interface_client.h index f091e36..c6d2838 100644 --- a/src/app/interface/interface_client.h +++ b/src/app/interface/interface_client.h @@ -1,5 +1,5 @@ #include -void affiche_client(int a); -void menu_client(int *choix, int a); +void affiche_client(); +void menu_client(int *choix); void global_client(); \ No newline at end of file diff --git a/src/app/interface/interface_resp.c b/src/app/interface/interface_resp.c index f7c7cf3..0b1c23d 100644 --- a/src/app/interface/interface_resp.c +++ b/src/app/interface/interface_resp.c @@ -20,11 +20,9 @@ void affiche_resp(void){ printf("||\t2 : Afficher un article \t \t \t \t || \n"); printf("||\t3 : Afficher un client \t \t \t \t \t || \n"); printf("||\t4 : Afficher les clients \t \t \t \t || \n"); - printf("||\t5 : Ajouter un article \t \t \t \t \t || \n"); - printf("||\t6 : Supprimer un article \t \t \t \t || \n"); - printf("||\t7 : Modifier un article \t \t \t \t || \n"); - printf("||\t8 : Ajouter un client\t \t \t \t \t || \n"); - printf("||\t9 : Quittez. \t \t \t \t \t \t || \n"); + printf("||\t5 : Supprimer un article \t \t \t \t || \n"); + printf("||\t6 : Modifier un article \t \t \t \t || \n"); + printf("||\t7 : Réinitialiser le panier. \t \t \t \t || \n"); printf("+-----------------------------------------------------------------+\n"); } /* @@ -49,10 +47,9 @@ void affiche_resp(int a){ void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique) { printf("\t Liste des articles \n\n"); - printf("\t Ref\t Poids\t Volume\t Prix\n"); for ( int i = 0; i < tLogique; ++i) { - printf("\t %d\t %.2f\t %.2f\t %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]); + printf("\t %d %.2f %.2f %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]); } } @@ -60,17 +57,16 @@ void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], in { int ref; printf("\tQuelle est la référence de l'article à rechercher ?\n"); - while(scanf("%d", &ref) != 1 || ref <= 0) + while(scanf("%d", &ref != 1 || ref <= 0)) { printf("\tEntrez une référence valide\n"); while(getchar() != '\n'); } - printf("\t Ref\t Poids\t Volume\t Prix\n"); for ( int i = 0; i < tLogique; ++i) { if ( ref == tRef[i] ) { - printf("\t %d\t %.2f\t %.2f\t %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]); + printf("\t %d %.2f %.2f %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]); return; } } @@ -86,12 +82,11 @@ void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogiqu printf("\t Veuillez entrez un numéro valide !\n"); while(getchar() != '\n'); } - printf("\t NumClient\t Cagnotte\t Etat\n"); for ( int i = 0; i < tLogique; ++i) { if ( numC == tNumClient[i] ) { - printf("\t %d\t\t %.2f\t %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]); + printf("\t %d %.2f %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]); return; } } @@ -101,52 +96,65 @@ void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogiqu void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique) { printf("\t Liste des clients\n"); - printf("\t NumClient\t Cagnotte\t Etat\n"); for ( int i = 0; i < tLogique; ++i) { - printf("\t %d\t\t %.2f\t\t %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]); + printf("\t %d %.2f %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]); } printf("\t Fin de la liste ! \n"); } void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix) { - printf("\t Entrez la ref du nouveaux produit\n"); - while(scanf("%d", ref) != 1 || *ref <= 0) + printf("Entrez la ref du nouveaux produit\n"); + scanf("%d", ref); + if ( *ref < 0 ) { - printf("\t Veuillez entrer une référence valide.\n"); - while(getchar() != '\n'); + while ( *ref < 0 ) + { + printf("Entrez un nombre correct !\n"); + scanf("%d", ref); + } } - - printf("\t Entrez le poids du nouveaux produit\n"); - while(scanf("%f", poids) != 1 || *poids <= 0) + printf("Entrez le poids du nouveaux produit\n"); + scanf("%f", poids); + if ( *poids < 0 ) { - printf("\t Veuillez entrer un poids valide.\n"); - - while(getchar() != '\n'); + while ( *poids < 0 ) + { + printf("Entrez un nombre correct !\n"); + scanf("%f", poids); + } } - - printf("\t Entrez le volume du nouveaux produit\n"); - while(scanf("%f", volume) != 1 || *volume <= 0) + printf("Entrez le volume du nouveaux produit\n"); + scanf("%f", volume); + if ( *volume < 0 ) { - printf("\t Veuillez entrer un volume valide.\n"); - while(getchar() != '\n'); + while ( *volume < 0 ) + { + printf("Entrez un poids correct !\n"); + scanf("%f", poids); + } } - - printf("\t Entrez le prix du nouveaux produit\n"); - while(scanf("%f", prix) != 1 || *prix <= 0) + printf("Entrez le prix du nouveaux produit\n"); + scanf("%f", prix); + if ( *prix < 0 ) { - printf("\t Veuillez entrer un prix valide.\n"); - while(getchar() != '\n'); + while ( *prix < 0 ) + { + printf("Entrez un prix correct !\n"); + scanf("%f", prix); + } } } + + void affichSupprimerArticle(int *ref) { printf("\t Quel est la référence de l'article voulez-vous supprimez\n"); - while(scanf("%d", ref ) != 1 || *ref <= 0) + while(scanf("%d", ref == 1 || *ref <= 0)) { - printf("\t Veuillez entrer une référence valide.\n"); + printf("\t Veuillez entrer une référence valide."); while(getchar() != '\n'); } } @@ -165,43 +173,25 @@ void affichModifierArticle(int *ref, float *poids, float *volume, float *prix) printf("\t Quel est le nouveau poids à entrer ?\n"); while(scanf("%f", poids) != 1 || *poids <= 0) { - printf("\t Veuillez entrer un poids correct !\n"); + printf("\t Veuillez entrer un poids correct !"); while (getchar() != '\n'); } printf("\t Quel est le nouveau volume à entrer ?\n"); while(scanf("%f", volume) != 1 || *volume <= 0) { - printf("\t Veuillez entrer un volume correct !\n"); + printf("\t Veuillez entrer un volume correct !"); while (getchar() != '\n'); } printf("\t Quel est le nouveau prix à entrer ?\n"); while(scanf("%f", prix) != 1 || *prix <= 0) { - printf("\t Veuillez entrer un prix correct !\n"); + printf("\t Veuillez entrer un prix correct !"); while (getchar() != '\n'); } } -void affichAjoutClient(int tNumClient[], int tLogique, int *numC) -{ - printf("\t Veuillez entrer le numéro du nouveau client\n"); - while(scanf("%d", numC) != 1 || *numC <= 0) - { - printf("Entrez un numéro valide !\n"); - while(getchar() != '\n'); - } - for ( int i = 0 ; i < tLogique; ++i) - { - if ( *numC == tNumClient[i] ) - { - fprintf(stderr,"\t Client déjà existant.\n"); - return; - } - } -} - /* void menu_resp(int *choix, int jour) { affiche_resp(); @@ -219,7 +209,7 @@ void menu_resp(int *choix) { affiche_resp(); //affiche_resp(jour); printf("Vous choisissez: "); - while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9) { + while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) { while (getchar() != '\n'); affiche_resp(); printf("Veuillez entrer un choix valide : "); @@ -227,8 +217,7 @@ void menu_resp(int *choix) { } void global_resp(){ - int choix, ref = 0; - float poids = 0, volume = 0 , prix = 0; + int choix, a; int tRef[MAX_ARTICLES]; float tPoids[MAX_ARTICLES]; float tVol[MAX_ARTICLES]; @@ -240,43 +229,31 @@ void global_resp(){ int tLogArticle = chargementArticles(tRef, tPoids, tVol, tPrix, MAX_ARTICLES); int tLogClient = charger_clients(tNumClient, tCagnotte, tSus, MAX_CLIENTS); - do { - - - menu_resp(&choix); - switch (choix) { - case 1: - affichArticles(tRef, tPoids, tVol, tPrix, tLogArticle); - break; - case 2: - affichUnArticle(tRef, tPoids, tVol, tPrix, tLogArticle); - break; - case 3: - affichUnClient(tNumClient, tCagnotte, tSus, tLogClient); - break; - case 4: - affichClients(tNumClient, tCagnotte, tSus, tLogClient); - break; - case 5: - ajouterArticle(tRef, tPoids, tVol, tPrix, &tLogArticle, MAX_ARTICLES, ref, poids, volume, prix); - break; - case 6: - supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle); - break; - case 7: - modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle); - break; - case 8: - ajouterClient(tNumClient, tCagnotte, tSus, &tLogClient, MAX_CLIENTS); - break; - case 9: - sauvegardArticles(tRef, tPoids, tVol, tPrix, tLogArticle); - affichArticles(tRef, tPoids, tVol, tPrix, tLogArticle); - return; - default: - printf("Veuillez entrer un choix valide ! \n"); - break; - } - } while (choix != 9); - + menu_resp(&choix); + switch (choix) { + case 1: + affichArticles(tRef, tPoids, tVol, tPrix, tLogArticle); + break; + case 2: + affichUnArticle(tRef, tPoids, tVol, tPrix, tLogArticle); + break; + case 3: + affichUnClient(tNumClient, tCagnotte, tSus, tLogClient); + break; + case 4: + affichClients(tNumClient, tCagnotte, tSus, tLogClient); + break; + case 5: + modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle); + break; + case 6: + supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle); + break; + case 7: + printf("Ouai tkt ^^'"); + break; + default: + printf("Veuillez entrer un choix valide ! \n"); + break; + } } \ No newline at end of file diff --git a/src/app/interface/interface_resp.h b/src/app/interface/interface_resp.h index 6b9826c..b793ad2 100644 --- a/src/app/interface/interface_resp.h +++ b/src/app/interface/interface_resp.h @@ -5,8 +5,6 @@ void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix); void affichSupprimerArticle(int *ref); void affichModifierArticle(int *ref, float *poids, float *volume, float *prix); -void problemRechercheArticle(); -void affichAjoutClient(int tNumClient[], int tLogique, int *numC); void menu_resp(int *choix); void global_resp(); void affiche_resp(void); \ No newline at end of file diff --git a/src/main.c b/src/main.c index 64b8b3a..3910ccf 100644 --- a/src/main.c +++ b/src/main.c @@ -10,31 +10,30 @@ int choixInterface(void) { printf("Choix de l'interface: \n"); printf("1. Interface 'responsable': Pour les responsables \n"); printf("2. Interface 'Client' : Pour les clients\n"); - printf("Vous choisissez l'interface n°: "); - scanf("%d", &choix); - if (choix < 0 || choix > 2) { - fprintf(stderr,"Veuillez entrer un choix valide ! \n"); + + while (1) { + printf("Vous choisissez l'interface n°: "); + if (scanf("%d", &choix) != 1 || (choix < 1 || choix > 2)) { + printf("ERREUR : Veuillez entrer un choix valide (1 ou 2) : "); + while (getchar() != '\n'); + } else { + break; + } } + switch (choix) { - case 1: - printf("Vous avez choisit l'interface responsable.\n"); - break; - case 2: - printf("Vous avez choisit l'interface client.\n"); - break; + case 1: printf("Vous avez choisi l'interface responsable.\n"); break; + case 2: printf("Vous avez choisi l'interface client.\n"); break; } + return choix; } int main(){ switch (choixInterface()) { - case 1: - global_resp(); - break; - case 2: - global_client(); - break; + case 1: global_resp(); + case 2: global_client(); } return 0; -} +} \ No newline at end of file