correction d'erreur et ajout du menu client

doc^2^2
Louis GERMAIN 2 years ago
parent 74ac403e4e
commit e8df641096

@ -108,33 +108,42 @@ void displayClientList(int clientID[], float cagnotte[], int suspended[], int is
* @param weight: tableau des poids des articles * @param weight: tableau des poids des articles
* @param volume: tableau du volume des articles * @param volume: tableau du volume des articles
* @param unitPrice: tableau du prix unitaire des articles * @param unitPrice: tableau du prix unitaire des articles
* @param cagnotte: pointeur indiquant la valeur de la cagnotte * @param cagnotte: valeur de la cagnotte
* @param tlog: taille logique du tableau `tab_reference` * @param tlog: taille logique du tableau `tab_reference`
* @param tlog_basket: taille logique du panier * @param tlog_basket: taille logique du panier
* @return void * @return void
*/ */
void display_basket(int basket_tab_ref[], int basket_qte[], float weight[], float volume[], float cagnotte[], float unitPrice[], int tlog, int tlog_basket) void display_basket(int basket_tab_ref[], int tabItemRef[], int basket_qte[], float tabWeight[], float tabVolume[], float cagnotte, float tabUnitPrice[], int tlogItem, int tlog_basket)
{ {
float total_weight_line[tlog_basket], total_volume_line[tlog_basket], total_price_line[tlog_basket]; float total_weight_line[tlog_basket], total_volume_line[tlog_basket], total_price_line[tlog_basket];
float totalWeight = 0, totalVol = 0, total_price = 0; float totalWeight = 0, totalVol = 0, total_price = 0, weight[tmaxArticles], volume[tmaxArticles], unitPrice[tmaxArticles];
int i; int i, found, index, j = 0;
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];
totalWeight += total_weight_line[i];
totalVol += total_volume_line [i];
total_price += total_price_line[i];
}
printf("Récapitulatif de votre panier:\n"); printf("Récapitulatif de votre panier:\n");
printf("Référence\tQuantité\tPoids\tVolume\tPrix unitaire\tPoids Total\tVol Total\tPrix Total\n"); printf("Référence\tQuantité\tPoids\tVolume\tPrix unitaire\tPoids Total\tVol Total\tPrix Total\n");
for (i=0; i<tlog_basket; i++) for (i=0; i<tlog_basket; i++)
{
index = searchTab(tabItemRef, basket_tab_ref[i], tlogItem, &found);
if (found == 1)
{
weight[j] = tabWeight[index];
volume[j] = tabVolume[index];
unitPrice[j] = tabUnitPrice[index];
j++;
}
total_weight_line[i] = basket_qte[i]*weight;
total_volume_line[i] = basket_qte[i]*volume;
total_price_line[i] = basket_qte[i]*unitPrice;
totalWeight += total_weight_line[i];
totalVol += total_volume_line [i];
total_price += total_price_line[i];
printf("%d\t%d\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]); printf("%d\t%d\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]);
}
printf("Prix total: %f€\n", total_price); printf("Prix total: %f€\n", total_price);
printf("Poids total: %fkg\n", totalWeight); printf("Poids total: %fkg\n", totalWeight);
printf("Volume total: %fm³\n", totalVol); printf("Volume total: %fm³\n", totalVol);
printf("Cagnotte:%.2f€", cagnotte)
} }

@ -52,9 +52,9 @@ int searchTab(int targetTab[], int valSearched, int tLog, int *found);
//! PANIER //! PANIER
void clientConstraint(float *weight, float *volume, float *price); void clientConstraint(float *weight, float *volume, float *price);
int constraintExceeded(float weightConstraint, float volumeConstraint, float *priceConstraint, float *cagnotte, float tabWeight[], float tabVolume[], float tabPrice[], int tabItemRef[], int tabBasketRef[], int tabBasketQuantity[], int tlogItem, int tlogBasket); int constraintExceeded(float weightConstraint, float volumeConstraint, float *priceConstraint, float *cagnotte, float tabWeight[], float tabVolume[], float tabPrice[], int tabItemRef[], int tabBasketRef[], int tabBasketQuantity[], int tlogItem, int tlogBasket);
int basket_add (int tab_reference[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], int tlog, int tlog_basket); void basket_add(int tab_reference[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], int tlogItem, int *tlog_basket);
void display_basket(int basket_tab_ref[], int basket_qte[], float weight[], float volume[], float cagnotte[], float unitPrice[], int tlog, int tlog_basket); void display_basket(int basket_tab_ref[], int basket_qte[], float weight[], float volume[], float cagnotte[], float unitPrice[], int tlog, int tlog_basket);
int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket); void basket_del_article(int basket_tab_ref[], int basket_tab_qte[], int *tlog_basket)
//! LOGIN //! LOGIN
int login(int clientID[], int clientPassword[], int isAdmin[], int tlog); int login(int clientID[], int clientPassword[], int isAdmin[], int tlog);

@ -5,9 +5,9 @@
#include "main.h" #include "main.h"
void clientMenu(float *weight, float *volume, float *price) void clientMenu(float *weight, float *volume, float *price, int tabItemRef[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], float tabWeight[], float tabVolume[], float tabPrice[], int tlogItem, int *tlogBasket)
{ {
int choice = 0; int choice = 0, constraint;
while (choice != 6) while (choice != 6)
{ {
printf("\n=================================\n"); printf("\n=================================\n");
@ -28,12 +28,19 @@ void clientMenu(float *weight, float *volume, float *price)
clientConstraint(weight, volume, price); clientConstraint(weight, volume, price);
break; break;
case 2: case 2:
basket_add(tabItemRef, unitPrice, cagnotte, basket_tab_ref, basket_tab_qte, tlogItem, tlogBasket);
constraint = constraintExceeded(*weight, *volume, price, cagnotte, tabWeight, tabVolume, tabPrice, tabItemRef, basket_tab_ref, basket_tab_qte, tlogItem, *tlogBasket);
if (constraint == -1)
basket_del_article(basket_tab_ref, basket_tab_qte, tlogBasket);
break; break;
case 3: case 3:
display_basket(basket_tab_ref[], tabItemRef[], basket_tab_qte[], tabWeight[], tabVolume[], *cagnotte, tabPrice[], tlogItem, *tlogBasket);
break; break;
case 4: case 4:
reinit_basket(tlogBasket);
break; break;
case 5: case 5:
basket_del_article(basket_tab_ref, basket_tab_qte, tlogBasket);
break; break;
case 6: case 6:
return; return;

@ -103,18 +103,18 @@ int constraintExceeded(float weightConstraint, float volumeConstraint, float *pr
* @param tlog_basket: taille logique du panier * @param tlog_basket: taille logique du panier
* @return taille logique du panier * @return taille logique du panier
*/ */
int basket_add (int tab_reference[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], int tlog, int tlog_basket) void basket_add(int tab_reference[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], int tlogItem, int *tlog_basket)
{ {
int ref_to_add, qte_to_add, trouve, index_ajout; int ref_to_add, qte_to_add, trouve, index_ajout;
float total_weight[tlog_basket], total_volume[tlog_basket], total_price[tlog_basket], total_cagnotte[tlog_basket]; float total_weight[tlog_basket], total_volume[tlog_basket], total_price[tlog_basket], total_cagnotte[tlog_basket];
printf("Quelle référence souhaitez-vous ajouter au panier?"); printf("Quelle référence souhaitez-vous ajouter au panier?");
scanf("%d", &ref_to_add); scanf("%d", &ref_to_add);
index_ajout = searchTab(tab_reference, ref_to_add, tlog, &trouve); index_ajout = searchTab(tab_reference, ref_to_add, tlogItem, &trouve);
while (trouve == 0) while (trouve == 0)
{ {
printf("L'élément que vous souhaitez ajouter n'existe pas, ressayez s'il vous plaît"); printf("L'élément que vous souhaitez ajouter n'existe pas, ressayez s'il vous plaît");
scanf("%d", &ref_to_add); scanf("%d", &ref_to_add);
index_ajout = searchTab(tab_reference, ref_to_add, tlog, &trouve); index_ajout = searchTab(tab_reference, ref_to_add, tlogItem, &trouve);
} }
basket_tab_ref[index_ajout] = ref_to_add; basket_tab_ref[index_ajout] = ref_to_add;
printf("Quelle quantité de cet article souhaitez-vous ajouter au panier?"); printf("Quelle quantité de cet article souhaitez-vous ajouter au panier?");
@ -127,9 +127,7 @@ int basket_add (int tab_reference[], float unitPrice[], float *cagnotte, int ba
basket_tab_qte[index_ajout] = ref_to_add; basket_tab_qte[index_ajout] = ref_to_add;
*cagnotte += (unitPrice[index_ajout]*qte_to_add) *0.1; *cagnotte += (unitPrice[index_ajout]*qte_to_add) *0.1;
tlog_basket = tlog_basket+1; *tlog_basket += 1;
return tlog_basket;
} }
/** /**
@ -151,7 +149,7 @@ void reinit_basket(int *tlog_basket)
* @param tlog_basket: taille logique du panier * @param tlog_basket: taille logique du panier
* @return taille logique du panier * @return taille logique du panier
*/ */
int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket) void 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; int ref_to_del, trouve, index_to_del, qte_to_del, i;
@ -183,7 +181,6 @@ int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_bas
if (qte_to_del<basket_tab_qte[index_to_del]) if (qte_to_del<basket_tab_qte[index_to_del])
{ {
basket_tab_qte[index_to_del]=basket_tab_qte[index_to_del]-qte_to_del; basket_tab_qte[index_to_del]=basket_tab_qte[index_to_del]-qte_to_del;
return tlog_basket;
} }
else if (qte_to_del==basket_tab_qte[index_to_del]) else if (qte_to_del==basket_tab_qte[index_to_del])
{ {
@ -192,7 +189,7 @@ int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_bas
basket_tab_ref[i]=basket_tab_ref[i+1]; basket_tab_ref[i]=basket_tab_ref[i+1];
basket_tab_qte[i]=basket_tab_qte[i+1]; basket_tab_qte[i]=basket_tab_qte[i+1];
} }
return tlog_basket-1; *tlog_basket -= 1;
} }
} }

Loading…
Cancel
Save