modify article function is working

pull/3/head^2
yannis.doumir_fernandes 2 years ago
parent 12feccbbf1
commit 6cfa94b096

BIN
app

Binary file not shown.

@ -1,5 +1,3 @@
101 2.250 2.50 15.75
233 10.00 15.00 32.00
272 6.500 10.00 29.99
464 50.0 25.50 60.00
958 4.75 60.00 32.00
464 50.000000 25.500000 60.000000
958 4.750000 60.000000 32.000000
101 1.000000 1.000000 1.000000

@ -36,18 +36,17 @@ void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[],
fe = fopen("donnee/articles.txt", "w");
if ( fe == NULL)
{
perror("fopen");
fprintf(stderr, "\n Problème ouverture ficher\n");
return;
}
for ( i = 0; i < tLogique; i++)
{
fprintf(fe,"%d %f %f %f\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
fprintf(fe,"\t %d\t %f\t %f\t %f\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
}
fclose(fe);
}
int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique, int tPhysique, int ref, float poids, float volume, float prix)
{
int i = *tLogique;
@ -57,14 +56,14 @@ int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int
fprintf(stderr,"Tableau plein !");
return -2;
}
// SI on trie pas par ref c'est ca
printf("%d\n", *tLogique);
tRef[i] = ref;
tPoids[i] = poids;
tVol[i] = volume;
tPrix[i] = prix;
(*tLogique)++;
printf("%d\n", *tLogique);
return 0;
}
void rechercheRefArticle(int tRef[], int ref, int *index, int tLogique)
@ -77,19 +76,18 @@ void rechercheRefArticle(int tRef[], int ref, int *index, int tLogique)
return;
}
}
fprintf(stderr, "\t Article non trouvé.\n");
*index = -1;
return;
}
void supprimerArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique)
{
int ref, index;
affichSupprimerArticle(&ref);
rechercheRefArticle(tRef, ref, &index, *tLogique);
for( int i = index; i< *tLogique-1; ++i)
for( int i = index; i < *tLogique-1; ++i)
{
tRef[i] = tRef[i+1];
tPoids[i] = tPoids[i+1];

@ -20,9 +20,10 @@ void affiche_resp(void){
printf("||\t2 : Afficher un article \t \t \t \t || \n");
printf("||\t3 : Afficher un client \t \t \t \t \t || \n");
printf("||\t4 : Afficher les clients \t \t \t \t || \n");
printf("||\t5 : Supprimer un article \t \t \t \t || \n");
printf("||\t6 : Modifier un article \t \t \t \t || \n");
printf("||\t7 : Réinitialiser le panier. \t \t \t \t || \n");
printf("||\t5 : Ajouter un article \t \t \t \t \t || \n");
printf("||\t6 : Supprimer un article \t \t \t \t || \n");
printf("||\t7 : Modifier un article \t \t \t \t || \n");
printf("||\t9 : Quittez. \t \t \t \t \t \t || \n");
printf("+-----------------------------------------------------------------+\n");
}
/*
@ -47,9 +48,10 @@ void affiche_resp(int a){
void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique)
{
printf("\t Liste des articles \n\n");
printf("\t Ref\t Poids\t Volume\t Prix\n");
for ( int i = 0; i < tLogique; ++i)
{
printf("\t %d %.2f %.2f %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
printf("\t %d\t %.2f\t %.2f\t %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
}
}
@ -62,11 +64,12 @@ void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], in
printf("\tEntrez une référence valide\n");
while(getchar() != '\n');
}
printf("\t Ref\t Poids\t Volume\t Prix\n");
for ( int i = 0; i < tLogique; ++i)
{
if ( ref == tRef[i] )
{
printf("\t %d %.2f %.2f %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
printf("\t %d\t %.2f\t %.2f\t %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
return;
}
}
@ -82,11 +85,12 @@ void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogiqu
printf("\t Veuillez entrez un numéro valide !\n");
while(getchar() != '\n');
}
printf("\t NumClient\t Cagnotte\t Etat\n");
for ( int i = 0; i < tLogique; ++i)
{
if ( numC == tNumClient[i] )
{
printf("\t %d %.2f %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]);
printf("\t %d\t\t %.2f\t %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]);
return;
}
}
@ -96,59 +100,46 @@ void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogiqu
void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique)
{
printf("\t Liste des clients\n");
printf("\t NumClient\t Cagnotte\t Etat\n");
for ( int i = 0; i < tLogique; ++i)
{
printf("\t %d %.2f %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]);
printf("\t %d\t\t %.2f\t\t %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]);
}
printf("\t Fin de la liste ! \n");
}
void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
{
printf("Entrez la ref du nouveaux produit\n");
scanf("%d", ref);
if ( *ref < 0 )
printf("\t Entrez la ref du nouveaux produit\n");
while(scanf("%d", ref) != 1 || *ref <= 0)
{
while ( *ref < 0 )
{
printf("Entrez un nombre correct !\n");
scanf("%d", ref);
}
printf("\t Veuillez entrer une référence valide.\n");
while(getchar() != '\n');
}
printf("Entrez le poids du nouveaux produit\n");
scanf("%f", poids);
if ( *poids < 0 )
printf("\t Entrez le poids du nouveaux produit\n");
while(scanf("%f", poids) != 1 || *poids <= 0)
{
while ( *poids < 0 )
{
printf("Entrez un nombre correct !\n");
scanf("%f", poids);
}
printf("\t Veuillez entrer un poids valide.\n");
while(getchar() != '\n');
}
printf("Entrez le volume du nouveaux produit\n");
scanf("%f", volume);
if ( *volume < 0 )
printf("\t Entrez le volume du nouveaux produit\n");
while(scanf("%f", volume) != 1 || *volume <= 0)
{
while ( *volume < 0 )
{
printf("Entrez un poids correct !\n");
scanf("%f", poids);
}
printf("\t Veuillez entrer un volume valide.\n");
while(getchar() != '\n');
}
printf("Entrez le prix du nouveaux produit\n");
scanf("%f", prix);
if ( *prix < 0 )
printf("\t Entrez le prix du nouveaux produit\n");
while(scanf("%f", prix) != 1 || *prix <= 0)
{
while ( *prix < 0 )
{
printf("Entrez un prix correct !\n");
scanf("%f", prix);
}
printf("\t Veuillez entrer un prix valide.\n");
while(getchar() != '\n');
}
}
void affichSupprimerArticle(int *ref)
{
printf("\t Quel est la référence de l'article voulez-vous supprimez\n");
@ -173,21 +164,21 @@ void affichModifierArticle(int *ref, float *poids, float *volume, float *prix)
printf("\t Quel est le nouveau poids à entrer ?\n");
while(scanf("%f", poids) != 1 || *poids <= 0)
{
printf("\t Veuillez entrer un poids correct !");
printf("\t Veuillez entrer un poids correct !\n");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau volume à entrer ?\n");
while(scanf("%f", volume) != 1 || *volume <= 0)
{
printf("\t Veuillez entrer un volume correct !");
printf("\t Veuillez entrer un volume correct !\n");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau prix à entrer ?\n");
while(scanf("%f", prix) != 1 || *prix <= 0)
{
printf("\t Veuillez entrer un prix correct !");
printf("\t Veuillez entrer un prix correct !\n");
while (getchar() != '\n');
}
}
@ -217,7 +208,8 @@ void menu_resp(int *choix) {
}
void global_resp(){
int choix;
int choix, ref = 0;
float poids = 0, volume = 0 , prix = 0;
int tRef[MAX_ARTICLES];
float tPoids[MAX_ARTICLES];
float tVol[MAX_ARTICLES];
@ -247,20 +239,25 @@ void global_resp(){
affichClients(tNumClient, tCagnotte, tSus, tLogClient);
break;
case 5:
supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle);
ajouterArticle(tRef, tPoids, tVol, tPrix, &tLogArticle, MAX_ARTICLES, ref, poids, volume, prix);
break;
case 6:
modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle);
supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle);
break;
case 7:
printf("Ouai tkt ^^'");
modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle);
break;
case 8:
printf("Ouai tkt ^^'\n");
break;
case 9:
sauvegardArticles(tRef, tPoids, tVol, tPrix, tLogArticle);
affichArticles(tRef, tPoids, tVol, tPrix, tLogArticle);
return;
default:
printf("Veuillez entrer un choix valide ! \n");
break;
}
} while (choix != 9);
sauvegardArticles(tRef, tPoids, tVol, tPrix, tLogArticle);
}

@ -5,6 +5,7 @@ void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique
void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix);
void affichSupprimerArticle(int *ref);
void affichModifierArticle(int *ref, float *poids, float *volume, float *prix);
void problemRechercheArticle();
void menu_resp(int *choix);
void global_resp();
void affiche_resp(void);
Loading…
Cancel
Save