diff --git a/fonction.c b/fonction.c index 12fd3e1..ccde440 100644 --- a/fonction.c +++ b/fonction.c @@ -1,28 +1,64 @@ #include "fonction.h" -int chargementAdherent(int tabAdherent[], int tphys) +int chargementAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tphys) { - int adhe, i =0; - FILE*flot; + int adhe, points, valjour, valmois, valannee, perdue, i = 0, pos; + FILE* flot; flot = fopen("adherent.txt","r"); - fscanf(flot,"%d",&adhe); + if (flot == NULL) { + printf("Erreur ouverture du fichier !\n"); + return -2; + } + fscanf(flot,"%d%d%d%d%d%d",&adhe,&points,&valjour,&valmois,&valannee,&perdue); while(!feof(flot)) { if(i >= tphys) { printf("tableau plein\n"); fclose(flot); - return i; + return -1; + } + pos = ajouter(tabAdherent,i,adhe,tphys); + if (pos >= 0) { + tabPoints[pos] = points; + jour[pos] = valjour; + mois[pos] = valmois; + annee[pos] = valannee; + carte[pos] = perdue; + i = i + 1; } - ajouter(tabAdherent,i,adhe,tphys); - i = i + 1; - fscanf(flot,"%d",&adhe); + fscanf(flot,"%d%d%d%d%d%d",&adhe,&points,&valjour,&valmois,&valannee,&perdue); + } + if (i == 0) printf("Fichier vide !\n"); + fclose(flot); + return i; +} + +int chargementActivite(int tabPoint[],int tabNbEntree[], int tphys) +{ + int num, point, nbEntree, i =0; + FILE*flot; + flot = fopen("activite.txt","r"); + fscanf(flot,"%d %d %d",&num, &point, &nbEntree); + while(!feof(flot)) + { + if(i >= tphys) + { + printf("tableau plein\n"); + fclose(flot); + return -1; + } + tabPoint[num] = point; + tabNbEntree[num] = nbEntree; + i = i + 1; + fscanf(flot,"%d %d %d",&num, &point, &nbEntree); } fclose(flot); return i; } -int recherche(int tabTri[], int val, int nb, int *trouve) { + +int recherche(int tabTri[], int val, int nb, int *trouve){ int i; *trouve = 0; for(i = 0 ; i < nb ; i++) { @@ -54,21 +90,48 @@ int ajouter(int tab[], int nb, int val, int tphys) { int pos, trouve; if (nb == tphys) { printf("Impossible d'insérer un nouvel élément, le tableau est plein !\n"); - return nb; + return -1; } pos = recherche(tab, val, nb, &trouve); if (trouve == 1) { printf("Valeur déjà présente dans le tableau !\n"); - return nb; + return -1; } decalageDroite(tab, nb, pos); tab[pos] = val; + return pos; +} + +int ajouterAdherent(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb, int tmax) { + int val, trouve, points = 10, valJour, valMois, valAnnee, perdue = 1, pos, coderetour; + printf("Nouveau numéro de carte : "); + scanf("%d",&val); + pos = recherche(tabAdhe, val, nb, &trouve); + coderetour = ajouter(tabAdhe, nb, val, tmax); + if (coderetour == -1) { + printf("Erreur ajout du nouvel élement !\n"); + return nb; + } + printf("\nJour : "); + scanf("%d",&valJour); + printf("\nMois : "); + scanf("%d",&valMois); + printf("\nAnnée : ",valAnnee); + scanf("%d",&valAnnee); + tabPoints[pos] = points; + jour[pos] = valJour; + mois[pos] = valMois; + annee[pos] = valAnnee; + carte[pos] = perdue; nb += 1; return nb; + + + } -int suppression(int tab[], int nb, int val) { +int suppression(int tab[], int tabPoints[], int nb, int val) { int pos, trouve; if (nb == 0) { printf("Aucun élément à supprimer dans le tableau !\n"); @@ -76,42 +139,67 @@ int suppression(int tab[], int nb, int val) { } pos = recherche(tab, val, nb, &trouve); decalageGauche(tab, nb, pos); + decalageGauche(tabPoints, nb, pos); nb -= 1; return nb; } -void affichageInfo(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille) + +void affichageTous(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[],int taille) { - int i, idnum, trouve; - printf("Votre Numéro de Carte d'Adhérent :"); - scanf("%d", &idnum); - printf("Num Carte \t Points \t Date \n"); - i = recherche(tabNumCarte, idnum, taille, &trouve); - if (trouve == 0) printf("numéro de carte %d n'est pas attribué.\n", idnum); + int i; + printf("Numéro\tPoints\tDate d'activation\t\n"); + for (i = 0 ; i < taille ; i++) { + if (carte[i] == 1) printf("%d\t%d\t%d/%d/%d\t\t Carte Active\n",tabAdhe[i],tabPoints[i],jour[i],mois[i],annee[i]); + else if (carte[i] == 0) printf("%d\t%d\t%d/%d/%d\t\t Carte Désactivée\n",tabAdhe[i],tabPoints[i],jour[i],mois[i],annee[i]); + } +} + + +void affichageCarte(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb) { + int carteVal, pos, trouve; + printf("Numéro de la carte ?\n"); + scanf("%d",&carteVal); + pos = recherche(tabAdhe, carteVal, nb, &trouve); + if (trouve == 0) printf("Valeur non trouvée !\n"); else { - printf("Num Carte \t Points \t Etat Carte \t Date \n"); - if (carte[i] == 0) - printf("%d \t %d \t perdu \t %d/%d/%d \n", tabNumCarte[i],tabPoint[i], jour[i], mois[i], annee[i]); - if (carte[i] == 1) - printf("%d \t %d \t actif \t %d/%d/%d \n", tabNumCarte[i],tabPoint[i], jour[i], mois[i], annee[i]); + printf("Numéro\tPoints\tDate d'activation\t\n"); + if (carte[pos] == 1) printf("%d\t%d\t%d/%d/%d\t\t Carte Active\n",tabAdhe[pos],tabPoints[pos],jour[pos],mois[pos],annee[pos]); + else if (carte[pos] == 0) printf("%d\t%d\t%d/%d/%d\t\t Carte Désactivée\n",tabAdhe[pos],tabPoints[pos],jour[pos],mois[pos],annee[pos]); } } -void affichageTous(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille) +void affichageActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL) { int i; - printf("Num Carte \t Points \t Date \n"); - for (i = 0; i < taille; i++) + printf("N°Activité \t Points \t Nombre Entrées \n"); + for (i = 0; i < tailleL; i++) { - if (carte[i] == 0) - printf("%d \t %d \t perdu \t %d/%d/%d \n", tabNumCarte[i],tabPoint[i], jour[i], mois[i], annee[i]); - if (carte[i] == 1) - printf("%d \t %d \t actif \t %d/%d/%d \n", tabNumCarte[i],tabPoint[i], jour[i], mois[i], annee[i]); + if (tabCoutPoint[i] != 0) + printf("%d \t %d \t %d", i, tabCoutPoint[i], tabNbEntree[i]\n); } } +void affichageToutActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL) +{ + int i, num, trouve = 0; + 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 (i == num) + { + printf("%d \t %d \t %d", i, tabCoutPoint[i], tabNbEntree[i]\n); + trouve = 1; + } + } + if (trouve == 0) + printf("Le numéro d'activité n'éxiste pas"); + +} void affichageTest(int tabAdhe[], int nb) { int i; @@ -121,28 +209,6 @@ void affichageTest(int tabAdhe[], int nb) { } } -int chargementActivite(int tabPoint[],int tabNbEntree[], int tphys) -{ - int num, point, nbEntree, i =0; - FILE*flot; - flot = fopen("activite.txt","r"); - fscanf(flot,"%d %d %d",&num, &point, &nbEntree); - while(!feof(flot)) - { - if(i < tphys) - { - printf("tableau plein\n"); - fclose(flot); - return i; - } - tabPoint[num] = point; - tabNbEntree[num] = nbEntree; - i = i + 1; - fscanf(flot,"%d %d %d",&num, &point, &nbEntree); - } - fclose(flot); - return i; -} void afficheNbEntreAct(int tabNbEntree[], int tabCoutPoint[], int tphys) { @@ -201,18 +267,20 @@ void alimenterCarte (int tabAdherent[], int tabPoint[],int nb) printf("Erreur ! Numéro de carte absente de la base de donnée\n"); } -void ajoutActivite(int tabCoutPoint[],int tabNbEntree[]) +void ajoutActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL) { int num, nbPoint; printf("Numéro de la Nouvelle Activité :"); scanf("%d", &num); if (tabCoutPoint[num] != 0) printf("Numéro d'activité déjà existant.\n"); + if (tailleL < num) + printf("tableau plein"); else { printf("Coût de l'activité :"); scanf("%d", &nbPoint); - prinf("\t Récapitulatif :"); + printf("\t Récapitulatif :"); printf("Numéro d'activité : %d\n", num); printf("Nombre de point : %d\n", nbPoint); tabCoutPoint[num] = nbPoint; @@ -220,14 +288,16 @@ void ajoutActivite(int tabCoutPoint[],int tabNbEntree[]) } -void suppActivite(int tabCoutPoint[], int tabNbEntree[]) +void suppActivite(int tabCoutPoint[], int tabNbEntree[],int tailleL) { int num; char choix; - prinf("Quel Activité voulez vous supprimer : "); + printf("Quel Activité voulez vous supprimer : "); scanf("%d", &num); if (tabCoutPoint[num] == 0) printf("Numéro d'activité pas existant\n"); + if (tailleL < num) + printf("tableau plein\n"); else { printf("Êtes vous sûre de vouloir supprimer l'activité (O|N): "); @@ -249,9 +319,39 @@ void suppActivite(int tabCoutPoint[], int tabNbEntree[]) } +void faireActivite(int tabAdherent[], int tabPoint[],int tabCoutPoint[], int tabNbEntree[], int tailleLAdhe, int tailleLAct) +{ + int num, idAct, i, trouve; + printf("Identifiant Adhérent : "); + scanf("%d", &num); + i = recherche(tabAdherent, num, tailleLAdhe, &trouve) + if (trouve == 0) + printf("Identifiant Adhérent pas existant\n"); + else + { + printf("Numéro d'activité que vous voulez pratiquer : "); + scanf("%d", &idAct); + while (tabCoutPoint[idAct] == 0) + { + printf("Activité inexistante\n"); + printf("Numéro d'activité que vous voulez pratiquer : "); + scanf("%d", &idAct); + if (idAct == -1) + exit(1); + } + if (tabCoutPoint[idAct] > tabPoint[i]) + printf("Vous n'avez pas assez de point"); + else{ + tabPoint[i] = tabPoint[i] - tabCoutPoint[idAct]; + printf("Achat effectué\n"); + printf("Il vous reste %d point sur votre carte\n", tabPoint[i]); + } + } + +} -int SauvegardeAdherent(int tabAdherent[], int tailleL) { +int SauvegardeAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tailleL) { int i; FILE* flot = fopen("adherent.txt","w"); if (flot == NULL) { @@ -259,12 +359,13 @@ int SauvegardeAdherent(int tabAdherent[], int tailleL) { return -1; } for (i = 0 ; i < tailleL ; i++) { - fprintf(flot,"%d\n",tabAdherent[i]); + fprintf(flot,"%d %d %d %d %d %d\n",tabAdherent[i],tabPoints[i],jour[i],mois[i],annee[i],carte[i]); } + fclose(flot); return 0; } -int SauvegardeActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL) { +int SauvegardeActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL) { int i; FILE* flot = fopen("activite.txt","w"); @@ -276,6 +377,7 @@ int SauvegardeActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL) { if (tabCoutPoint[num] != 0) fprintf(flot,"%d %d %d",i, tabCoutPoint[i], tabNbEntree[i]); } + fclose(flot); return 0; } diff --git a/fonction.h b/fonction.h index af377c5..a139545 100644 --- a/fonction.h +++ b/fonction.h @@ -1,30 +1,41 @@ #include +int chargementAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tphys); -int recherche(int tabTri[], int val, int nb, int *trouve); +int chargementActivite(int tabPoint[],int tabNbEntree[], int tphys); +int recherche(int tabTri[], int val, int nb, int *trouve); 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 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); +void affichageTous(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille); -int chargementAdherent(int tabAdherent[], int tphys); +void affichageCarte(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb) -void affichageInfo(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille); +void affichageActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL); -void affichageTous(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille); +void affichageToutActivite(int tabCoutPoint[], int tabNbEntree[], int tailleL); void affichageTest(int tabAdhe[], int nb); +void afficheNbEntreAct(int tabNbEntree[], int tabCoutPoint[], int tphys); + +void alimenterCarte (int tabAdherent[], int tabPoint[],int nb); + +void ajoutActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL); + +void suppActivite(int tabCoutPoint[], int tabNbEntree[],int tailleL); + +void faireActivite(int tabAdherent[], int tabPoint[],int tabCoutPoint[], int tabNbEntree[], int tailleLAdhe, int tailleLAct); + +int SauvegardeAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tailleL); -int SauvegardeAdherent(int tabAdherent[], int tailleL); \ No newline at end of file +int SauvegardeActivite(int tabCoutPoint[],int tabNbEntree[],int tailleL); \ No newline at end of file