Debbug des fonctions jusque Ajout de points

master
Antoine PEREDERII 2 years ago
parent 5a634983b6
commit f7bfcccae4

@ -21,15 +21,16 @@ void AffichageNbAdherents(int nbElem);
void GestionMenus(void); void GestionMenus(void);
/* Fonction de sauvegarde */ /* 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 */ /* Fonctions de gestion des adhérents */
int RechercheAdherent(int tNoCarte[], int nbElem, int NoCarte, int *trouve); 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); int AjoutAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int tMax, int nbElem);
void ModificationAge(int tNoCarte[], int tAge[], int nbElem); void ModificationAge(int tNoCarte[], int tAge[], int nbElem);
int SupprimerAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int nbElem); int SupprimerAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int nbElem);
void ModificationActivationCarte(int tNoCarte[], int tCarteActive[], int nbElem); void ModificationActivationCarte(int tNoCarte[], int tCarteActive[], int nbElem);
/* Fonctions de gestion des points */ /* 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); void DebitActivitee(int tNoCarte[], int tCarteActive[], int tNbActivitesJour[], int nbElem);

@ -1,20 +1,15 @@
#include "Fonctions.h" #include "Fonctions.h"
int RechercheAdherent(int tNoCarte[], int nbElem, int noCarte, int *trouve) int RechercheAjoutAdherent(int tNoCarte[], int nbElem, int noCarte)
{ {
int i; int i;
for (i = 0; i < nbElem; i++) while(i < nbElem)
{ {
if (tNoCarte[i] == noCarte) if(tNoCarte[i] != i + 1)
{ {
*trouve = 1;
return i; return i;
} }
else if (tNoCarte[i] > noCarte) i++;
{
*trouve = 0;
return i + 1;
}
} }
} }
@ -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("Vous voulez créer un nouvel adhérent.\n");
printf("Donnez l'âge de l'adhérent : "); printf("Donnez l'âge de l'adhérent : ");
scanf("%d", &age); scanf("%d", &age);
pas = RechercheAdherent(tNoCarte, nbElem, noCarte, &trouve); pas = RechercheAjoutAdherent(tNoCarte, nbElem, noCarte);
printf("%d\n", pas);
for (j = nbElem; j > pas; j--) for (j = nbElem; j > pas; j--)
{ {
if (j == tMax) if (j == tMax)
@ -40,13 +34,12 @@ int AjoutAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActi
tCarteActive[j] = tCarteActive[j - 1]; tCarteActive[j] = tCarteActive[j - 1];
} }
tNoCarte[pas] = pas + 1; tNoCarte[pas] = pas + 1;
printf("%d\n", tNoCarte[pas]);
tAge[pas] = age; tAge[pas] = age;
tPointsCarte[pas] = 0; tPointsCarte[pas] = 0;
tCarteActive[pas] = 0; tCarteActive[pas] = 0;
nbElem++; 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]); 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; return nbElem;
} }
@ -61,7 +54,7 @@ void ModificationAge(int tNoCarte[], int tAge[], int nbElem)
printf("Entrez le nouvel âge de l'adhérent : "); printf("Entrez le nouvel âge de l'adhérent : ");
scanf("%d", &age); scanf("%d", &age);
tAge[pas] = 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 else
{ {

@ -1,10 +1,26 @@
#include "Fonctions.h" #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; int i;
printf("Entrez le numéro de la carte de l'adhérent recherché : "); for (i = 0; i < nbElem; i++)
scanf("%d", &noCarte); {
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); pas = RechercheAdherent(tNoCarte, nbElem, noCarte, &trouve);
if (trouve == 1) if (trouve == 1)
{ {
@ -12,25 +28,25 @@ void AjoutPoints(int tNoCarte[], int tPointsCarte[], int tCarteActive[], int nbE
scanf("%d", &pointsCarte); scanf("%d", &pointsCarte);
if (pointsCarte > 0 && pointsCarte <= 20) if (pointsCarte > 0 && pointsCarte <= 20)
{ {
tPointsCarte[pas] = pointsCarte; tPointsCarte[pas] = tPointsCarte[pas] + pointsCarte;
tCarteActive[pas] = 1; tCarteActive[pas] = 1;
printf("La carte est active.\n"); printf("La carte est active.\n");
} }
else if (pointsCarte > 20 && pointsCarte <= 50) 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; tCarteActive[pas] = 1;
printf("Merci pour votre achat. Nous vous offrons 5%% supplémentaires.\nDe plus, votre carte est active.\n"); printf("Merci pour votre achat. Nous vous offrons 5%% supplémentaires.\nDe plus, votre carte est active.\n");
} }
else if (pointsCarte > 50 && pointsCarte <= 100) 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; tCarteActive[pas] = 1;
printf("Merci pour votre achat. Nous vous offrons 10%% supplémentaires.\nDe plus, votre carte est active.\n"); printf("Merci pour votre achat. Nous vous offrons 10%% supplémentaires.\nDe plus, votre carte est active.\n");
} }
else if (pointsCarte > 100) else if (pointsCarte > 100)
{ {
tPointsCarte[pas] = pointsCarte + pointsCarte * (1 + (15 / 100.0)); tPointsCarte[pas] = tPointsCarte[pas] + pointsCarte * (1 + (15 / 100.0));
tCarteActive[pas] = 1; tCarteActive[pas] = 1;
printf("Merci pour votre achat. Nous vous offrons 15%% supplémentaires.\nDe plus, votre carte est active.\n"); printf("Merci pour votre achat. Nous vous offrons 15%% supplémentaires.\nDe plus, votre carte est active.\n");
} }

@ -25,7 +25,7 @@ void GestionMenus(void)
{ {
int tNoCarte[20] = {0}, tAge[20] = {0}, tPointsCarte[20] = {0}, tCarteActive[20] = {0}; int tNoCarte[20] = {0}, tAge[20] = {0}, tPointsCarte[20] = {0}, tCarteActive[20] = {0};
int tDate[20] = {0}, tNbActivitesJour[20] = {0}; int tDate[20] = {0}, tNbActivitesJour[20] = {0};
int tMax = 20, nbElem, choix, pasAct; int tMax = 20, nbElem, choix, pasAct, noCarte;
char choixA; char choixA;
nbElem = Ouverture(tNoCarte, tAge, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, tMax, &pasAct); nbElem = Ouverture(tNoCarte, tAge, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, tMax, &pasAct);
if (nbElem < 0) if (nbElem < 0)
@ -78,8 +78,9 @@ void GestionMenus(void)
} }
if (choix == 5) if (choix == 5)
{ {
printf("Saisissez le numéro de la carte à créditer :");
AjoutPoints(tNoCarte, tPointsCarte, tCarteActive, nbElem); scanf("%d", &noCarte);
AjoutPoints(tNoCarte, tPointsCarte, tCarteActive, nbElem, noCarte);
} }
if (choix == 6) if (choix == 6)
{ {
@ -91,6 +92,6 @@ void GestionMenus(void)
} }
choix = ChoixMenu(); choix = ChoixMenu();
} }
Sauvegarde(tNoCarte, tAge, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, nbElem); Sauvegarde(tNoCarte, tAge, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, nbElem, pasAct);
exit(1); exit(1);
} }

@ -1,11 +1,11 @@
#include "Fonctions.h" #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; int i, j;
FILE *flot, *jour; FILE *flot, *jour;
flot = fopen("membres.don", "a"); flot = fopen("membres.don", "w");
jour = fopen("ActivitesJour.don", "a"); jour = fopen("ActivitesJour.don", "w");
if (flot == NULL) if (flot == NULL)
{ {
printf("Problème d'ouverture du fichier membres.don en écriture.\n"); printf("Problème d'ouverture du fichier membres.don en écriture.\n");

BIN
exe

Binary file not shown.

@ -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 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}; 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) int main(void)

Loading…
Cancel
Save