Merge branch 'master' into doc
continuous-integration/drone/push Build is passing Details

doc
Rémi LAVERGNE 1 year ago
commit 35e55c2efd

@ -8,18 +8,26 @@
#include "main.h" #include "main.h"
void decalageADroite(int tab[], int index, int tlog) void decalageADroiteInt(int tab[], int index, int tlog)
{ {
for (int i = tlog; i > index; i--) for (int i = tlog; i > index; i--)
{
tab[i] = tab[i-1]; tab[i] = tab[i-1];
}
} }
void decalageAGauche(int tab[], int index, int tlog) void decalageAGaucheInt(int tab[], int index, int tlog)
{
for (int i = index; i < tlog; i++)
tab[i] = tab[i+1];
}
void decalageADroiteFloat(float tab[], int index, int tlog)
{
for (int i = tlog; i > index; i--)
tab[i] = tab[i-1];
}
void decalageAGaucheFloat(float tab[], int index, int tlog)
{ {
for (int i = index; i < tlog; i++) for (int i = index; i < tlog; i++)
{
tab[i] = tab[i+1]; tab[i] = tab[i+1];
}
} }

@ -108,33 +108,41 @@ 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;
printf("Récapitulatif de votre panier:\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[i] = tabWeight[index];
volume[i] = tabVolume[index];
unitPrice[i] = tabUnitPrice[index];
}
total_weight_line[i] = basket_qte[i]*weight[i]; total_weight_line[i] = basket_qte[i]*weight[i];
total_volume_line[i] = basket_qte[i]*volume[i]; total_volume_line[i] = basket_qte[i]*volume[i];
total_price_line[i] = basket_qte[i]*unitPrice[i]; total_price_line[i] = basket_qte[i]*unitPrice[i];
totalWeight += total_weight_line[i]; totalWeight += total_weight_line[i];
totalVol += total_volume_line [i]; totalVol += total_volume_line [i];
total_price += total_price_line[i]; total_price += total_price_line[i];
}
printf("Récapitulatif de votre panier:\n");
printf("Référence\tQuantité\tPoids\tVolume\tPrix unitaire\tPoids Total\tVol Total\tPrix Total\n");
for (i=0; i<tlog_basket; 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);
} }

Binary file not shown.

@ -12,9 +12,9 @@
* @param tlog: Taille logique des Tableaux * @param tlog: Taille logique des Tableaux
* @return Est Admin ? (1 > Oui, 0 > Non, -1 > Quitter) * @return Est Admin ? (1 > Oui, 0 > Non, -1 > Quitter)
*/ */
int login(int clientID[], int clientPassword[], int isAdmin[], int tlog) int login(int clientID[], int clientPassword[], int isAdmin[], int tlog, int *index)
{ {
int id, password, index, found, tentative=3; int id, password, found, tentative=3;
printf("Entrez votre identifiant: "); printf("Entrez votre identifiant: ");
scanf("%d%*c", &id); scanf("%d%*c", &id);
while (id < 0) while (id < 0)
@ -22,7 +22,7 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog)
printf("Erreur, l'identifiant doit être positif, entrez votre identifiant: "); printf("Erreur, l'identifiant doit être positif, entrez votre identifiant: ");
scanf("%d%*c", &id); scanf("%d%*c", &id);
} }
index = searchTab(clientID, id, tlog, &found); *index = searchTab(clientID, id, tlog, &found);
while(found == 0) while(found == 0)
{ {
printf("Erreur, l'identifiant n'existe pas, entrez votre identifiant: "); printf("Erreur, l'identifiant n'existe pas, entrez votre identifiant: ");
@ -39,7 +39,7 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog)
} }
printf("Il vous reste %d tentatives.\n", tentative); printf("Il vous reste %d tentatives.\n", tentative);
index = searchTab(clientID, id, tlog, &found); *index = searchTab(clientID, id, tlog, &found);
} }
printf("Entrez votre mot de passe: "); printf("Entrez votre mot de passe: ");
@ -50,9 +50,9 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog)
scanf("%d%*c", &password); scanf("%d%*c", &password);
} }
if (password == decrypt(clientPassword[index])) if (password == decrypt(clientPassword[*index]))
{ {
if (isAdmin[index] == 1) if (isAdmin[*index] == 1)
{ {
return 1; return 1;
} }
@ -80,18 +80,18 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog)
*/ */
int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog) int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog)
{ {
int id, password, index, found, status; int id, password, index, found;
printf("Entrez votre identifiant: "); printf("Entrez votre identifiant ou 0 si vous souhaitez quitter: ");
scanf("%d%*c", &id); scanf("%d%*c", &id);
while (id < 0) while (id < 0)
{ {
printf("Erreur, l'identifiant doit être positif, entrez votre identifiant: "); printf("Erreur, l'identifiant doit être positif, entrez votre identifiant ou 0 si vous souhaitez quitter: ");
scanf("%d%*c", &id); scanf("%d%*c", &id);
} }
index = searchTab(clientID, id, *tlog, &found); index = searchTab(clientID, id, *tlog, &found);
while(found == 1) while(found == 1)
{ {
printf("Erreur, l'identifiant existe déjà, entrez votre identifiant: "); printf("Erreur, l'identifiant existe déjà, entrez votre identifiant ou 0 si vous souhaitez quitter: ");
scanf("%d%*c", &id); scanf("%d%*c", &id);
if (id == 0) if (id == 0)
{ {
@ -109,5 +109,6 @@ int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended
scanf("%d%*c", &password); scanf("%d%*c", &password);
} }
return inputClient(id, password, index, clientID, clientPassword, cagnotte, suspended, isAdmin, tlog); inputClient(id, password, index, clientID, clientPassword, cagnotte, suspended, isAdmin, tlog);
return 0;
} }

@ -50,11 +50,11 @@ int displayMenu(void)
void global(void) void global(void)
{ {
// Déclaration des variables // Déclaration des variables
int tLogArticle, tLogClient, choice, status, currentUser; int tLogItem, tLogClient, tlogBasket, choice, status, currentUser, index;
int reference[tmaxArticles], clientID[tmaxClients], clientPassword[tmaxClients], suspended[tmaxClients], isAdmin[tmaxClients]; int reference[tmaxArticles], clientID[tmaxClients], clientPassword[tmaxClients], suspended[tmaxClients], isAdmin[tmaxClients], basket_tab_ref[tmaxArticles], basket_tab_qte[tmaxArticles];
float weight[tmaxArticles], volume[tmaxArticles], unitPrice[tmaxArticles], cagnotte[tmaxClients]; float weight[tmaxArticles], volume[tmaxArticles], unitPrice[tmaxArticles], cagnotte[tmaxClients];
// Chargement de toute les données // Chargement de toute les données
chargeDonnees(&tLogArticle, &tLogClient, reference, weight, volume, unitPrice, clientID, clientPassword, cagnotte, suspended, isAdmin); chargeDonnees(&tLogItem, &tLogClient, reference, weight, volume, unitPrice, clientID, clientPassword, cagnotte, suspended, isAdmin);
// Affichage du menu // Affichage du menu
choice = displayMenu(); choice = displayMenu();
@ -63,16 +63,14 @@ void global(void)
switch(choice) switch(choice)
{ {
case 1: case 1:
status = login(clientID, clientPassword, isAdmin, tLogClient); status = login(clientID, clientPassword, isAdmin, tLogClient, &index);
if(status == 1) if(status == 1)
{ {
//TODO > Menu Admin adminMenu(clientID, clientPassword, cagnotte, suspended, isAdmin, reference, weight, volume, unitPrice, &tLogItem, &tLogClient);
//adminMenu();
} }
else if(status == 0) else if(status == 0)
{ {
//TODO > Menu Client clientMenu(&weight[index], &volume[index], &unitPrice[index], reference, unitPrice, &cagnotte[index], basket_tab_ref, basket_tab_qte, weight, volume, tLogItem, &tlogBasket);
//clientMenu();
} }
else else
{ {
@ -98,10 +96,10 @@ void global(void)
//opposition(); //opposition();
break; break;
case 4: case 4:
sauvegardeDonnees(tLogArticle, tLogClient, reference, weight, volume, unitPrice, clientID, clientPassword, cagnotte, isAdmin, suspended); sauvegardeDonnees(tLogItem, tLogClient, reference, weight, volume, unitPrice, clientID, clientPassword, cagnotte, isAdmin, suspended);
return; return;
case 9: case 9:
debugMenu(reference, weight, volume, unitPrice, clientID, cagnotte, suspended, isAdmin, tLogArticle, tLogClient); debugMenu(reference, weight, volume, unitPrice, clientID, cagnotte, suspended, isAdmin, tLogItem, tLogClient);
break; break;
default: default:
printf("Erreur, veuillez entrer un choix valide.\n"); printf("Erreur, veuillez entrer un choix valide.\n");

@ -28,11 +28,13 @@ void sauvegardeArticles(int reference[], float weight[], float volume[], float u
void sauvegardeClients(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int tLogClient); void sauvegardeClients(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int tLogClient);
//! DECALAGES TABLEAUX //! DECALAGES TABLEAUX
void decalageADroite(int tab[], int index, int tlog); void decalageADroiteInt(int tab[], int index, int tlog);
void decalageAGauche(int tab[], int index, int tlog); void decalageAGaucheInt(int tab[], int index, int tlog);
void decalageADroiteFloat(float tab[], int index, int tlog);
void decalageAGaucheFloat(float tab[], int index, int tlog);
//! GESTION CLIENTS //! GESTION CLIENTS
int inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); void inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog);
void modifyClient(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int tlog); void modifyClient(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int tlog);
void deleteClient(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); void deleteClient(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int *tlog);
@ -52,12 +54,13 @@ 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 tabItemRef[], int basket_qte[], float tabWeight[], float tabVolume[], float cagnotte, float tabUnitPrice[], int tlogItem, int tlog_basket);
int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket); void reinit_basket(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, int *index);
int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog);
//! MOT DE PASSE //! MOT DE PASSE
@ -65,5 +68,5 @@ int encrypt(int password);
int decrypt(int password); int decrypt(int password);
//! MENUS //! MENUS
void adminMenu(void); void adminMenu(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int tabReference[], float tabWeight[], float tabVolume[], float unitPrice[], int *tlogItem, int *tlogClient);
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[], int tlogItem, int *tlogBasket);

@ -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[], 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, unitPrice, 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, unitPrice, 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;
@ -44,7 +51,61 @@ void clientMenu(float *weight, float *volume, float *price)
} }
} }
void adminMenu(void) void adminMenu(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int tabReference[], float tabWeight[], float tabVolume[], float unitPrice[], int *tlogItem, int *tlogClient)
{ {
int choice = 0;
while (choice != 10)
{
printf("\n=================================\n");
printf(" Menu Client\n");
printf("=================================\n");
printf("1\u2022 Ajouter un client\n");
printf("2\u2022 Modifier les données d'un client\n");
printf("3\u2022 Supprimer un client\n");
printf("4\u2022 Ajouter un article\n");
printf("5\u2022 Supprimer un article\n");
printf("6\u2022 Afficher les données d'un article\n");
printf("7\u2022 Afficher la liste des articles\n");
printf("8\u2022 Afficher les données d'un client\n");
printf("9\u2022 Afficher la liste des clients\n");
printf("10\u2022 Quitter\n");
printf("=================================\n");
printf("Votre choix: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
signup(clientID, clientPassword, cagnotte, suspended, isAdmin, tlogClient);
break;
case 2:
modifyClient(clientID, cagnotte, suspended, isAdmin, *tlogClient);
break;
case 3:
deleteClient(clientID, cagnotte, suspended, isAdmin, tlogClient);
break;
case 4:
inputItem(tabReference, tabWeight, tabVolume, unitPrice, tlogItem);
break;
case 5:
deleteItem(tabReference, tabWeight, tabVolume, unitPrice, tlogItem);
break;
case 6:
displayItem(tabReference, tabWeight, tabVolume, unitPrice, *tlogItem);
break;
case 7:
displayItemList(tabReference, tabWeight, tabVolume, unitPrice, *tlogItem);
break;
case 8:
displayClient(clientID, cagnotte, suspended, isAdmin, *tlogClient);
break;
case 9:
displayClientList(clientID, cagnotte, suspended, isAdmin, *tlogClient);
break;
case 10:
return;
default:
printf("Erreur, veuillez entrer un choix valide.\n");
break;
}
}
} }

@ -18,20 +18,20 @@
* @param tlog: Taille logique des tableaux * @param tlog: Taille logique des tableaux
* @return 0 si tout s'est bien passé, -2 si la taille physique du tableau est dépassée * @return 0 si tout s'est bien passé, -2 si la taille physique du tableau est dépassée
*/ */
int inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog) void inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog)
{ {
// Vérification du dépassement de la taille physique du tableau // Vérification du dépassement de la taille physique du tableau
if (*tlog == tmaxClients) if (*tlog == tmaxClients)
{ {
printf("[ERREUR] - La taille physique du tableau est dépassée, impossible d'ajouter un nouveau client.\n"); printf("[ERREUR] - La taille physique du tableau est dépassée, impossible d'ajouter un nouveau client.\n");
return -2; return;
} }
// Décalage // Décalage
decalageADroite(clientID, index, *tlog); decalageADroiteInt(clientID, index, *tlog);
decalageADroite(cagnotte, index, *tlog); decalageADroiteFloat(cagnotte, index, *tlog);
decalageADroite(suspended, index, *tlog); decalageADroiteInt(suspended, index, *tlog);
decalageADroite(isAdmin, index, *tlog); decalageADroiteInt(isAdmin, index, *tlog);
clientID[index] = id; clientID[index] = id;
clientPassword[index] = encrypt(passwd); clientPassword[index] = encrypt(passwd);
@ -40,7 +40,6 @@ int inputClient(int id, int passwd, int index, int clientID[], int clientPasswor
isAdmin[index] = 0; isAdmin[index] = 0;
*tlog++; *tlog++;
return 0; // Tout s'est bien passé
} }
/** /**

@ -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[tmaxArticles], total_volume[tmaxArticles], total_price[tmaxArticles], total_cagnotte[tmaxArticles];
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;
} }
/** /**
@ -141,7 +139,9 @@ void reinit_basket(int *tlog_basket)
{ {
*tlog_basket=0; *tlog_basket=0;
// En mettant 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 // on fait comme si la taille logique était à 0, faisant que l'on ne considère plus aucun élément des tableaux,
//et donc qu'il est désormais vide.
return tlog_basket;
} }
/** /**
@ -151,18 +151,18 @@ 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;
printf("Quelle référence voulez vous supprimer de votre panier?\n"); printf("Quelle référence voulez vous supprimer de votre panier?\n");
scanf("%d",&ref_to_del); scanf("%d",&ref_to_del);
index_to_del = searchTab(basket_tab_ref, ref_to_del, tlog_basket, &trouve); index_to_del = searchTab(basket_tab_ref, ref_to_del, *tlog_basket, &trouve);
while (trouve == 0) while (trouve == 0)
{ {
printf("Erreur, la valeur que vous voulez supprimer n'existe pas, réssayez"); printf("Erreur, la valeur que vous voulez supprimer n'existe pas, réssayez");
scanf("%d",&ref_to_del); scanf("%d",&ref_to_del);
index_to_del = searchTab(basket_tab_ref, ref_to_del, tlog_basket, &trouve); index_to_del = searchTab(basket_tab_ref, ref_to_del, *tlog_basket, &trouve);
} }
if (basket_tab_qte[index_to_del]>1) if (basket_tab_qte[index_to_del]>1)
{ {
@ -183,16 +183,15 @@ 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])
{ {
for (i=tlog_basket; i>index_to_del; i--) for (i=*tlog_basket; i>index_to_del; i--)
{ {
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