From 0933f634f17e0414ab9738ea4a488c3dd19c5f82 Mon Sep 17 00:00:00 2001 From: Alexis LAURENT Date: Wed, 9 Nov 2022 10:22:43 +0100 Subject: [PATCH] =?UTF-8?q?mise=20=C3=A0=20jour=20du=209=20novembre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- activite.txt | 2 +- adherent.txt | 11 +++--- fonction.c | 97 ++++++++++++++++++++++++++++------------------------ fonction.h | 11 +++--- test.c | 35 +++++-------------- 5 files changed, 75 insertions(+), 81 deletions(-) diff --git a/activite.txt b/activite.txt index 0052ec9..af4a175 100644 --- a/activite.txt +++ b/activite.txt @@ -1,5 +1,5 @@ 5 9 14 8 12 11 13 6 28 -46 15 5 +45 12 0 47 6 18 diff --git a/adherent.txt b/adherent.txt index 391a9ee..a738b7d 100644 --- a/adherent.txt +++ b/adherent.txt @@ -1,6 +1,5 @@ -2 -14 -56 -69 -77 -89 +2 18 29 10 2022 1 +14 25 14 5 2007 1 +23 10 5 7 1000 1 +56 6 7 1 2015 0 +69 17 14 7 2016 1 diff --git a/fonction.c b/fonction.c index ccde440..f0bf538 100644 --- a/fonction.c +++ b/fonction.c @@ -18,7 +18,7 @@ int chargementAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[ fclose(flot); return -1; } - pos = ajouter(tabAdherent,i,adhe,tphys); + pos = ajouter(tabAdherent,tabPoints,jour,mois,annee,carte,i,adhe,tphys); if (pos >= 0) { tabPoints[pos] = points; jour[pos] = valjour; @@ -86,19 +86,24 @@ void decalageGauche(int tabTri[], int nb, int pos) { } -int ajouter(int tab[], int nb, int val, int tphys) { +int ajouter(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb, int val, int tmax) { int pos, trouve; - if (nb == tphys) { + if (nb == tmax) { printf("Impossible d'insérer un nouvel élément, le tableau est plein !\n"); return -1; } - pos = recherche(tab, val, nb, &trouve); + pos = recherche(tabAdhe, val, nb, &trouve); if (trouve == 1) { printf("Valeur déjà présente dans le tableau !\n"); return -1; } - decalageDroite(tab, nb, pos); - tab[pos] = val; + decalageDroite(tabAdhe, nb, pos); + decalageDroite(tabPoints, nb, pos); + decalageDroite(jour, nb, pos); + decalageDroite(mois, nb, pos); + decalageDroite(annee, nb, pos); + decalageDroite(carte, nb, pos); + tabAdhe[pos] = val; return pos; } @@ -107,7 +112,7 @@ int ajouterAdherent(int tabAdhe[], int tabPoints[], int jour[], int mois[], int printf("Nouveau numéro de carte : "); scanf("%d",&val); pos = recherche(tabAdhe, val, nb, &trouve); - coderetour = ajouter(tabAdhe, nb, val, tmax); + coderetour = ajouter(tabAdhe, tabPoints, jour, mois, annee, carte, nb, val, tmax); if (coderetour == -1) { printf("Erreur ajout du nouvel élement !\n"); return nb; @@ -131,7 +136,16 @@ int ajouterAdherent(int tabAdhe[], int tabPoints[], int jour[], int mois[], int } -int suppression(int tab[], int tabPoints[], int nb, int val) { +int supprimerAdherent(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tailleL) { + int numAdhe; + printf("Numéro de l'adhérent à supprimer ?\n"); + scanf("%d",&numAdhe); + tailleL=suppression(tabAdhe,tabPoints,jour,mois,annee,carte,tailleL,numAdhe); + return tailleL; +} + + +int suppression(int tab[], int tabPoints[], int jour[], int mois[], int annee[], int carte[],int nb, int val) { int pos, trouve; if (nb == 0) { printf("Aucun élément à supprimer dans le tableau !\n"); @@ -140,6 +154,10 @@ int suppression(int tab[], int tabPoints[], int nb, int val) { pos = recherche(tab, val, nb, &trouve); decalageGauche(tab, nb, pos); decalageGauche(tabPoints, nb, pos); + decalageGauche(jour, nb, pos); + decalageGauche(mois, nb, pos); + decalageGauche(annee, nb, pos); + decalageGauche(carte,nb,pos); nb -= 1; return nb; @@ -171,44 +189,32 @@ void affichageCarte(int tabAdhe[], int tabPoints[], int jour[], int mois[], int } } -void affichageActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL) +void affichageToutActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL) { int i; printf("N°Activité \t Points \t Nombre Entrées \n"); for (i = 0; i < tailleL; i++) { if (tabCoutPoint[i] != 0) - printf("%d \t %d \t %d", i, tabCoutPoint[i], tabNbEntree[i]\n); + printf("%d \t\t %d \t\t %d\n", i, tabCoutPoint[i], tabNbEntree[i]); } } -void affichageToutActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL) +void affichageActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL) { - int i, num, trouve = 0; + int i, num; printf("Plus d'information de l'activité :"); scanf("%d", &num); - printf("N°Activité \t Points \t Nombre Entrées \n"); - for (i = 0; i < tailleL; i++) + if (tabCoutPoint[num] == 0) + printf("Le numéro d'activité n'éxiste pas\n"); + else { - if (i == num) - { - printf("%d \t %d \t %d", i, tabCoutPoint[i], tabNbEntree[i]\n); - trouve = 1; - } + printf("N°Activité \t Points \t Nombre Entrées \n"); + printf("%d \t\t %d \t\t %d\n", num, tabCoutPoint[num], tabNbEntree[num]); } - if (trouve == 0) - printf("Le numéro d'activité n'éxiste pas"); } -void affichageTest(int tabAdhe[], int nb) { - int i; - printf("Numéro de carte\n"); - for (i = 0 ; i < nb ; i++) { - printf("%d\n",tabAdhe[i]); - } -} - void afficheNbEntreAct(int tabNbEntree[], int tabCoutPoint[], int tphys) { @@ -228,7 +234,7 @@ void alimenterCarte (int tabAdherent[], int tabPoint[],int nb) int num, trouve, i; char formule; printf("numero carte :"); - scanf("%d",&num); + scanf("%d%*c",&num); i = recherche(tabAdherent, num, nb, &trouve); if (trouve == 1) { @@ -237,29 +243,29 @@ void alimenterCarte (int tabAdherent[], int tabPoint[],int nb) printf("B : 10€ -> 12 point\n"); printf("C : 15€ -> 20 point\n"); printf("Choisir :"); - scanf("%*c%c", &formule); - while (formule != 'A' || formule != 'B' || formule != 'C') + scanf("%c%*c", &formule); + while (formule != 'A' && formule != 'B' && formule != 'C') { printf("Erreur récupération de donnée\n"); printf("A : 5€ -> 5 points\n"); printf("B : 10€ -> 12 point\n"); printf("C : 15€ -> 20 point\n"); printf("Choisir :"); - scanf("%*c%c", &formule); + scanf("%c%*c", &formule); } if (formule == 'A') { - tabAdherent[i] = tabAdherent[i] + 5; + tabPoint[i] = tabPoint[i] + 5; printf("accréditation de 5 points\n"); } if (formule == 'B') { - tabAdherent[i] = tabAdherent[i] + 12; + tabPoint[i] = tabPoint[i] + 12; printf("accréditation de 12 points\n"); } if (formule == 'C') { - tabAdherent[i] = tabAdherent[i] + 20; + tabPoint[i] = tabPoint[i] + 20; printf("accréditation de 20 points\n"); } } @@ -280,7 +286,7 @@ void ajoutActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL) { printf("Coût de l'activité :"); scanf("%d", &nbPoint); - printf("\t Récapitulatif :"); + printf("\t Récapitulatif \n:"); printf("Numéro d'activité : %d\n", num); printf("Nombre de point : %d\n", nbPoint); tabCoutPoint[num] = nbPoint; @@ -293,7 +299,7 @@ void suppActivite(int tabCoutPoint[], int tabNbEntree[],int tailleL) int num; char choix; printf("Quel Activité voulez vous supprimer : "); - scanf("%d", &num); + scanf("%d%*c", &num); if (tabCoutPoint[num] == 0) printf("Numéro d'activité pas existant\n"); if (tailleL < num) @@ -301,11 +307,11 @@ void suppActivite(int tabCoutPoint[], int tabNbEntree[],int tailleL) else { printf("Êtes vous sûre de vouloir supprimer l'activité (O|N): "); - scanf("%*c%c", choix); - while(choix != 'N' || choix != 'O') + scanf("%c%*c", &choix); + while(choix != 'N' && choix != 'O') { printf("Êtes vous sûre de vouloir supprimer l'activité (O|N): "); - scanf("%*c%c", choix); + scanf("%c%*c", &choix); } if (choix == 'N') printf("Annulation de la suppression\n"); @@ -324,7 +330,7 @@ void faireActivite(int tabAdherent[], int tabPoint[],int tabCoutPoint[], int tab int num, idAct, i, trouve; printf("Identifiant Adhérent : "); scanf("%d", &num); - i = recherche(tabAdherent, num, tailleLAdhe, &trouve) + i = recherche(tabAdherent, num, tailleLAdhe, &trouve); if (trouve == 0) printf("Identifiant Adhérent pas existant\n"); else @@ -337,7 +343,10 @@ void faireActivite(int tabAdherent[], int tabPoint[],int tabCoutPoint[], int tab printf("Numéro d'activité que vous voulez pratiquer : "); scanf("%d", &idAct); if (idAct == -1) + { + printf("annulation réservation Activité !\n") exit(1); + } } if (tabCoutPoint[idAct] > tabPoint[i]) printf("Vous n'avez pas assez de point"); @@ -374,8 +383,8 @@ int SauvegardeActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL) return -1; } for (i = 0 ; i < tailleL ; i++) { - if (tabCoutPoint[num] != 0) - fprintf(flot,"%d %d %d",i, tabCoutPoint[i], tabNbEntree[i]); + if (tabCoutPoint[i] != 0) + fprintf(flot,"%d %d %d\n",i, tabCoutPoint[i], tabNbEntree[i]); } fclose(flot); return 0; diff --git a/fonction.h b/fonction.h index a139545..c5f74e9 100644 --- a/fonction.h +++ b/fonction.h @@ -1,4 +1,5 @@ #include +#include int chargementAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tphys); @@ -10,15 +11,15 @@ void decalageDroite(int tabTri[], int nb, int pos); void decalageGauche(int tabTri[], int nb, int pos); -int ajouter(int tab[], int nb, int val, int tphys); +int ajouter(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb, int val, int tmax); int ajouterAdherent(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb, int tmax); -int suppression(int tab[], int nb, int val); +int suppression(int tab[], int tabPoints[], int jour[], int mois[], int annee[], int carte[],int nb, int val); void affichageTous(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille); -void affichageCarte(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb) +void affichageCarte(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb); void affichageActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL); @@ -38,4 +39,6 @@ void faireActivite(int tabAdherent[], int tabPoint[],int tabCoutPoint[], int tab int SauvegardeAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tailleL); -int SauvegardeActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL); \ No newline at end of file +int SauvegardeActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL); + +int supprimerAdherent(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tailleL); \ No newline at end of file diff --git a/test.c b/test.c index 8ccf711..fb74ebf 100644 --- a/test.c +++ b/test.c @@ -3,31 +3,14 @@ int main(void) { - int tab[50], tailleL, codeSauv, coderetour=-1; - tailleL=chargementAdherent(tab,50); - affichageTest(tab,tailleL); - tailleL=ajouter(tab,tailleL,69,50); - affichageTest(tab,tailleL); - // tailleL=suppression(tab,tailleL,69); - // affichageTest(tab,tailleL); - printf("Sauvegarder ? (1 : Oui, 2 : Non)\n"); - scanf("%d",&codeSauv); - if (codeSauv == 1) { - - while(coderetour == -1) { - coderetour = SauvegardeAdherent(tab,tailleL); - if (coderetour == 0) { - printf("Sauvegarde réussie !\n"); - break; - } - else { - printf("Sauvegarde échouée\n"); - printf("Réessayer ?(1 : Oui, 2 : Non\n"); - scanf("%d",&codeSauv); - if (codeSauv == 2) break; - - } - } - } + int tabAdhe[50]={0}, tabPoints[50]={0}, jour[50]={0}, mois[50]={0}, annee[50]={0}, carte[50]={0}, tailleLAdhe, tabCoutPoint[50]={0}, tabNbEntree[50]={0}, tailleLAct; + tailleLAdhe=chargementAdherent(tabAdhe,tabPoints,jour,mois,annee,carte,50); + tailleLAct=chargementActivite(tabCoutPoint, tabNbEntree, 50); + tailleLAct=50; + affichageToutActivite(tabCoutPoint, tabNbEntree, tailleLAct); + faireActivite(tabAdhe, tabPoints, tabCoutPoint, tabNbEntree, tailleLAdhe, tailleLAct); + affichageTous(tabAdhe, tabPoints, jour, mois, annee, carte, tailleLAdhe); + SauvegardeActivite(tabCoutPoint, tabNbEntree, tailleLAct); + return 0; } \ No newline at end of file