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 58f7e82..e2d36db 100755 Binary files a/exe and b/exe differ 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)