#include "main.h" void clientConstraint(float *weight, float *volume, float *price) { /* Saisie des contraintes du client. */ printf("Entrez la charge maximale de votre véhicule en kilogrammes: "); scanf("%f", weight); while (*weight < 0) { printf("Erreur, le poids doit être positif, entrez la charge maximale de votre véhicule en kilogrammes: "); scanf("%f", weight); } printf("Entrez le volume du coffre de votre véhicule en mètres cubes: "); scanf("%f", volume); while (*volume < 0) { printf("Erreur: le volume doit être positif, entrez le volume du coffre de votre véhicule en mètres cubes: "); scanf("%f", volume); } printf("Entrez votre budget maximum ou -1 si vous n'en avait pas: "); scanf("%f", price); while (*price < 0 || *price != -1) { printf("Erreur: le prix doit être positif, entrez votre budget maximum ou -1 si vous n'en avait pas: "); scanf("%f", price); } } /** * The function checks if the weight, volume, and price constraints are exceeded and allows the user to * use their cagnotte (a type of credit) to stay within the price constraint. * * @param weightConstraint The weight constraint for the vehicle `float`. * @param volumeConstraint The volume constraint is the maximum volume that the vehicle can hold. It is * a float value. * @param priceConstraint A pointer to a float variable representing the maximum budget constraint. * @param tabWeight An array containing the weights of each item in the inventory. * @param tabVolume tabVolume is an array that stores the volume of each item in the inventory. * @param tabUnitPrice tabUnitPrice is an array that stores the unit price of each item in the * inventory. * @param tabQuantity tabQuantity is an array that stores the quantity of each item in the shopping * cart. * @param tlog The parameter "tlog" represents the number of items in the inventory or the number of * items in the transaction log. * @param cagnotte A pointer to a float variable representing the amount of money available for use. * * @return an integer value. */ // TODO réécrire cette documentation int constraintExceeded(float weightConstraint, float volumeConstraint, float *priceConstraint, float tabWeight[], float tabVolume[], float tabUnitPrice[], int tabQuantity[], int tlog, float *cagnotte) { float totalWeight = 0, totalVolume = 0, totalPrice = 0, cagnotteUse; int i; for (i=0; i weightConstraint) { printf("Attention, la contrainte de charge maximale du véhicule a été dépassée de %.2f, veuillez retirer un article\n", totalWeight - weightConstraint); return -1; } if (totalVolume > volumeConstraint) { printf("Attention, la contrainte de volume maximum a été dépassé de %.2f, veuillez retirer un article\n", totalVolume - volumeConstraint); return -1; } if (*priceConstraint != -1 && totalPrice > *priceConstraint) { printf("Attention, la contrainte de budget maximum a été dépassé de %.2f\n", totalPrice - *priceConstraint); if (*cagnotte < totalPrice) { printf("Le prix total excédant votre cagnotte, veuillez retirer un article\n"); return -1; } else { printf("Vous pouvez utiliser votre cagnotte, dont le montant est de %.2f, entrez le montant à utiliser ou -1 si vous voulez retirer un article: ", *cagnotte); scanf("%f", &cagnotteUse); if (cagnotteUse == -1) return -1; while (cagnotteUse > *cagnotte || totalPrice-cagnotteUse > *priceConstraint) { if (cagnotteUse > *cagnotte) printf("Erreur: vous ne pouvez pas utiliser plus que vous n'avez, réessayez ou entrer -1 si vous souhaitez retirer un article: "); if (totalPrice-cagnotteUse > *priceConstraint) printf("Erreur: vous n'avez pas utilisé assez de votre cagnotte, vous devez utiliser au moins %.2f, veuillez rentrer le montant à utiliser ou -1 si vous voulez retirer un article: ", totalPrice - *priceConstraint); scanf("%f", &cagnotteUse); if (cagnotteUse == -1) return -1; *cagnotte -= cagnotteUse; *priceConstraint += cagnotteUse; } } } } return 0; } /** * @brief Ajoute un article au panier et calcule les différents attributs pour la fonction `display_basket` * @param tab_reference: tableau des références des articles * @param weight: tableau des poids des articles * @param volume: tableau du volume des articles * @param unitPrice: tableau du prix unitaire des articles * @param cagnotte: pointeur indiquant la valeur de la cagnotte * @param basket_tab_ref: tableau des références du panier * @param basket_tab_qte: tableau de la quantité de l'article du panier * @param tlog: taille logique du tableau `tab_reference` * @param tlog_basket: taille logique du panier * @return taille logique du panier */ int basket_add (int tab_reference[], float weight[], float volume[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[],int tlog, int tlog_basket) { int ref_to_add, qte_to_add, trouve, index_ajout, i; float total_weight[], total_volume[], total_price[], total_cagnotte[]; printf("Quelle référence souhaitez-vous ajouter au panier?"); scanf("%d", &ref_to_add); index_ajout = searchTab(tab_reference, ref_to_add, tlog, &trouve); while (trouve == 0) { printf("L'élément que vous souhaitez ajouter n'existe pas, ressayez s'il vous plaît"); scanf("%d", &ref_to_add); index_ajout = searchTab(tab_reference, ref_to_add, tlog, &trouve); } basket_tab_ref[index_ajout] = ref_to_add; printf("Quelle quantité de cet article souhaitez-vous ajouter au panier?"); scanf("%d", &qte_to_add); while (qte_to_add <= 0) { printf("Vous ne pouvez pas ajouter une quantité nulle ou négative ressayez"); scanf("%d", &qte_to_add); } basket_tab_qte[index_ajout] = ref_to_add; index_ajout = basket_tab_ref[i]; total_weight[i] = total_weight + weight[index_ajout]*qte_to_add; total_volume[i] = total_volume + volume[index_ajout]*qte_to_add; total_price[i] = total_price + unitPrice[index_ajout]*qte_to_add; *cagnotte = *cagnotte + *cagnotte*0.10; tlog_basket = tlog_basket+1; display_basket( basket_tab_ref[], basket_tab_qte[], weight[], volume[], unitPrice[], *cagnotte, weight_constraint, volume_constraint, tlog, tlog_basket); return tlog_basket; } int reinit_basket(int tlog_basket) { tlog_basket=0; // En mettant tlog_basket à 0, // on fait comme si la taille logique était à 0, faisant que l'on ne considère plus aucun élément des tableaux return tlog_basket; } int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket) { int ref_to_del, trouve, index_to_del, qte_to_del, i; printf("Quelle référence voulez vous supprimer de votre panier?\n"); scanf("%d",&ref_to_del); index_to_del = searchTab(basket_tab_ref, ref_to_del, tlog_basket, &trouve); while (trouve == 0) { printf("Erreur, la valeur que vous voulez supprimer n'existe pas, réssayez"); scanf("%d",&ref_to_del); index_to_del = searchTab(basket_tab_ref, ref_to_del, tlog_basket, &trouve); } if (basket_tab_qte[index_to_del]>1) { printf("Combien d'articles e ce type voulez-vous supprimer?"); scanf("%d",&qte_to_del); while(qte_to_del<=0) { printf("Erreur, vous ne pouvez pas supprimer un nombre nul ou négatif d'articles, réssayez"); //on pourrait supprimer un nombre nul d'articles, //mais ça n'a pas de sens car cette fonction à pour but de supprimer des articles scanf("%d",&qte_to_del); } while(basket_tab_qte[index_to_del]-qte_to_del>=0) { printf("Erreur, vous ne pouvez pas supprimer plus d'articles que vous n'en avez dans votre panier, ressayez"); scanf("%d",&qte_to_del); } if (qte_to_delindex_to_del; i--) { basket_tab_ref[i]=basket_tab_ref[i+1]; basket_tab_qte[i]=basket_tab_qte[i+1]; } return tlog_basket-1; } } }