From f7bfcccae4cd87785c8a2455ce04d7090106bf69 Mon Sep 17 00:00:00 2001 From: "antoine.perederii" Date: Fri, 11 Nov 2022 00:47:34 +0100 Subject: [PATCH] Debbug des fonctions jusque Ajout de points --- Fonctions.h | 5 +++-- GestionAdherents.c | 21 +++++++-------------- GestionPoints.c | 32 ++++++++++++++++++++++++-------- Global.c | 9 +++++---- Sauvegarde.c | 6 +++--- exe | Bin 30400 -> 30432 bytes main.c | 2 +- 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Fonctions.h b/Fonctions.h index b1b7aca..198fee7 100644 --- a/Fonctions.h +++ b/Fonctions.h @@ -21,15 +21,16 @@ void AffichageNbAdherents(int nbElem); void GestionMenus(void); /* Fonction de sauvegarde */ -int Sauvegarde(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int tNbActivitesJour[], int tDate[], int nbElem); +int Sauvegarde(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int tNbActivitesJour[], int tDate[], int nbElem, int pasAct); /* Fonctions de gestion des adhérents */ int RechercheAdherent(int tNoCarte[], int nbElem, int NoCarte, int *trouve); +int RechercheAjoutAdherent(int tNoCarte[], int nbElem, int noCarte); int AjoutAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int tMax, int nbElem); void ModificationAge(int tNoCarte[], int tAge[], int nbElem); int SupprimerAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int nbElem); void ModificationActivationCarte(int tNoCarte[], int tCarteActive[], int nbElem); /* Fonctions de gestion des points */ -void AjoutPoints(int tNoCarte[], int tPointsCarte[], int tCarteActive[], int nbElem); +void AjoutPoints(int tNoCarte[], int tPointsCarte[], int tCarteActive[], int nbElem, int noCarte); void DebitActivitee(int tNoCarte[], int tCarteActive[], int tNbActivitesJour[], int nbElem); \ No newline at end of file diff --git a/GestionAdherents.c b/GestionAdherents.c index b03e9c6..2ca497f 100644 --- a/GestionAdherents.c +++ b/GestionAdherents.c @@ -1,20 +1,15 @@ #include "Fonctions.h" -int RechercheAdherent(int tNoCarte[], int nbElem, int noCarte, int *trouve) +int RechercheAjoutAdherent(int tNoCarte[], int nbElem, int noCarte) { int i; - for (i = 0; i < nbElem; i++) + while(i < nbElem) { - if (tNoCarte[i] == noCarte) + if(tNoCarte[i] != i + 1) { - *trouve = 1; return i; } - else if (tNoCarte[i] > noCarte) - { - *trouve = 0; - return i + 1; - } + i++; } } @@ -25,8 +20,7 @@ int AjoutAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActi printf("Vous voulez créer un nouvel adhérent.\n"); printf("Donnez l'âge de l'adhérent : "); scanf("%d", &age); - pas = RechercheAdherent(tNoCarte, nbElem, noCarte, &trouve); - printf("%d\n", pas); + pas = RechercheAjoutAdherent(tNoCarte, nbElem, noCarte); for (j = nbElem; j > pas; j--) { if (j == tMax) @@ -40,13 +34,12 @@ int AjoutAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActi tCarteActive[j] = tCarteActive[j - 1]; } tNoCarte[pas] = pas + 1; - printf("%d\n", tNoCarte[pas]); tAge[pas] = age; tPointsCarte[pas] = 0; tCarteActive[pas] = 0; nbElem++; printf("Vous avez créé l'adhérent numéro %d. Il a %d ans.\nSa carte n'est pas active car il n'y a pas de points dessus.\nIl est nécessaire de créditer la carte.\n", tNoCarte[pas], tAge[pas]); - AjoutPoints(tNoCarte, tPointsCarte, tCarteActive, nbElem); + AjoutPoints(tNoCarte, tPointsCarte, tCarteActive, nbElem, tNoCarte[pas]); return nbElem; } @@ -61,7 +54,7 @@ void ModificationAge(int tNoCarte[], int tAge[], int nbElem) printf("Entrez le nouvel âge de l'adhérent : "); scanf("%d", &age); tAge[pas] = age; - printf("Vous avez modifié l'âge de l'adhérent numéro %d. Son nouvel âge est %d.\n", noCarte, age); + printf("Vous avez modifié l'âge de l'adhérent avec le numéro de carte %d. Son nouvel âge est de %d ans.\n", noCarte, age); } else { diff --git a/GestionPoints.c b/GestionPoints.c index 0e5b5d0..61503ad 100644 --- a/GestionPoints.c +++ b/GestionPoints.c @@ -1,10 +1,26 @@ #include "Fonctions.h" -void AjoutPoints(int tNoCarte[], int tPointsCarte[], int tCarteActive[], int nbElem) +int RechercheAdherent(int tNoCarte[], int nbElem, int noCarte, int *trouve) { - int pointsCarte, noCarte, trouve, pas; - printf("Entrez le numéro de la carte de l'adhérent recherché : "); - scanf("%d", &noCarte); + int i; + for (i = 0; i < nbElem; i++) + { + if (tNoCarte[i] == noCarte) + { + *trouve = 1; + return i; + } + else if (tNoCarte[i] > noCarte) + { + *trouve = 0; + return i + 1; + } + } +} + +void AjoutPoints(int tNoCarte[], int tPointsCarte[], int tCarteActive[], int nbElem, int noCarte) +{ + int pointsCarte, trouve, pas; pas = RechercheAdherent(tNoCarte, nbElem, noCarte, &trouve); if (trouve == 1) { @@ -12,25 +28,25 @@ void AjoutPoints(int tNoCarte[], int tPointsCarte[], int tCarteActive[], int nbE scanf("%d", &pointsCarte); if (pointsCarte > 0 && pointsCarte <= 20) { - tPointsCarte[pas] = pointsCarte; + tPointsCarte[pas] = tPointsCarte[pas] + pointsCarte; tCarteActive[pas] = 1; printf("La carte est active.\n"); } else if (pointsCarte > 20 && pointsCarte <= 50) { - tPointsCarte[pas] = pointsCarte + pointsCarte * (1 + (5 / 100.0)); + tPointsCarte[pas] = tPointsCarte[pas] + pointsCarte * (1 + (5 / 100.0)); tCarteActive[pas] = 1; printf("Merci pour votre achat. Nous vous offrons 5%% supplémentaires.\nDe plus, votre carte est active.\n"); } else if (pointsCarte > 50 && pointsCarte <= 100) { - tPointsCarte[pas] = pointsCarte + pointsCarte * (1 + (10 / 100.0)); + tPointsCarte[pas] = tPointsCarte[pas] + pointsCarte * (1 + (10 / 100.0)); tCarteActive[pas] = 1; printf("Merci pour votre achat. Nous vous offrons 10%% supplémentaires.\nDe plus, votre carte est active.\n"); } else if (pointsCarte > 100) { - tPointsCarte[pas] = pointsCarte + pointsCarte * (1 + (15 / 100.0)); + tPointsCarte[pas] = tPointsCarte[pas] + pointsCarte * (1 + (15 / 100.0)); tCarteActive[pas] = 1; printf("Merci pour votre achat. Nous vous offrons 15%% supplémentaires.\nDe plus, votre carte est active.\n"); } diff --git a/Global.c b/Global.c index e4375c6..51be9fb 100644 --- a/Global.c +++ b/Global.c @@ -25,7 +25,7 @@ void GestionMenus(void) { int tNoCarte[20] = {0}, tAge[20] = {0}, tPointsCarte[20] = {0}, tCarteActive[20] = {0}; int tDate[20] = {0}, tNbActivitesJour[20] = {0}; - int tMax = 20, nbElem, choix, pasAct; + int tMax = 20, nbElem, choix, pasAct, noCarte; char choixA; nbElem = Ouverture(tNoCarte, tAge, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, tMax, &pasAct); if (nbElem < 0) @@ -78,8 +78,9 @@ void GestionMenus(void) } if (choix == 5) { - - AjoutPoints(tNoCarte, tPointsCarte, tCarteActive, nbElem); + printf("Saisissez le numéro de la carte à créditer :"); + scanf("%d", &noCarte); + AjoutPoints(tNoCarte, tPointsCarte, tCarteActive, nbElem, noCarte); } if (choix == 6) { @@ -91,6 +92,6 @@ void GestionMenus(void) } choix = ChoixMenu(); } - Sauvegarde(tNoCarte, tAge, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, nbElem); + Sauvegarde(tNoCarte, tAge, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, nbElem, pasAct); exit(1); } \ No newline at end of file diff --git a/Sauvegarde.c b/Sauvegarde.c index 1ecb4fb..59636f6 100644 --- a/Sauvegarde.c +++ b/Sauvegarde.c @@ -1,11 +1,11 @@ #include "Fonctions.h" -int Sauvegarde(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int tNbActivitesJour[], int tDate[], int nbElem) +int Sauvegarde(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int tNbActivitesJour[], int tDate[], int nbElem, int pasAct) { int i, j; FILE *flot, *jour; - flot = fopen("membres.don", "a"); - jour = fopen("ActivitesJour.don", "a"); + flot = fopen("membres.don", "w"); + jour = fopen("ActivitesJour.don", "w"); if (flot == NULL) { printf("Problème d'ouverture du fichier membres.don en écriture.\n"); diff --git a/exe b/exe index 58f7e823161cf3311d39775c58936868d9c98d67..e2d36db040085277b11f2d3af9482b713356bab9 100755 GIT binary patch delta 5049 zcmai14OEm>8veck3>5iM1cm`-5EKxUA7wR_VxrM;6#*6NY*LLdzyJaQLm3(x(rL~# zrstZ~YP;HYT+!U5vA+|oBAIApRIFKQO6KWf!LyKPXwpWJdmR7xj`+(yA4YNP`j7L>nHJ= zLqY3KM_=A)+xQ8oDn8=dzBK+&Z`LWdpt&>A|BQj-%&v(AOr$rv2Lp7x=2vgG-=uPl zrZ1kf1OD7rGCs=7da;(7V2}z0^;5hUT)inC1LH84B)9M>$sL%jJj8>Hzr%=wL$h={*D{IJU@1!e4 zyR{w5&x#yEk^W897=k&5GXMP++k*M(-0v`hvIWn_D$L*B5;Kq#ZIge~F1q}#^i0Z7 zBr%MZYnK@MrMA7KGQ4_=78P;`}t<@uHPCSh| zz+9ML1GMY3&HX?Y^=A)%T+D%d%^n8Q5x6F>b^Ny_U2OXv^*5SM^r@fo*O4{UXb{?^lq$ayGtVJKF zX>A!AyJVfJy%~0t+;sfuLWsuUpoTR#$YYLKw9~{+k~h5rNS-;$VS;0TKjR1>m%<|! z7J^f_dIP=k!sHT}|F##TmNpKj`oGY~^s(eJH%In{hiK9gNlV1ixh0gMl-)9rPwE(o z!v9CXzebKkJdpOTx*~&PI*DO7X2GDI#d)jA^mZ{NeoY+4Sz{|b@3EhcN zj-a8R;+njFg9C0#`QKQ&m`aXCz9BhNX_#@WN}PX_QjNV@a;yxbpo+kMoFQs=w&KD^L zN0%kFAxcTASfELyKL>-bfEQ^CP{VTA*CWV}J05^Uu8ncHSh9*aBNgPn?Z zG9~0X#!bilwFhMEYL*{2Y~y9m2GGiJ_#S$e@bfmHBF5X`Q;e#YZU z`!~fa`357hZxc(l)2>Id#gsOH(#o?2DO`OU*iD`c%vzXQIhJ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cJR)Cc3T$`_ ztCBv4te8?)xET7Wqbnxs(%7ZPamGjHw-tX~1m)pU?^$D2srQC)kwVo$GL<#0JIjp;Mfa~=8iypde?_?qk*Zhm!oO?9Kwl5WqjG&$27s+-cQYn--b z%VdtD`dKf~Rbxc_LWe!w?r=3*>e7$Cw$hT$EVFCcIhCk%# zGw>I(oi90)=Rip`7$LOhwRDM0Z z1gM=30=fXGGI3lomQ{r1?m~8)F*52IVfN_ZAv=VK5n&u!jVr?ZdtH=RnJO$jN%uj# ze~KQjOwHJE`u{r}g3}-!tW3(j!00~-1`T*0+@X&PRq2N?KaFm}G8qZ1L3vWK%sZBb z5Y@5>^DZh}kQBNYnuQ*NwgK7?v<}*CXjSwQv_sIg(?Mt#p!Luf(1xI$rJK-_!Cpy* zhh~S?LbLj-A9{8a+Sy9tl6(1Df5wwPgz&W#zC7Qc{zr>!v?qj%;gl}QOut%yZ zhDl|zX6_3Mj_U4Td^2aGI(AN!bQ?IHhpL&3OW{casKF4RzAGO>aeXX zv)Em~y5gQnJw1(9meBueUTRsFPc|w9dA?W@$~6 zYpKm{b8?bTrNd@-HgS!X8u;Q*wWgW%6KF&IpQ5!~)$sl-`-NfrHsYJ|!_^Z|ONC8y xS)H5mqt#Qa${y+jx~yC-h${E`dFM<4C)n6LJv?BOC-0}t&C~hc(81=M{{q@MAZh>r diff --git a/main.c b/main.c index cee3edd..9f361f3 100644 --- a/main.c +++ b/main.c @@ -16,7 +16,7 @@ void testSauvegarde(void) { int tNoCarte[500] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, tage[500] = {22, 25, 47, 38, 18, 46, 36, 19, 21, 30}, tPointsCarte[500] = {10, 5, 7, 8, 8, 6, 6, 2, 1, 4}, tCarteActive[500] = {0, 1, 1, 1, 1, 1, 0, 1, 1, 1}; int tDate[500] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, tNbActivitesJour[500] = {500, 525, 740, 812, 850, 620, 601, 422, 501, 520}; - Sauvegarde(tNoCarte, tage, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, 10); + Sauvegarde(tNoCarte, tage, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, 10, 10); } int main(void)