From b26a6b20a250368215118cdb4b0a2c7593c7d8cd Mon Sep 17 00:00:00 2001 From: lolaborie Date: Sat, 5 Nov 2022 14:03:01 +0100 Subject: [PATCH] 05/11 Version de Alexis --- adherent.txt | 5 ++ fonction.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++ fonction.h | 27 +++++++ test.c | 14 ++++ 4 files changed, 258 insertions(+) create mode 100644 adherent.txt create mode 100644 fonction.c create mode 100644 fonction.h create mode 100644 test.c diff --git a/adherent.txt b/adherent.txt new file mode 100644 index 0000000..3c11a7e --- /dev/null +++ b/adherent.txt @@ -0,0 +1,5 @@ +2 +89 +14 +77 +56 diff --git a/fonction.c b/fonction.c new file mode 100644 index 0000000..60bcd4c --- /dev/null +++ b/fonction.c @@ -0,0 +1,212 @@ +#include "fonction.h" + +int chargementAdherent(int tabAdherent[], int tphys) +{ + int adhe, i =0; + FILE*flot; + flot = fopen("adherent.txt","r"); + fscanf(flot,"%d",&adhe); + while(!feof(flot)) + { + if(i >= tphys) + { + printf("tableau plein\n"); + fclose(flot); + return i; + } + ajouter(tabAdherent,i,adhe,tphys); + i = i + 1; + fscanf(flot,"%d",&adhe); + } + 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 nb; + } + pos = recherche(tab, val, nb, &trouve); + if (trouve == 1) { + printf("Valeur déjà présente dans le tableau !\n"); + return nb; + } + decalageDroite(tab, nb, pos); + tab[pos] = val; + nb += 1; + return nb; +} + + +int suppression(int tab[], 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); + nb -= 1; + return nb; + +} + + +void affichageInfo(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],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); + 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]); + } +} + +void affichageTous(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille) +{ + int i; + printf("Num Carte \t Points \t Date \n"); + for (i = 0; i < taille; 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]); + } +} + + +void affichageTest(int tabAdhe[], int nb) { + int i; + printf("Numéro de carte\n"); + for (i = 0 ; i < nb ; i++) { + printf("%d\n",tabAdhe[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 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("Qu'elle 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"); +} + + + + + + + + + + diff --git a/fonction.h b/fonction.h new file mode 100644 index 0000000..3274aa4 --- /dev/null +++ b/fonction.h @@ -0,0 +1,27 @@ +#include + + +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 suppression(int tab[], int nb, int val); + + +int chargementAdherent(int tabAdherent[], int tphys); + +void affichageInfo(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille); + +void affichageTous(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille); + +void affichageTest(int tabAdhe[], int nb); \ No newline at end of file diff --git a/test.c b/test.c new file mode 100644 index 0000000..e6a1d25 --- /dev/null +++ b/test.c @@ -0,0 +1,14 @@ +#include "fonction.h" + + + +int main(void) { + int tab[50], tailleL; + tailleL=chargementAdherent(tab,50); + affichageTest(tab,tailleL); + tailleL=ajouter(tab,tailleL,69,50); + affichageTest(tab,tailleL); + tailleL=suppression(tab,tailleL,69); + affichageTest(tab,tailleL); + return 0; +} \ No newline at end of file