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 464 50.000000 25.500000 60.000000
233 10.00 15.00 32.00 958 4.750000 60.000000 32.000000
272 6.500 10.00 29.99 101 1.000000 1.000000 1.000000
464 50.0 25.50 60.00
958 4.75 60.00 32.00

@ -36,18 +36,17 @@ void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[],
fe = fopen("donnee/articles.txt", "w"); fe = fopen("donnee/articles.txt", "w");
if ( fe == NULL) if ( fe == NULL)
{ {
perror("fopen"); fprintf(stderr, "\n Problème ouverture ficher\n");
return; return;
} }
for ( i = 0; i < tLogique; i++) 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); 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 ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique, int tPhysique, int ref, float poids, float volume, float prix)
{ {
int i = *tLogique; int i = *tLogique;
@ -57,14 +56,14 @@ int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int
fprintf(stderr,"Tableau plein !"); fprintf(stderr,"Tableau plein !");
return -2; return -2;
} }
printf("%d\n", *tLogique);
// SI on trie pas par ref c'est ca
tRef[i] = ref; tRef[i] = ref;
tPoids[i] = poids; tPoids[i] = poids;
tVol[i] = volume; tVol[i] = volume;
tPrix[i] = prix; tPrix[i] = prix;
(*tLogique)++;
printf("%d\n", *tLogique);
return 0; return 0;
} }
void rechercheRefArticle(int tRef[], int ref, int *index, int tLogique) 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; return;
} }
} }
fprintf(stderr, "\t Article non trouvé.\n");
*index = -1; *index = -1;
return; return;
} }
void supprimerArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique) void supprimerArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique)
{ {
int ref, index; int ref, index;
affichSupprimerArticle(&ref); affichSupprimerArticle(&ref);
rechercheRefArticle(tRef, ref, &index, *tLogique); 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]; tRef[i] = tRef[i+1];
tPoids[i] = tPoids[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("||\t2 : Afficher un article \t \t \t \t || \n");
printf("||\t3 : Afficher un client \t \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("||\t4 : Afficher les clients \t \t \t \t || \n");
printf("||\t5 : Supprimer un article \t \t \t \t || \n"); printf("||\t5 : Ajouter un article \t \t \t \t \t || \n");
printf("||\t6 : Modifier un article \t \t \t \t || \n"); printf("||\t6 : Supprimer un article \t \t \t \t || \n");
printf("||\t7 : Réinitialiser le panier. \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"); printf("+-----------------------------------------------------------------+\n");
} }
/* /*
@ -47,9 +48,10 @@ void affiche_resp(int a){
void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique) void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique)
{ {
printf("\t Liste des articles \n\n"); printf("\t Liste des articles \n\n");
printf("\t Ref\t Poids\t Volume\t Prix\n");
for ( int i = 0; i < tLogique; ++i) 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"); printf("\tEntrez une référence valide\n");
while(getchar() != '\n'); while(getchar() != '\n');
} }
printf("\t Ref\t Poids\t Volume\t Prix\n");
for ( int i = 0; i < tLogique; ++i) for ( int i = 0; i < tLogique; ++i)
{ {
if ( ref == tRef[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; return;
} }
} }
@ -82,11 +85,12 @@ void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogiqu
printf("\t Veuillez entrez un numéro valide !\n"); printf("\t Veuillez entrez un numéro valide !\n");
while(getchar() != '\n'); while(getchar() != '\n');
} }
printf("\t NumClient\t Cagnotte\t Etat\n");
for ( int i = 0; i < tLogique; ++i) for ( int i = 0; i < tLogique; ++i)
{ {
if ( numC == tNumClient[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; 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) void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique)
{ {
printf("\t Liste des clients\n"); printf("\t Liste des clients\n");
printf("\t NumClient\t Cagnotte\t Etat\n");
for ( int i = 0; i < tLogique; ++i) 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"); printf("\t Fin de la liste ! \n");
} }
void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix) void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
{ {
printf("Entrez la ref du nouveaux produit\n"); printf("\t Entrez la ref du nouveaux produit\n");
scanf("%d", ref); while(scanf("%d", ref) != 1 || *ref <= 0)
if ( *ref < 0 )
{ {
while ( *ref < 0 ) printf("\t Veuillez entrer une référence valide.\n");
{ while(getchar() != '\n');
printf("Entrez un nombre correct !\n");
scanf("%d", ref);
}
} }
printf("Entrez le poids du nouveaux produit\n");
scanf("%f", poids); printf("\t Entrez le poids du nouveaux produit\n");
if ( *poids < 0 ) while(scanf("%f", poids) != 1 || *poids <= 0)
{ {
while ( *poids < 0 ) printf("\t Veuillez entrer un poids valide.\n");
{
printf("Entrez un nombre correct !\n"); while(getchar() != '\n');
scanf("%f", poids);
}
} }
printf("Entrez le volume du nouveaux produit\n");
scanf("%f", volume); printf("\t Entrez le volume du nouveaux produit\n");
if ( *volume < 0 ) while(scanf("%f", volume) != 1 || *volume <= 0)
{ {
while ( *volume < 0 ) printf("\t Veuillez entrer un volume valide.\n");
{ while(getchar() != '\n');
printf("Entrez un poids correct !\n");
scanf("%f", poids);
}
} }
printf("Entrez le prix du nouveaux produit\n");
scanf("%f", prix); printf("\t Entrez le prix du nouveaux produit\n");
if ( *prix < 0 ) while(scanf("%f", prix) != 1 || *prix <= 0)
{ {
while ( *prix < 0 ) printf("\t Veuillez entrer un prix valide.\n");
{ while(getchar() != '\n');
printf("Entrez un prix correct !\n");
scanf("%f", prix);
}
} }
} }
void affichSupprimerArticle(int *ref) void affichSupprimerArticle(int *ref)
{ {
printf("\t Quel est la référence de l'article voulez-vous supprimez\n"); 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"); printf("\t Quel est le nouveau poids à entrer ?\n");
while(scanf("%f", poids) != 1 || *poids <= 0) 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'); while (getchar() != '\n');
} }
printf("\t Quel est le nouveau volume à entrer ?\n"); printf("\t Quel est le nouveau volume à entrer ?\n");
while(scanf("%f", volume) != 1 || *volume <= 0) 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'); while (getchar() != '\n');
} }
printf("\t Quel est le nouveau prix à entrer ?\n"); printf("\t Quel est le nouveau prix à entrer ?\n");
while(scanf("%f", prix) != 1 || *prix <= 0) 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'); while (getchar() != '\n');
} }
} }
@ -217,7 +208,8 @@ void menu_resp(int *choix) {
} }
void global_resp(){ void global_resp(){
int choix; int choix, ref = 0;
float poids = 0, volume = 0 , prix = 0;
int tRef[MAX_ARTICLES]; int tRef[MAX_ARTICLES];
float tPoids[MAX_ARTICLES]; float tPoids[MAX_ARTICLES];
float tVol[MAX_ARTICLES]; float tVol[MAX_ARTICLES];
@ -247,20 +239,25 @@ void global_resp(){
affichClients(tNumClient, tCagnotte, tSus, tLogClient); affichClients(tNumClient, tCagnotte, tSus, tLogClient);
break; break;
case 5: case 5:
supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle); ajouterArticle(tRef, tPoids, tVol, tPrix, &tLogArticle, MAX_ARTICLES, ref, poids, volume, prix);
break; break;
case 6: case 6:
modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle); supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle);
break; break;
case 7: case 7:
printf("Ouai tkt ^^'"); modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle);
break;
case 8:
printf("Ouai tkt ^^'\n");
break; break;
case 9: case 9:
sauvegardArticles(tRef, tPoids, tVol, tPrix, tLogArticle);
affichArticles(tRef, tPoids, tVol, tPrix, tLogArticle);
return; return;
default: default:
printf("Veuillez entrer un choix valide ! \n"); printf("Veuillez entrer un choix valide ! \n");
break; break;
} }
} while (choix != 9); } 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 affichAjoutArticle(int *ref, float *poids, float *volume, float *prix);
void affichSupprimerArticle(int *ref); void affichSupprimerArticle(int *ref);
void affichModifierArticle(int *ref, float *poids, float *volume, float *prix); void affichModifierArticle(int *ref, float *poids, float *volume, float *prix);
void problemRechercheArticle();
void menu_resp(int *choix); void menu_resp(int *choix);
void global_resp(); void global_resp();
void affiche_resp(void); void affiche_resp(void);
Loading…
Cancel
Save