Ajout de la fonction display_basket et correction de bugs

doc
Julien ABADIE 1 year ago
parent 0090a24956
commit f0edfe731c

@ -111,3 +111,55 @@ void displayClientList(int clientID[], float cagnotte[], int suspended[], int is
printf("%d\t%f\t%d\t%d", clientID[i], cagnotte[i], suspended[i], isAdmin[i]);
}
}
void display_basket(int basket_tab_ref[], int basket_qte[], float weight[], float volume[], float unitPrice[], float *cagnotte,float weight_constraint, float volume_constraint, int tlog, int tlog_basket)
{
float total_weight_line[], total_volume_line[], total_price_line[], cagnotte_line[], total_weight, total_volume, total_price;
int i;
for (i=0; i<tlog_basket; i++)
{
total_weight_line[i] = basket_qte[i]*weight[i];
total_volume_line[i] = basket_qte[i]*volume[i];
total_price_line[i] = basket_qte[i]*unitPrice[i];
cagnotte_line[i] = total_price_line[i] * 0.10;
}
for (i=0; i<tlog_basket; i++)
{
total_price = total_price + total_price_line[i];
}
printf("Récapitulatif de votre panier:\n");
printf("Référence\tQuantité\tPoids\tVolume\tPrixU\tPoidsTot\tVolTot\tPrixTot\tCagnotte\n");
for (i=0; i<tlog_basket; i++)
printf("%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", basket_tab_ref[i], basket_qte[i], weight[i], volume[i], unitPrice[i], total_weight_line[i], total_volume_line[i], total_price_line[i],cagnotte_line[i]);
printf("\t\t\t\t\tPrix total à payer: %f\t euros\n", total_price);
printf("\t\t\t\t\tCagnotte totale: %f\t euros\n", *cagnotte);
if (volume_constraint<total_volume)
{
printf("Volume actuel:%.2f\n", total_volume);
printf("Volume restant: Attention, dépasssement du volume autorisé de %2.f, veuillez suprimer des articles",total_volume - volume_constraint);
}
else
{
printf("Volume actuel:%.2f\n", total_volume);
printf("Volume restant:%2.f\n", volume_constraint - total_volume);
}
if (weight_constraint<total_weight)
{
printf("Charge actuelle:\t%2.f",total_weight);
printf("Attention, dépasssement de la charge autorisée de %2.f, veuillez suprimer des articles", total_weight - weight_constraint);
}
else
{
printf("Charge actuelle:\t%2.f",total_weight);
printf("Charge restante:\t%2.f", volume_constraint - total_volume);
}
}

@ -42,3 +42,4 @@ int recherche(int val, int tab[], int tlog);
void clientConstraint(float *weight, float *volume, float *price);
int constraintExceeded(float weightConstraint, float volumeConstraint, float *priceConstraint, float tabWeight[], float tabVolume[], float tabUnitPrice[], int tabQuantity[], int tlog, float *cagnotte);
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);
void display_basket(int basket_tab_ref[], int basket_qte[], float weight[], float volume[], float unitPrice[], float *cagnotte,float weight_constraint, float volume_constraint, int tlog, int tlog_basket);

@ -30,6 +30,27 @@ void clientConstraint(float *weight, float *volume, float *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;
@ -99,7 +120,7 @@ int constraintExceeded(float weightConstraint, float volumeConstraint, float *pr
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=0, total_volume=0, total_price=0, total_cagnotte=0;
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);
@ -119,17 +140,17 @@ int basket_add (int tab_reference[], float weight[], float volume[], float unitP
}
basket_tab_qte[index_ajout] = ref_to_add;
for (i=0; i<tlog_basket; i++)
{
index_ajout = basket_tab_ref[i];
total_weight = total_weight + weight[index_ajout]*qte_to_add;
total_volume = total_volume + volume[index_ajout]*qte_to_add;
total_price = total_price + unitPrice[index_ajout]*qte_to_add;
}
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;
basket_add()
display_basket();
//paramètres à poser
tlog_basket = tlog_basket+1;
return tlog_basket;

Loading…
Cancel
Save