ajout de la fonction reset / affich / modifier

master
Ange BARDET 1 year ago
parent b6bc0429e1
commit b0246a7917

@ -5,10 +5,17 @@
int ajoutPanier(int TrefC[],int TquanC[],int nArticle,int Tref[], int n) int ajoutPanier(int TrefC[],int TquanC[],int nArticle,int Tref[], int n)
{ {
int refP,code,quantite; int refP,code,quantite,pos;
printf("Saisir la référence du produit à ajouter au panier: "); printf("Saisir la référence du produit à ajouter au panier: ");
scanf("%d",&refP); scanf("%d",&refP);
pos = posRefC(TrefC,n,refP,nArticle,Tref);
if (pos != -1)
{
printf("L'article existe déja dans le panier.");
return nArticle;
}
code = posRef(Tref,refP,n); code = posRef(Tref,refP,n);
while (code == -1) while (code == -1)
{ {
@ -85,7 +92,7 @@ void affichPanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[
printf("%.0f kg\n",chargeR); printf("%.0f kg\n",chargeR);
} }
int posRefC(int TrefC[], float Tpoid[], int n, int refR,int nArticle,int Tref[]) int posRefC(int TrefC[], int n, int refR,int nArticle,int Tref[])
{ {
int i,pos; int i,pos;
for (i=0;i <nArticle;i++) for (i=0;i <nArticle;i++)
@ -98,21 +105,57 @@ int posRefC(int TrefC[], float Tpoid[], int n, int refR,int nArticle,int Tref[])
int SupprArticlePanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[],float Tvolume[],float Tprix[],int n) int SupprArticlePanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[],float Tvolume[],float Tprix[],int n)
{ {
if (nArticle <= 0)
{
printf("Il n'y a aucun article dans le panier.");
return nArticle;
}
int refR,pos; int refR,pos;
printf("Saisir la référence de l'article a supprimer: "); printf("Saisir la référence de l'article a supprimer: ");
scanf("%d",&refR); scanf("%d",&refR);
printf("l'article est %d",refR); pos = posRefC(TrefC,n,refR,nArticle,Tref);
pos = posRefC(TrefC,Tpoid,n,refR,nArticle,Tref); if (pos == -1)
printf("La pos de %d est %d",refR,pos);
int i;
for (i=pos;i<=n;i++)
{ {
TrefC[i] = TrefC[i+1]; printf("L'article n'existe pas dans le panier.");
TquanC[i] = TquanC[i+1];
} }
else
{
TrefC[pos] = TrefC[pos+1];
TquanC[pos] = TquanC[pos+1];
return nArticle - 1; return nArticle - 1;
}
}
void ModifArticlePanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[],float Tvolume[],float Tprix[],int n)
{
if (nArticle <= 0)
{
printf("Il n'y a aucun article dans le panier.");
return;
}
int refR,pos,nQuan;
printf("Saisir la référence de l'article a modifier: ");
scanf("%d",&refR);
pos = posRefC(TrefC,n,refR,nArticle,Tref);
if (pos == -1)
{
printf("L'article n'existe pas dans le panier.");
}
else
{
printf("Saisir la nouvelle quantité du produit: ");
scanf("%d",&nQuan);
TquanC[pos] = nQuan;
}
} }
/*Modifier la quantité d'un article existant déjà dans le panier int ResetPanier(int TrefC[],int TquanC[],int nArticle)
Réinitialiser le panier*/ {
int i;
for (i=0;i<=nArticle;i++)
{
TrefC[i]=0;
TquanC[i]=0;
}
return 0;
}

@ -3,4 +3,6 @@ int ajoutPanier(int TrefC[],int TquanC[],int nArticle,int Tref[], int n);
void affichPanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[],float Tvolume[],float Tprix[],float chargeV, float volV,int n); void affichPanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[],float Tvolume[],float Tprix[],float chargeV, float volV,int n);
float initVoiture(float *chargeV); float initVoiture(float *chargeV);
int SupprArticlePanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[],float Tvolume[],float Tprix[],int n); int SupprArticlePanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[],float Tvolume[],float Tprix[],int n);
int posRefC(int TrefC[], float Tpoid[], int n, int refR,int nArticle,int Tref[]); int posRefC(int TrefC[], int n, int refR,int nArticle,int Tref[]);
void ModifArticlePanier(int TrefC[],int TquanC[],int nArticle,int Tref[], float Tpoid[],float Tvolume[],float Tprix[],int n);
int ResetPanier(int TrefC[],int TquanC[], int nArticle);

@ -63,14 +63,14 @@ void testF(void)
{ {
printf("Bienvenue Mr. le client :)\n"); printf("Bienvenue Mr. le client :)\n");
volV = initVoiture(&chargeV); volV = initVoiture(&chargeV);
printf("Que voulez vous faire ? (Ajout[0]/SupprimerArticle[1]/quitter[9]) "); printf("Que voulez vous faire ? (Ajout[0]/ModifierArticle[1]/SupprimerArticle[2]/AfficherPanier[3]/ResetPanier[4]/quitter[9]) ");
scanf("%d",&rep); scanf("%d",&rep);
int TrefC[200]={0},TquanC[200]={0},nArticle=0; int TrefC[200]={0},TquanC[200]={0},nArticle=0;
while (rep != 9) while (rep != 9)
{ {
while ((rep < 0 || rep > 1) && rep != 9) while ((rep < 0 || rep > 4) && rep != 9)
{ {
printf("Erreur; (Ajout[0]/SupprimerArticle[1]/quitter[9]) "); printf("Erreur; (Ajout[0]/ModifierArticle[1]/SupprimerArticle[2]/AfficherPanier[3]/ResetPanier[4]/quitter[9]) ");
scanf("%d",&rep); scanf("%d",&rep);
} }
if (rep == 0) if (rep == 0)
@ -80,13 +80,28 @@ void testF(void)
printf("\n"); printf("\n");
} }
if (rep == 1) if (rep == 1)
{
ModifArticlePanier(TrefC,TquanC,nArticle,Tref,Tpoid,Tvolume,Tprix,n);
printf("\n");
}
if (rep == 2)
{ {
nArticle = SupprArticlePanier(TrefC,TquanC,nArticle,Tref,Tpoid,Tvolume,Tprix,n); nArticle = SupprArticlePanier(TrefC,TquanC,nArticle,Tref,Tpoid,Tvolume,Tprix,n);
printf("\n"); printf("\n");
} }
if (rep == 3)
{
affichPanier(TrefC,TquanC,nArticle,Tref,Tpoid,Tvolume,Tprix,chargeV,volV,n);
printf("\n");
}
if (rep == 4)
{
nArticle = ResetPanier(TrefC,TquanC,nArticle);
printf("\n");
}
if (rep != 9) if (rep != 9)
{ {
printf("Que faire ? (Ajout[0]/SupprimerArticle[1]/quitter[9]) "); printf("Que faire ? (Ajout[0]/ModifierArticle[1]/SupprimerArticle[2]/AfficherPanier[3]/ResetPanier[4]/quitter[9]) ");
scanf("%d",&rep); scanf("%d",&rep);
} }

Loading…
Cancel
Save