client #13

Merged
matheo.hersan merged 20 commits from client into master 2 years ago

@ -80,3 +80,8 @@ Lorsqu'un utilisateur décide de quitter l'application, plusieurs scénarios son
Ces fonctionnalités garantissent que l'application aide les utilisateurs à gérer leur budget et à utiliser leur cagnotte de manière efficace pour éviter les problèmes financiers. Ces fonctionnalités garantissent que l'application aide les utilisateurs à gérer leur budget et à utiliser leur cagnotte de manière efficace pour éviter les problèmes financiers.
## Traces d'exécution :
Voici les traces d'execution pour la partie **client** :
Tout d'abord les cas ou le client n'a pas de carte suspendu et choisis un budget:

@ -1,4 +1,4 @@
32 0.00 1 32 69.00 1
660 61.00 0 660 5351.40 0
5079 75.50 0 5079 75.50 0
53 0.00 0 53 0.00 0

@ -81,3 +81,19 @@ void supprimer_article(int tPanier[], int tQuantite[], int *tLogPanier, int refe
tCagnotte[clientIndex] -= 0.1 * montantTotal; tCagnotte[clientIndex] -= 0.1 * montantTotal;
} }
} }
void verifInt(int *var) {
while (scanf("%d", var) != 1 || *var < 0) {
fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer une valeur valide (entier positif) :\x1B[0m ");
while (getchar() != '\n');
}
while (getchar() != '\n');
}
void verifFloat(float *var) {
while (scanf("%f", var) != 1 || *var < 0) {
fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer une valeur valide (valeur positive) :\x1B[0m ");
while (getchar() != '\n');
}
}

@ -74,5 +74,18 @@ int trouver_index_client(int numClient, int tNumClient[], int tLogClient);
*/ */
void supprimer_article(int tPanier[], int tQuantite[], int *tLogPanier, int reference, int numClient, int tNumClient[], int tLogClient, int tRef[], float tPrixUnitaire[], float tCagnotte[]); void supprimer_article(int tPanier[], int tQuantite[], int *tLogPanier, int reference, int numClient, int tNumClient[], int tLogClient, int tRef[], float tPrixUnitaire[], float tCagnotte[]);
/**
* @brief Vérifie l'entrée utilisateur pour un entier.
*
* @param var une variable de type int
*/
void verifInt(int *var);
/**
* @brief Vérifie l'entrée utilisateur pour un float.
*
* @param var une variable de type float
*/
void verifFloat(float *var);
#endif // CLIENT_H #endif // CLIENT_H

@ -181,7 +181,7 @@ void chiffrementCesar(char *mdp, int decalage) {
int i; int i;
int longueur = strlen(mdp); int longueur = strlen(mdp);
for (i = 0; i < longueur; ++i) for (i = 0; i < longueur; ++i)
{ {
if (mdp[i] >= 'a' && mdp[i] <= 'z') { if (mdp[i] >= 'a' && mdp[i] <= 'z') {
mdp[i] = 'a' + (mdp[i] - 'a' + decalage) % 26; mdp[i] = 'a' + (mdp[i] - 'a' + decalage) % 26;
} else if (mdp[i] >= 'A' && mdp[i] <= 'Z') } else if (mdp[i] >= 'A' && mdp[i] <= 'Z')
@ -277,6 +277,6 @@ void suppressionReduc(int tRefReduc[], int tReduc[], int *tLogReduc, int tRef[],
--(*tLogReduc); --(*tLogReduc);
indexPrix = trouver_index_article(ref, tRef, tLogArticle); indexPrix = trouver_index_article(ref, tRef, tLogArticle);
tPrix[indexPrix] = retrouvePrix(tPrix[indexPrix], tReduc[indexReduc]); tPrix[indexPrix] = retrouvePrix(tPrix[indexPrix], tReduc[indexReduc]);
} }

@ -20,9 +20,8 @@ void affiche_client(void) {
printf("+----------------------------------------------------------------+\n"); printf("+----------------------------------------------------------------+\n");
} }
void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float tVol[], float tPrixUnitaire[], void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float tVol[], float tPrixUnitaire[],
int tNumClient[], float tCagnotte[], int tSus[], int tLogArticle, int tLogClient, int tNumClient[], float tCagnotte[], int tLogArticle, int tLogClient,
float volumeCoffre, float chargeMaximale, int tPanier[], int tQuantite[], int *tLogPanier, float budget) { float volumeCoffre, float chargeMaximale, int tPanier[], int tQuantite[], int *tLogPanier, float budget) {
int reference, quantite, articleIndex, clientIndex; int reference, quantite, articleIndex, clientIndex;
@ -30,33 +29,24 @@ void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float
printf("Entrez la référence de l'article : "); printf("Entrez la référence de l'article : ");
while (scanf("%d", &reference) != 1) { verifInt(&reference);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une référence valide (nombre) : ");
}
while (getchar() != '\n');
articleIndex = trouver_index_article(reference, tRef, tLogArticle); articleIndex = trouver_index_article(reference, tRef, tLogArticle);
while (articleIndex == -1) { while (articleIndex == -1) {
printf("ERREUR : Article non trouvé. Veuillez entrer une référence valide : "); fprintf(stderr, "\x1B[31mERREUR : Article non trouvé. Veuillez entrer une référence valide :\x1B[0m ");
while(scanf("%d", &reference) != 1) { verifInt(&reference);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une référence valide (nombre) : ");
}
articleIndex = trouver_index_article(reference, tRef, tLogArticle); articleIndex = trouver_index_article(reference, tRef, tLogArticle);
} }
printf("Entrez la quantité : "); printf("Entrez la quantité : ");
while (scanf("%d", &quantite) != 1) { verifInt(&quantite);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une quantité valide (nombre) : ");
}
while (getchar() != '\n');
poidsTotal = tPoids[articleIndex] * quantite; poidsTotal = tPoids[articleIndex] * (float)quantite;
volumeTotal = tVol[articleIndex] * quantite; volumeTotal = tVol[articleIndex] * (float)quantite;
montantTotal = tPrixUnitaire[articleIndex] * quantite; montantTotal = tPrixUnitaire[articleIndex] * (float)quantite;
if (poidsTotal > chargeMaximale) { if (poidsTotal > chargeMaximale) {
depassementCharge = poidsTotal - chargeMaximale; depassementCharge = poidsTotal - chargeMaximale;
@ -70,21 +60,7 @@ void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float
depassementBudget = montantTotal - budget; depassementBudget = montantTotal - budget;
} }
if (depassementCharge || depassementVolume || depassementBudget) { montantTotal = tPrixUnitaire[articleIndex] * (float)quantite;
printf("Attention : \n");
if (depassementCharge) {
printf("\tDépassement de la charge autorisée de %.2f kg \n", depassementCharge);
}
if (depassementVolume) {
printf("\tDépassement du volume autorisé de %.2f litres \n", depassementVolume);
}
if (depassementBudget) {
printf("\tDépassement du budget autorisé de %.2f euros \n", depassementBudget);
}
printf("\n");
}
montantTotal = tPrixUnitaire[articleIndex] * quantite;
clientIndex = trouver_index_client(numClient, tNumClient, tLogClient); clientIndex = trouver_index_client(numClient, tNumClient, tLogClient);
@ -102,46 +78,44 @@ void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float
} }
printf("\n"); printf("\n");
printf("Référence : %d\nQuantité : %d\n", reference, quantite); if(depassementBudget < 0 || depassementCharge < 0 || depassementVolume < 0) {
printf("Récap :\n"); printf("Référence : %d\nQuantité : %d\n", reference, quantite);
printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot Cagnotte\n"); printf("Récap :\n");
printf("%d %d %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n", printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot Cagnotte\n");
reference, quantite, tPoids[articleIndex], tVol[articleIndex], printf("%d %d %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",
tPrixUnitaire[articleIndex], poidsTotal, volumeTotal, montantTotal, reference, quantite, tPoids[articleIndex], tVol[articleIndex],
tCagnotte[clientIndex]); tPrixUnitaire[articleIndex], poidsTotal, volumeTotal, montantTotal,
printf("Prix total à payer: %.2f euros\n", montantTotal); tCagnotte[clientIndex]);
printf("Cagnotte totale : %.2f euros\n", tCagnotte[clientIndex]); printf("Prix total à payer: %.2f euros\n", montantTotal);
printf("Volume utilise : %.2f litres\n", volumeTotal); printf("Cagnotte totale : %.2f euros\n", tCagnotte[clientIndex]);
printf("Volume restant : %.2f litres\n", volumeCoffre - volumeTotal); printf("Volume utilise : %.2f litres\n", volumeTotal);
printf("Charge Actuelle: %.2f kg\n", poidsTotal); printf("Volume restant : %.2f litres\n", volumeCoffre - volumeTotal);
printf("Charge restante: %.2f kg\n", chargeMaximale - poidsTotal); printf("Charge Actuelle: %.2f kg\n", poidsTotal);
printf("Charge restante: %.2f kg\n", chargeMaximale - poidsTotal);
} else {
affiche_recap_panier(tPanier, *tLogPanier, tRef, tPoids, tVol, tPrixUnitaire, tQuantite, tCagnotte, numClient, tNumClient, tLogClient, volumeCoffre, chargeMaximale, budget);
}
} }
void supprimer_article_du_panier(int tPanier[], int tQuantite[], int *tLogPanier, float tCagnotte[], int numClient, int tNumClient[], int tLogClient, int tRef[], float tPrixUnitaire[]) { void supprimer_article_du_panier(int tPanier[], int tQuantite[], int *tLogPanier, float tCagnotte[], int numClient, int tNumClient[], int tLogClient, int tRef[], float tPrixUnitaire[]) {
int reference, articleIndex; int reference, articleIndex;
printf("Entrez la référence de l'article à supprimer : "); printf("Entrez la référence de l'article à supprimer : ");
while (scanf("%d", &reference) != 1) { verifInt(&reference);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une référence valide (nombre) : ");
}
while (getchar() != '\n');
articleIndex = trouver_index_article(reference, tRef, MAX_ARTICLES); articleIndex = trouver_index_article(reference, tPanier, *tLogPanier);
while (articleIndex == -1) { while (articleIndex == -1) {
printf("Article non trouvé dans le panier. Veuillez entrer une référence valide : "); fprintf(stderr, "\x1B[31mERREUR : Article non trouvé dans le panier. Veuillez entrer une référence valide :\x1B[0m ");
while(scanf("%d", &reference) != 1) { verifInt(&reference);
while (getchar() != '\n'); articleIndex = trouver_index_article(reference, tPanier, *tLogPanier);
printf("ERREUR : Veuillez entrer une référence valide (nombre) : ");
}
articleIndex = trouver_index_article(reference, tRef, MAX_ARTICLES);
} }
supprimer_article(tPanier, tQuantite, tLogPanier, reference, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire, tCagnotte); supprimer_article(tPanier, tQuantite, tLogPanier, reference, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire, tCagnotte);
printf("Article supprimé du panier avec succès.\n"); printf("\033[32mArticle supprimé du panier avec succès.\033[0m\n");
} }
@ -153,12 +127,6 @@ void affiche_recap_panier(int tPanier[], int tLogPanier, int tRef[], float tPoid
float poidsTotal = 0, volumeTotal = 0, montantTotal = 0, prixArticle = 0, poidsArticle = 0, volumeArticle = 0; float poidsTotal = 0, volumeTotal = 0, montantTotal = 0, prixArticle = 0, poidsArticle = 0, volumeArticle = 0;
char attentionDepassement[200] = ""; char attentionDepassement[200] = "";
printf("Contenu du panier : ");
for (int i = 0; i < tLogPanier; i++) {
printf("%d ", tPanier[i]);
}
printf("\n");
printf("Récap :\n"); printf("Récap :\n");
printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot\n"); printf("Réf Qté Poids Vol PrixU PoidsTot VolTot PrixTot\n");
@ -173,11 +141,11 @@ void affiche_recap_panier(int tPanier[], int tLogPanier, int tRef[], float tPoid
printf("%d\t %d\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\n", printf("%d\t %d\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\n",
reference, quantite, poidsArticle, volumeArticle, reference, quantite, poidsArticle, volumeArticle,
prixArticle, poidsArticle * quantite, volumeArticle * quantite, prixArticle * quantite); prixArticle, poidsArticle * (float)quantite, volumeArticle * (float)quantite, prixArticle * (float)quantite);
poidsTotal += poidsArticle * quantite; poidsTotal += poidsArticle * (float)quantite;
volumeTotal += volumeArticle * quantite; volumeTotal += volumeArticle * (float)quantite;
montantTotal += prixArticle * quantite; montantTotal += prixArticle * (float)quantite;
if (poidsTotal > chargeMaximale) { if (poidsTotal > chargeMaximale) {
float depassement = poidsTotal - chargeMaximale; float depassement = poidsTotal - chargeMaximale;
@ -207,7 +175,8 @@ void affiche_recap_panier(int tPanier[], int tLogPanier, int tRef[], float tPoid
printf("Charge Actuelle: %.2f kg\n", poidsTotal); printf("Charge Actuelle: %.2f kg\n", poidsTotal);
if (strlen(attentionDepassement) > 0) { if (strlen(attentionDepassement) > 0) {
printf("Attention : %s", attentionDepassement); printf("Attention : \n");
printf("%s", attentionDepassement);
} }
} }
@ -215,19 +184,14 @@ void configurer_session_client(int tNumClient[], int tLogClient, double *budget,
int indexClient, choixBudget = 0; int indexClient, choixBudget = 0;
printf("Veuillez saisir votre numéro de client : "); printf("Veuillez saisir votre numéro de client : ");
while (scanf("%d", numClient) != 1) { verifInt(numClient);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer un numéro de client valide : ");
}
indexClient = trouver_index_client(*numClient, tNumClient, tLogClient); indexClient = trouver_index_client(*numClient, tNumClient, tLogClient);
while (indexClient == -1) { while (indexClient == -1) {
printf("ERREUR : Veuillez entrer un numéro de client valide : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un numéro de client valide :\x1B[0m ");
while (scanf("%d", numClient) != 1) { verifInt(numClient);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer un numéro de client valide : ");
}
indexClient = trouver_index_client(*numClient, tNumClient, tLogClient); indexClient = trouver_index_client(*numClient, tNumClient, tLogClient);
} }
@ -235,28 +199,22 @@ void configurer_session_client(int tNumClient[], int tLogClient, double *budget,
printf("Voulez-vous définir un budget à ne pas dépasser ? (1 pour Oui, 0 pour Non) : "); printf("Voulez-vous définir un budget à ne pas dépasser ? (1 pour Oui, 0 pour Non) : ");
while (scanf("%d", &choixBudget) != 1 || (choixBudget != 0 && choixBudget != 1)) { while (scanf("%d", &choixBudget) != 1 || (choixBudget != 0 && choixBudget != 1)) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non :\x1B[0m ");
} }
if (choixBudget == 1) { if (choixBudget == 1) {
printf("Entrez le budget à ne pas dépasser : "); printf("Entrez le budget à ne pas dépasser : ");
while (scanf("%lf", budget) != 1 || *budget <= 0) { while (scanf("%lf", budget) != 1 || *budget <= 0) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer un budget valide (nombre positif) : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un budget valide (nombre positif) :\x1B[0m ");
} }
} }
printf("Veuillez saisir la taille disponible du véhicule (en litres) : "); printf("Veuillez saisir la taille disponible du véhicule (en litres) : ");
while (scanf("%f", volumeCoffre) != 1 || *volumeCoffre <= 0) { verifFloat(volumeCoffre);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une taille de coffre valide (en litres) : ");
}
printf("Veuillez saisir la charge maximale autorisée (en kg) : "); printf("Veuillez saisir la charge maximale autorisée (en kg) : ");
while (scanf("%f", chargeMaximale) != 1 || *chargeMaximale <= 0) { verifFloat(chargeMaximale);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une charge maximale valide (en kg) : ");
}
} }
void modifier_quantite_article_panier(int tPanier[], int tQuantite[], int *tLogPanier, float tCagnotte[], int numClient, float tPrixUnitaire[], int tRef[], int tLogClient, int tNumClient[]) { void modifier_quantite_article_panier(int tPanier[], int tQuantite[], int *tLogPanier, float tCagnotte[], int numClient, float tPrixUnitaire[], int tRef[], int tLogClient, int tNumClient[]) {
@ -265,30 +223,18 @@ void modifier_quantite_article_panier(int tPanier[], int tQuantite[], int *tLogP
float prixArticle = 0, ancienneQuantite = 0; float prixArticle = 0, ancienneQuantite = 0;
printf("Entrez la référence de l'article : "); printf("Entrez la référence de l'article : ");
while (scanf("%d", &reference) != 1) { verifInt(&reference);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une référence valide (nombre) : ");
}
while (getchar() != '\n');
articleIndex = trouver_index_article(reference, tPanier, *tLogPanier); articleIndex = trouver_index_article(reference, tPanier, *tLogPanier);
while (articleIndex == -1) { while (articleIndex == -1) {
printf("Article non trouvé dans le panier. Veuillez entrer une référence valide : "); fprintf(stderr, "\x1B[31mERREUR : Article non trouvé dans le panier. Veuillez entrer une référence valide :\x1B[0m ");
while (scanf("%d", &reference) != 1) { verifInt(&reference);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une référence valide (nombre) : ");
}
articleIndex = trouver_index_article(reference, tPanier, *tLogPanier); articleIndex = trouver_index_article(reference, tPanier, *tLogPanier);
} }
printf("Entrez la quantité : "); printf("Entrez la quantité : ");
while (scanf("%d", &quantite) != 1 || quantite <= 0) { verifInt(&quantite);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer une quantité valide (nombre) : ");
}
while (getchar() != '\n');
// Mettre à jour la cagnotte en fonction du changement de quantité // Mettre à jour la cagnotte en fonction du changement de quantité
prixArticle = tPrixUnitaire[trouver_index_article(reference, tRef, MAX_ARTICLES)]; prixArticle = tPrixUnitaire[trouver_index_article(reference, tRef, MAX_ARTICLES)];
@ -298,7 +244,7 @@ void modifier_quantite_article_panier(int tPanier[], int tQuantite[], int *tLogP
tQuantite[articleIndex] = quantite; tQuantite[articleIndex] = quantite;
printf("Quantité modifiée avec succès.\n"); printf("\033[32mQuantité modifiée avec succès.\033[0m\n");
} }
void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float tCagnotte[], int numClient, int tNumClient[], int tLogClient, int tRef[], float tPrixUnitaire[]) { void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float tCagnotte[], int numClient, int tNumClient[], int tLogClient, int tRef[], float tPrixUnitaire[]) {
@ -306,48 +252,63 @@ void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float
supprimer_article(tPanier, tQuantite, tLogPanier, tPanier[i], numClient, tNumClient, tLogClient, tRef, tPrixUnitaire, tCagnotte); supprimer_article(tPanier, tQuantite, tLogPanier, tPanier[i], numClient, tNumClient, tLogClient, tRef, tPrixUnitaire, tCagnotte);
} }
*tLogPanier = 0; *tLogPanier = 0;
printf("\033[32mLe panier a été réinitialisé avec succès.\033[0m\n");
} }
void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient, int tSus[]) { void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient) {
int clientIndex = -1; int clientIndex;
for (int i = 0; i < tLogClient; i++) {
if (tNumClient[i] == numClient) { clientIndex = trouver_index_client(numClient, tNumClient, tLogClient);
clientIndex = i;
break;
}
}
if (clientIndex == -1) { if (clientIndex == -1) {
printf("Client non trouvé. Impossible de déduire la cagnotte.\n"); fprintf(stderr, "\x1B[31mERREUR : Client non trouvé. Impossible de déduire la cagnotte.\x1B[0m\n ");
return; return;
} }
if (tCagnotte[clientIndex] < montant) { if (tCagnotte[clientIndex] < montant) {
printf("Cagnotte insuffisante. Impossible de déduire la cagnotte.\n"); fprintf(stderr, "\x1B[31mERREUR : Cagnotte insuffisante. Impossible de déduire la cagnotte.\x1B[0m\n ");
return; return;
} }
tCagnotte[clientIndex] -= montant; tCagnotte[clientIndex] -= montant;
printf("Montant déduit de la cagnotte avec succès.\n"); printf("\033[32mMontant déduit de la cagnotte avec succès.\033[0m\n");
printf("Il vous reste %.2f euros dans votre cagnotte.\n", tCagnotte[clientIndex]);
} }
void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[], void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[],
float tPrixUnitaire[], int tQuantite[], float tCagnotte[], int numClient, float tPrixUnitaire[], int tQuantite[], float tCagnotte[], int numClient,
int tNumClient[], int tLogClient, float budget, int tSus[]) { int tNumClient[], int tLogClient, float budget, int tSus[], float volumeCoffre, float chargeMaximale) {
int reference, articleIndex, quantite, clientIndex, choixCagnotte = 0; int reference, articleIndex, quantite, clientIndex, choixCagnotte = 0;
float montantTotal = 0, prixArticle = 0, montantDeduction = 0, depassement = 0; float montantTotal = 0, prixArticle = 0, montantDeduction = 0, depassement = 0 , poidsTotal = 0, volumeTotal = 0, poidsArticle = 0, volumeArticle = 0;
char attentionDepassement[200] = ""; char attentionDepassement[200] = "";
for (int i = 0; i < tLogPanier; i++) { for (int i = 0; i < tLogPanier; i++) {
reference = tPanier[i]; reference = tPanier[i];
articleIndex = trouver_index_article(reference, tRef, MAX_ARTICLES); articleIndex = trouver_index_article(reference, tRef, MAX_ARTICLES);
poidsArticle = tPoid[articleIndex];
volumeArticle = tVol[articleIndex];
prixArticle = tPrixUnitaire[articleIndex]; prixArticle = tPrixUnitaire[articleIndex];
quantite = tQuantite[i]; quantite = tQuantite[i];
montantTotal += prixArticle * quantite; poidsTotal += poidsArticle * (float)quantite;
volumeTotal += volumeArticle * (float)quantite;
montantTotal += prixArticle * (float)quantite;
if (poidsTotal > chargeMaximale) {
depassement = poidsTotal - chargeMaximale;
char message[100];
sprintf(message, "Dépassement de la charge autorisée de %.2f kg.\n", depassement);
strcat(attentionDepassement, message);
}
if (volumeTotal > volumeCoffre) {
depassement = volumeTotal - volumeCoffre;
char message[100];
sprintf(message, "Dépassement du volume autorisé de %.2f litres.\n", depassement);
strcat(attentionDepassement, message);
}
if (budget > 0 && montantTotal > budget) { if (budget > 0 && montantTotal > budget) {
depassement = montantTotal - budget; depassement = montantTotal - budget;
@ -359,71 +320,97 @@ void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[
clientIndex = trouver_index_client(numClient, tNumClient, tLogClient); clientIndex = trouver_index_client(numClient, tNumClient, tLogClient);
if (tSus[clientIndex] == 1) {
printf("Vous ne pourrez pas utiliser votre cagnotte car votre carte est suspendu.\n");
}
printf("Prix total à payer: %.2f euros\n", montantTotal); printf("Prix total à payer: %.2f euros\n", montantTotal);
if (budget > 0) { if (budget > 0) {
printf("Budget : %.2f euros\n", budget); printf("Budget : %.2f euros\n", budget);
} }
printf("Volume utilise : %.2f litres\n", volumeTotal);
printf("Charge Actuelle: %.2f kg\n", poidsTotal);
if(volumeTotal > volumeCoffre) {
printf("Attention : %s", attentionDepassement);
printf("Vous ne pourrez pas payer. De plus vous ne pourrez pas utiliser votre cagnotte car votre coffre est plein.\n");
printf("Payement non effectué.\n");
return;
}
if(poidsTotal > chargeMaximale) {
printf("Attention : %s", attentionDepassement);
printf("Vous ne pourrez pas payer. De plus vous ne pourrez pas utiliser votre cagnotte car votre coffre est plein.\n");
printf("Payement non effectué.\n");
return;
}
if(tSus[clientIndex] == 1 && budget > 0 && montantTotal > budget) {
printf("Attention : %s", attentionDepassement);
printf("Vous ne pourrez pas payer. De plus vous ne pourrez pas utiliser votre cagnotte car votre carte est suspendu.\n");
printf("Payement non effectué.\n");
return;
}
if(tSus[clientIndex] == 1 && budget > 0 && montantTotal < budget) {
printf("Vous ne pourrez pas utiliser votre cagnotte car votre carte est suspendu.\n");
printf("Payement effectué.\n");
return;
}
if(tSus[clientIndex] == 1) {
printf("Vous ne pourrez pas utiliser votre cagnotte car votre carte est suspendu.\n");
printf("Payement effectué.\n");
return;
}
if(tSus[clientIndex] == 0) {
printf("Cagnotte totale : %.2f euros\n", tCagnotte[clientIndex]);
}
if (budget > 0 && montantTotal > budget && tCagnotte[clientIndex] < (montantTotal - budget)) { if (budget > 0 && montantTotal > budget && tCagnotte[clientIndex] < (montantTotal - budget)) {
printf("Attention : %s", attentionDepassement); printf("Attention : %s", attentionDepassement);
printf("Vous ne pourrez pas payer. De plus vous n'avez pas assez dans votre cagnotte pour la déduire et payer\n"); printf("Vous ne pourrez pas payer. De plus vous n'avez pas assez dans votre cagnotte pour la déduire et payer\n");
printf("Montant de votre cagnotte %.2f\n", tCagnotte[clientIndex]);
} }
if (budget > 0 && montantTotal > budget && montantTotal < budget + tCagnotte[clientIndex]) { if (budget > 0 && montantTotal > budget && montantTotal < budget + tCagnotte[clientIndex]) {
printf("Attention : %s", attentionDepassement); printf("Attention : %s", attentionDepassement);
printf("Vous ne pourrez pas payer, mais vous avez suffisamment dans votre cagnotte pour payer.\n"); printf("Vous ne pourrez pas payer, mais vous avez suffisamment dans votre cagnotte pour déduire le prix.\n");
printf("Montant de votre cagnotte %.2f\n", tCagnotte[clientIndex]);
printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : "); printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : ");
while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) { while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non :\x1B[0m ");
} }
if (choixCagnotte == 1) { if (choixCagnotte == 1) {
printf("Entrez le montant à déduire de votre cagnotte : "); printf("Entrez le montant à déduire de votre cagnotte : ");
while (scanf("%f", &montantDeduction) != 1) { verifFloat(&montantDeduction);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer un montant valide (nombre) : ");
}
while (getchar() != '\n');
while (montantDeduction < (montantTotal - budget)) { while (montantDeduction < (montantTotal - budget)) {
printf("ERREUR : Vous devez déduire suffisamment pour payer l'intégralité du montant dû.\n"); fprintf(stderr, "\x1B[31mERREUR : Vous devez déduire suffisamment pour payer l'intégralité du montant dû.\x1B[0m\n");
printf("Montant minimum à déduire pour payer : %.2f\n", montantTotal - budget); printf("Montant minimum à déduire pour payer : %.2f\n", montantTotal - budget);
printf("Entrez le montant à déduire de votre cagnotte : "); printf("Entrez le montant à déduire de votre cagnotte : ");
while (scanf("%f", &montantDeduction) != 1) { verifFloat(&montantDeduction);
while (getchar() != '\n');
printf("ERREUR : Veuillez entrer un montant valide (nombre) : ");
}
while (getchar() != '\n');
} }
deduire_cagnotte(numClient, montantDeduction, tNumClient, tCagnotte, tLogClient);
deduire_cagnotte(numClient, montantDeduction, tNumClient, tCagnotte, tLogClient, tSus); printf("Payement effectué.\n");
printf("Il vous reste %.2f euros dans votre cagnotte.\n", tCagnotte[clientIndex]); return;
} else {
printf("Payement non effectué.\n");
return;
} }
} }
printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : "); printf("Voulez-vous déduire de votre cagnotte avant de quitter ? (1 pour Oui, 0 pour Non) : ");
while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) { while (scanf("%d", &choixCagnotte) != 1 || (choixCagnotte != 0 && choixCagnotte != 1)) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer 1 pour Oui ou 0 pour Non :\x1B[0m ");
} }
if (choixCagnotte == 1) { if (choixCagnotte == 1) {
printf("Entrez le montant à déduire de votre cagnotte : "); printf("Entrez le montant à déduire de votre cagnotte : ");
while (scanf("%f", &montantDeduction) != 1) { verifFloat(&montantDeduction);
while (getchar() != '\n'); deduire_cagnotte(numClient, montantDeduction, tNumClient, tCagnotte, tLogClient);
printf("ERREUR : Veuillez entrer un montant valide (nombre) : "); printf("Payement effectué.\n");
} } else {
while (getchar() != '\n'); printf("Payement effectué.\n");
deduire_cagnotte(numClient, montantDeduction, tNumClient, tCagnotte, tLogClient, tSus);
printf("Il vous reste %.2f euros dans votre cagnotte.\n", tCagnotte[clientIndex]);
} }
} }
@ -432,16 +419,16 @@ void menu_client(int *choix) {
printf("Vous choisissez: "); printf("Vous choisissez: ");
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9 || (*choix > 6 && *choix < 9)) { while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 9 || (*choix > 6 && *choix < 9)) {
while (getchar() != '\n'); while (getchar() != '\n');
printf("ERREUR : Veuillez entrer un choix valide : "); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un choix valide :\x1B[0m ");
} }
} }
void global_client(void) { void global_client(void) {
int choix, tRef[MAX_ARTICLES], tNumClient[MAX_CLIENTS], tSus[MAX_CLIENTS], tLogArticle, tLogClient, int choix, tRef[MAX_ARTICLES], tNumClient[MAX_CLIENTS], tSus[MAX_CLIENTS], tLogArticle, tLogClient,
numClient, tQuantite[MAX_ARTICLES], tPanier[MAX_ARTICLES], tLogPanier = 0; numClient, tQuantite[MAX_ARTICLES], tPanier[MAX_ARTICLES], tLogPanier = 0;
float tPoids[MAX_ARTICLES], tVol[MAX_ARTICLES], tPrixUnitaire[MAX_ARTICLES], tCagnotte[MAX_CLIENTS], float tPoids[MAX_ARTICLES], tVol[MAX_ARTICLES], tPrixUnitaire[MAX_ARTICLES], tCagnotte[MAX_CLIENTS],
volumeCoffre, chargeMaximale; volumeCoffre, chargeMaximale;
double budget = -1.0; double budget = -1.0;
@ -462,7 +449,7 @@ void global_client(void) {
break; break;
case 3: case 3:
ajouter_article_au_panier(numClient, tRef, tPoids, tVol, tPrixUnitaire, tNumClient, tCagnotte, ajouter_article_au_panier(numClient, tRef, tPoids, tVol, tPrixUnitaire, tNumClient, tCagnotte,
tSus, tLogArticle, tLogClient, volumeCoffre, chargeMaximale, tPanier, tQuantite, &tLogPanier, budget); tLogArticle, tLogClient, volumeCoffre, chargeMaximale, tPanier, tQuantite, &tLogPanier, budget);
break; break;
case 4: case 4:
supprimer_article_du_panier(tPanier, tQuantite, &tLogPanier, tCagnotte, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire); supprimer_article_du_panier(tPanier, tQuantite, &tLogPanier, tCagnotte, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire);
@ -474,10 +461,9 @@ void global_client(void) {
break; break;
case 6: case 6:
reinitialiser_panier(tPanier, tQuantite, &tLogPanier, tCagnotte, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire); reinitialiser_panier(tPanier, tQuantite, &tLogPanier, tCagnotte, numClient, tNumClient, tLogClient, tRef, tPrixUnitaire);
printf("Le panier a été réinitialisé.\n");
break; break;
case 9: case 9:
quitter_application(tPanier, tLogPanier, tRef, tPoids, tVol, tPrixUnitaire, tQuantite, tCagnotte, numClient, tNumClient, tLogClient, budget, tSus); quitter_application(tPanier, tLogPanier, tRef, tPoids, tVol, tPrixUnitaire, tQuantite, tCagnotte, numClient, tNumClient, tLogClient, budget, tSus, volumeCoffre, chargeMaximale);
sauvegarde_clients(tNumClient, tCagnotte, tSus, tLogClient); sauvegarde_clients(tNumClient, tCagnotte, tSus, tLogClient);
printf("Au revoir !\n"); printf("Au revoir !\n");
return; return;

@ -32,7 +32,6 @@ void affiche_client(void);
* @param tPrixUnitaire - Un tableau de prix unitaires d'articles. * @param tPrixUnitaire - Un tableau de prix unitaires d'articles.
* @param tNumClient - Un tableau de numéros d'articles. * @param tNumClient - Un tableau de numéros d'articles.
* @param tCagnotte - Un tableau de cagnottes. * @param tCagnotte - Un tableau de cagnottes.
* @param tSus - Un tableau d'articles suspendus.
* @param tLogArticle - Le nombre total d'articles disponibles. * @param tLogArticle - Le nombre total d'articles disponibles.
* @param tLogClient - Le nombre total de clients. * @param tLogClient - Le nombre total de clients.
* @param volumeCoffre - La limite de volume pour le panier du client. * @param volumeCoffre - La limite de volume pour le panier du client.
@ -43,7 +42,7 @@ void affiche_client(void);
* @param budget - Le budget du client. * @param budget - Le budget du client.
*/ */
void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float tVol[], float tPrixUnitaire[], void ajouter_article_au_panier(int numClient, int tRef[], float tPoids[], float tVol[], float tPrixUnitaire[],
int tNumClient[], float tCagnotte[], int tSus[], int tLogArticle, int tLogClient, int tNumClient[], float tCagnotte[], int tLogArticle, int tLogClient,
float volumeCoffre, float chargeMaximale, int tPanier[], int tQuantite[], int *tLogPanier, float budget); float volumeCoffre, float chargeMaximale, int tPanier[], int tQuantite[], int *tLogPanier, float budget);
/** /**
@ -135,7 +134,7 @@ void reinitialiser_panier(int tPanier[], int tQuantite[], int *tLogPanier, float
* @param tLogClient - Le nombre total de clients. * @param tLogClient - Le nombre total de clients.
* @param tSus - Un tableau d'état des clients suspendus. * @param tSus - Un tableau d'état des clients suspendus.
*/ */
void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient, int tSus[]); void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCagnotte[], int tLogClient);
/** /**
* @brief Quitter l'application client. * @brief Quitter l'application client.
@ -153,10 +152,12 @@ void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCag
* @param tLogClient - Le nombre total de clients. * @param tLogClient - Le nombre total de clients.
* @param budget - Le budget du client. * @param budget - Le budget du client.
* @param tSus - Un tableau d'état des clients suspendus. * @param tSus - Un tableau d'état des clients suspendus.
* @param volumeCoffre - La limite de volume pour le véhicul du client.
* @param chargeMaximale - La limite de poids pour le véhicul du client.
*/ */
void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[], void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[],
float tPrixUnitaire[], int tQuantite[], float tCagnotte[], int numClient, float tPrixUnitaire[], int tQuantite[], float tCagnotte[], int numClient,
int tNumClient[], int tLogClient, float budget, int tSus[]); int tNumClient[], int tLogClient, float budget, int tSus[], float volumeCoffre, float chargeMaximale);
/** /**
* @brief Afficher le menu du client et enregistrer le choix de l'utilisateur. * @brief Afficher le menu du client et enregistrer le choix de l'utilisateur.

@ -1,5 +1,3 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "interface_resp.h" #include "interface_resp.h"
@ -126,14 +124,14 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix, int
while (getchar() != '\n'); while (getchar() != '\n');
} }
printf("\t Entrez le volume du nouveau produit\n"); printf("\t Entrez le volume du nouveau produit\n");
while (scanf("%f", volume) != 1 || *volume <= 0) while (scanf("%f", volume) != 1 || *volume <= 0)
{ {
printf("\t Veuillez entrer un volume valide.\n"); printf("\t Veuillez entrer un volume valide.\n");
while (getchar() != '\n'); while (getchar() != '\n');
} }
printf("\t Entrez le prix du nouveau produit\n"); printf("\t Entrez le prix du nouveau produit\n");
while (scanf("%f", prix) != 1 || *prix <= 0) while (scanf("%f", prix) != 1 || *prix <= 0)
{ {
printf("\t Veuillez entrer un prix valide.\n"); printf("\t Veuillez entrer un prix valide.\n");

Loading…
Cancel
Save