#include "fonction.h" int chargementAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tphys) { int adhe, points, valjour, valmois, valannee, perdue, i = 0, pos; FILE* flot; flot = fopen("adherent.txt","r"); 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 -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; } 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 recherche(int tabTri[], int val, int nb, int *trouve){ int i; *trouve = 0; for(i = 0 ; i < nb ; i++) { if (val == tabTri[i]) { *trouve = 1; return i; } if (val < tabTri[i]) return i; } return nb; } void decalageDroite(int tabTri[], int nb, int pos) { int j; for (j = nb ; j > pos ; j--) tabTri[j] = tabTri[j-1]; } void decalageGauche(int tabTri[], int nb, int pos) { int j; for(j = pos ; j < nb-1 ; j++) tabTri[j] = tabTri[j+1]; } 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 -1; } pos = recherche(tab, 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; 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 tabPoints[], int nb, int val) { int pos, trouve; if (nb == 0) { printf("Aucun élément à supprimer dans le tableau !\n"); return nb; } pos = recherche(tab, val, nb, &trouve); decalageGauche(tab, nb, pos); decalageGauche(tabPoints, nb, pos); nb -= 1; return nb; } void affichageTous(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[],int taille) { 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é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]); } } 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 tabPoint[], int tphys) { int num; printf("numero d’activité :"); scanf("%d",&num); if (tabPoint[num] == 0 && tabNbEntree[num] == 0) printf("Activité inexistante\n"); else printf("Nombre d’entrée : %d", tabNbEntree[num]); } void alimenterCarte (int tabAdherent[], int tabPoint[],int nb) { int num, trouve, i; char formule; printf("numero carte :"); scanf("%d",&num); i = recherche(tabAdherent, num, nb, &trouve); if (trouve == 1) { printf("Quelle formule :\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); 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); } if (formule == 'A') { tabAdherent[i] = tabAdherent[i] + 5; printf("accréditation de 5 points\n"); } if (formule == 'B') { tabAdherent[i] = tabAdherent[i] + 12; printf("accréditation de 12 points\n"); } if (formule == 'B') { tabAdherent[i] = tabAdherent[i] + 20; printf("accréditation de 20 points\n"); } } if (trouve == 0) printf("Erreur ! Numéro de carte absente de la base de donnée\n"); } 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) { printf("Erreur d'ouverture du fichier !\n"); return -1; } for (i = 0 ; i < tailleL ; 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; }