|
|
#include "SAE.h"
|
|
|
|
|
|
int Ouverture(int tNoCarte[], int tage[], int tPointsCarte[], int tCarteActive[], int tNbActivitesJour[], int tDate[], int tmax, int *pasAct)
|
|
|
{
|
|
|
int pasMembres, pasAct;
|
|
|
pasMembres = OuvertureMembres(tNoCarte, tage, tPointsCarte, tCarteActive, tmax);
|
|
|
pasAct = OuvertureActivitesJour(tNbActivitesJour, tDate, tmax);
|
|
|
*pasAct = pasAct;
|
|
|
return pasMembres;
|
|
|
}
|
|
|
|
|
|
int OuvertureMembres(int tNoCarte[], int tage[], int tPointsCarte[], int tCarteActive[], int tmax)
|
|
|
{
|
|
|
int i = 0;
|
|
|
int NoCarte, age, pointsCarte, CarteActive;
|
|
|
FILE *flot;
|
|
|
flot = fopen("membres.don", "r");
|
|
|
if(flot == NULL)
|
|
|
{
|
|
|
printf("Pb d'ouverture du fichier membres.don\n");
|
|
|
return -1;
|
|
|
}
|
|
|
fscanf(flot, "%d%d%d%d", &NoCarte, &age, &pointsCarte, &CarteActive);
|
|
|
while(!feof(flot))
|
|
|
{
|
|
|
if (i == tmax)
|
|
|
{
|
|
|
printf("Tableau plein\n");
|
|
|
fclose(flot);
|
|
|
return -1;
|
|
|
}
|
|
|
tNoCarte[i] = NoCarte;
|
|
|
tage[i] = age;
|
|
|
tPointsCarte[i] = pointsCarte;
|
|
|
tCarteActive[i] = CarteActive;
|
|
|
fscanf(flot, "%d%d%d%d", &NoCarte, &age, &pointsCarte, &CarteActive);
|
|
|
i++;
|
|
|
}
|
|
|
fclose(flot);
|
|
|
return i;
|
|
|
}
|
|
|
int OuvertureActivitesJour(int tNbActivitesJour[], int tDate[], int tmax)
|
|
|
{
|
|
|
int i = 0;
|
|
|
int Date, nbActivitesJour;
|
|
|
FILE *jour;
|
|
|
jour = fopen("ActivitesJour.don", "r");
|
|
|
if(jour == NULL)
|
|
|
{
|
|
|
printf("Pb d'ouverture du fichier ActivitesJour.don\n");
|
|
|
return -1;
|
|
|
}
|
|
|
fscanf(jour, "%d%d", &Date, &nbActivitesJour);
|
|
|
while(!feof(jour))
|
|
|
{
|
|
|
if(i == tmax)
|
|
|
{
|
|
|
printf("Tableau plein\n");
|
|
|
fclose(jour);
|
|
|
return -1;
|
|
|
}
|
|
|
tDate[i] = Date;
|
|
|
tNbActivitesJour[i] = nbActivitesJour;
|
|
|
fscanf(jour, "%d%d", &Date, &nbActivitesJour);
|
|
|
i++;
|
|
|
}
|
|
|
fclose(jour);
|
|
|
return i;
|
|
|
}
|
|
|
|
|
|
int choixMenu(void)
|
|
|
{
|
|
|
int choix;
|
|
|
printf("\t Gestion des matières\n");
|
|
|
printf("1.\tAffichage\n");
|
|
|
printf("2.\tAjouter un adhérent\n");
|
|
|
printf("3.\tModifier l'âge d'un adhérent\n");
|
|
|
printf("4.\tSuppression d'un adhérent\n");
|
|
|
printf("5.\tAjout de points sur une carte\n");
|
|
|
printf("6.\tModification de l'état de la carte\n");
|
|
|
printf("7.\tCréditer une activité à une carte\n");
|
|
|
printf("8.\tQuitter\n");
|
|
|
printf("\noption choisie :\n");
|
|
|
scanf("%d", &choix);
|
|
|
return choix;
|
|
|
}
|
|
|
|
|
|
int choixMenuAffichage(void)
|
|
|
{
|
|
|
int choix;
|
|
|
printf("\t Gestion des matières\n");
|
|
|
printf("1.\tAffichage des informations d'un adhérent\n");
|
|
|
printf("2.\tAffichage des informations de tous les adhérents\n");
|
|
|
printf("3.\tAffichage du nombre d’entrées totale dans la journée\n");
|
|
|
printf("4.\tAffichage du nombre d'entrées totale de toutes les journées\n");
|
|
|
printf("5.\tAffichage du nombre total d'adhérents\n");
|
|
|
printf("6.\tquitter\n");
|
|
|
printf("\noption choisie :\n");
|
|
|
scanf("%d", &choix);
|
|
|
return choix;
|
|
|
}
|
|
|
void Affichage1Adherent()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
void AffichageTousAdherents()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
void AffichageNbEntreesJour()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
void AffichageNbEntreesTousJours()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
void gestionMatieres(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;
|
|
|
nbelem = Ouverture(tNoCarte, tage, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, tmax, &pasAct);
|
|
|
if(nbelem < 0)
|
|
|
{
|
|
|
printf("Erreur d'ouverture du fichier ou tableau plein !!!\n");
|
|
|
return ;
|
|
|
}
|
|
|
choix = choixMenu();
|
|
|
while(choix != 8)
|
|
|
{
|
|
|
if(choix == 1)
|
|
|
{
|
|
|
choix = choixMenuAffichage();
|
|
|
while(choix != 6)
|
|
|
{
|
|
|
if(choix == 1)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(choix == 2)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(choix == 3)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(choix == 4)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(choix == 5)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
choix = choixMenuAffichage();
|
|
|
}
|
|
|
}
|
|
|
if(choix == 2)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(choix == 3)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(choix == 4)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(choix == 5)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(choix == 6)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
choix = choixMenu();
|
|
|
}
|
|
|
sauvegarde(tNoCarte, tage, tPointsCarte, tCarteActive, tNbActivitesJour, tDate, nbelem);
|
|
|
exit(1);
|
|
|
}
|
|
|
|
|
|
int Sauvegarde(int tNoCarte[], int tage[], int tPointsCarte[], int tCarteActive[], int tNbActivitesJour[], int tDate[], int nbelem)
|
|
|
{
|
|
|
int i, j;
|
|
|
FILE *flot, *jour;
|
|
|
flot = fopen("membres.don", "a");
|
|
|
jour = fopen("ActivitesJour.don", "a");
|
|
|
if(flot == NULL)
|
|
|
{
|
|
|
printf("Pb d'ouverture du fichier membres.don\n");
|
|
|
return -1;
|
|
|
}
|
|
|
if(jour == NULL)
|
|
|
{
|
|
|
printf("Pb d'ouverture du fichier ActivitesJour.don\n");
|
|
|
return -1;
|
|
|
}
|
|
|
for(i = 0; i < (nbelem-1); i++)
|
|
|
{
|
|
|
fprintf(flot, "\t%d\t%d\t\t%d\t\t%d\n", tNoCarte[i], tage[i], tPointsCarte[i], tCarteActive[i]);
|
|
|
}
|
|
|
for(j = 0; j < (nbelem-1); j++)
|
|
|
{
|
|
|
fprintf(jour, "%d\t\t%d\n", tDate[j], tNbActivitesJour[j]);
|
|
|
}
|
|
|
fclose(jour);
|
|
|
fclose(flot);
|
|
|
}
|
|
|
|
|
|
void ajouterPoints(int tNumCarte[], int tPoints[], int tailleLog)
|
|
|
{
|
|
|
|
|
|
int numCarte, nbPoints, trouve, index;
|
|
|
char choix;
|
|
|
|
|
|
printf("Entrez le numéro d'adhérent : ");
|
|
|
scanf("%d", &numCarte);
|
|
|
index = recherche(tNumCarte, tailleLog, numCarte, &trouve);
|
|
|
while (trouve == 0)
|
|
|
{
|
|
|
printf("Numéro de carte non trouvé. Veuillez réessayer.\nEntrez le numéro d'adhérent : ");
|
|
|
scanf("%d", &numCarte);
|
|
|
index = recherche(tNumCarte, tailleLog, numCarte, &trouve);
|
|
|
}
|
|
|
printf("Entrez le nombre de points à ajouter : ");
|
|
|
scanf("%d", &nbPoints);
|
|
|
printf("Vous voulez bien ajouter %d points à la carte n°%d ? (O/n)", nbPoints, numCarte);
|
|
|
scanf("%c%*c", &choix);
|
|
|
if (choix == 'n' || choix == 'N') {
|
|
|
printf("Annulation");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
modifierPoints(tNumCarte, tPoints, tailleLog, numCarte, nbPoints);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int modifierPoints(int tNumCarte[], int tPoints[], int tailleLog, int numCarte, int nbPoints)
|
|
|
{
|
|
|
int index, trouve;
|
|
|
|
|
|
index = recherche(tNumCarte, tailleLog, numCarte, &trouve);
|
|
|
|
|
|
if (trouve == 0)
|
|
|
{
|
|
|
printf("Numéro de carte non trouvé. Annulation de l'opétation.");
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tPoints[index] += nbPoints;
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int recherche(int tab[], int tailleLog, int valeur, int *trouve)
|
|
|
{
|
|
|
for (int i = 0; i < tailleLog; i++)
|
|
|
{
|
|
|
if (tab[i] == valeur)
|
|
|
{
|
|
|
*trouve = 1;
|
|
|
return i;
|
|
|
}
|
|
|
else if (tab[i] > valeur)
|
|
|
{
|
|
|
*trouve = 0;
|
|
|
return i;
|
|
|
}
|
|
|
}
|
|
|
*trouve = 0;
|
|
|
return tailleLog;
|
|
|
}
|
|
|
|
|
|
void ajouterPoints(int tNumCarte[], int tPoints[], int tailleLog)
|
|
|
{
|
|
|
|
|
|
int numCarte, nbPoints, trouve, index;
|
|
|
char choix;
|
|
|
|
|
|
printf("Entrez le numéro d'adhérent : ");
|
|
|
scanf("%d", &numCarte);
|
|
|
index = recherche(tNumCarte, tailleLog, numCarte, &trouve);
|
|
|
while (trouve == 0)
|
|
|
{
|
|
|
printf("Numéro de carte non trouvé. Veuillez réessayer.\nEntrez le numéro d'adhérent : ");
|
|
|
scanf("%d", &numCarte);
|
|
|
index = recherche(tNumCarte, tailleLog, numCarte, &trouve);
|
|
|
}
|
|
|
printf("Entrez le nombre de points à ajouter : ");
|
|
|
scanf("%d", &nbPoints);
|
|
|
printf("Vous voulez bien ajouter %d points à la carte n°%d ? (O/n)", nbPoints, numCarte);
|
|
|
scanf("%c%*c", &choix);
|
|
|
if (choix == 'n' || choix == 'N')
|
|
|
{
|
|
|
printf("Annulation");
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
modifierPoints(tNumCarte, tPoints, tailleLog, numCarte, nbPoints);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int modifierPoints(int tNumCarte[], int tPoints[], int tailleLog, int numCarte, int nbPoints)
|
|
|
{
|
|
|
int index, trouve;
|
|
|
|
|
|
index = recherche(tNumCarte, tailleLog, numCarte, &trouve);
|
|
|
|
|
|
if (trouve == 0)
|
|
|
{
|
|
|
printf("Numéro de carte non trouvé. Annulation de l'opétation.");
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tPoints[index] += nbPoints;
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void modifierAge(int tNumCarte[], int tAge[], int tailleLog)
|
|
|
{
|
|
|
int numCarte, age, index, trouve;
|
|
|
char choix;
|
|
|
printf("Entrez le numéro d'adhérent : ");
|
|
|
scanf("%d", &numCarte);
|
|
|
index = recherche(tNumCarte, tailleLog, numCarte, &trouve);
|
|
|
while (trouve == 0)
|
|
|
{
|
|
|
printf("Numéro de carte non trouvé. Veuillez réessayer.\nEntrez le numéro d'adhérent : ");
|
|
|
scanf("%d", &numCarte);
|
|
|
index = recherche(tNumCarte, tailleLog, numCarte, &trouve);
|
|
|
}
|
|
|
|
|
|
printf("Entrez le nouvel âge :");
|
|
|
scanf("%d", &age);
|
|
|
while (age <= 0)
|
|
|
{
|
|
|
printf("Âge non valide. Veuillez réessayer.\nEntrez le nouvel âge : ");
|
|
|
scanf("%d", &age);
|
|
|
}
|
|
|
|
|
|
printf("Le nouvel âge du client n°%d est bien %d ? (O/n)", numCarte, age);
|
|
|
scanf("%c%*c", &choix);
|
|
|
if (choix == 'n' || choix == 'N')
|
|
|
{
|
|
|
printf("Annulation");
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tAge[index] = age;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
int Sauvegarde(int tNoCarte[], int tage[], int tPointsCarte[], int tCarteActive[], int tNbActivitesJour[], int tDate[], int nbelem)
|
|
|
{
|
|
|
int i, j;
|
|
|
FILE *flot, *jour;
|
|
|
flot = fopen("membres.don", "a");
|
|
|
jour = fopen("ActivitesJour.don", "a");
|
|
|
if(flot == NULL)
|
|
|
{
|
|
|
printf("Pb d'ouverture du fichier membres.don\n");
|
|
|
return -1;
|
|
|
}
|
|
|
if(jour == NULL)
|
|
|
{
|
|
|
printf("Pb d'ouverture du fichier ActivitesJour.don\n");
|
|
|
return -1;
|
|
|
}
|
|
|
for(i = 0; i < (nbelem-1); i++)
|
|
|
{
|
|
|
fprintf(flot, "\t%d\t%d\t\t%d\t\t%d\n", tNoCarte[i], tage[i], tPointsCarte[i], tCarteActive[i]);
|
|
|
}
|
|
|
for(j = 0; j < (nbelem-1); j++)
|
|
|
{
|
|
|
fprintf(jour, "%d\t\t%d\n", tDate[j], tNbActivitesJour[j]);
|
|
|
}
|
|
|
fclose(jour);
|
|
|
fclose(flot);
|
|
|
}
|
|
|
|
|
|
int ajoutPointsCarte(int tNoCarte[], int tPointsCarte[], int tCarteActive[], int nbelem)
|
|
|
{
|
|
|
int i, NoCarte, pointsCarte, CarteActive;
|
|
|
printf("Entrez le numero de carte de l'adherent: ");
|
|
|
scanf("%d", &NoCarte);
|
|
|
for(i = 0; i < nbelem; i++)
|
|
|
{
|
|
|
if(NoCarte == tNoCarte[i])
|
|
|
{
|
|
|
printf("Entrez le nombre de points a ajouter: ");
|
|
|
scanf("%d", &pointsCarte);
|
|
|
tPointsCarte[i] += pointsCarte;
|
|
|
printf("Le nombre de points de l'adherent est maintenant de %d\n", tPointsCarte[i]);
|
|
|
if(tPointsCarte[i] >= 1000)
|
|
|
{
|
|
|
tCarteActive[i] = 1;
|
|
|
printf("La carte de l'adherent est maintenant active\n");
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
printf("Le numero de carte n'existe pas\n");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
int rechercheEtCreation(int tNoCarte[], int nbelem)
|
|
|
{
|
|
|
int NoCarte, i;
|
|
|
for( i=0; i < nbelem; i++)
|
|
|
{
|
|
|
if((i + 1) != tNoCarte[i])
|
|
|
{
|
|
|
return i;
|
|
|
}
|
|
|
}
|
|
|
return i;
|
|
|
}
|
|
|
|
|
|
int CreationAdherents(int tNoCarte[], int tage[], int tPointsCarte[], int tCarteActive[], int nbelem)
|
|
|
{
|
|
|
int NoCarte, age, pointsCarte, CarteActive, pas;
|
|
|
char reponse;
|
|
|
printf("Donnez l'âge du client :\n");
|
|
|
scanf("%d", &age);
|
|
|
pas = rechercheEtCreation(tNoCarte, nbelem);
|
|
|
for(j=nbelem; j> pas; j--)
|
|
|
{
|
|
|
tNoCarte[j] = tNoCarte[j-1];
|
|
|
tage[j] = tage[j-1];
|
|
|
tPointsCarte[j] = tPointsCarte[j-1];
|
|
|
tCarteActive[j] = tCarteActive[j-1];
|
|
|
}
|
|
|
tNoCarte[pas] =
|
|
|
tMatieres[i]= matieres;
|
|
|
tCoeff[i] = coeff;
|
|
|
nbMatieres = nbMatieres + 1;
|
|
|
return nbMatieres;
|
|
|
tNoCarte[pas] = tNoCarte[pas] + 1;
|
|
|
tage[pas] = age;
|
|
|
tPointsCarte[pas] = 0;
|
|
|
tCarteActive[pas] = 0;
|
|
|
printf("Le numero de carte de l'adherent qui a %d ans est %d.\nLa carte n'est pas active car il n'y a pas de points dessus.\nVoulez-vous en ajouter ? (O / N)", tage[pas], tNoCarte[pas]);
|
|
|
scanf("%*c%c", &reponse);
|
|
|
if(reponse == 'O' || reponse == 'o')
|
|
|
{
|
|
|
printf("Entrez le nombre de points a ajouter: ");
|
|
|
scanf("%d", &pointsCarte);
|
|
|
if(pointsCarte > 0)
|
|
|
tPointsCarte[pas] = tPointsCarte[pas] + pointsCarte;
|
|
|
printf("Le nombre de points de l'adherent est maintenant de %d\nVotre carte est désormais", tPointsCarte[pas]);
|
|
|
}
|
|
|
nbelem = nbelem + 1;
|
|
|
}
|
|
|
|
|
|
void pointsBonus()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
int CreationAdherents(int tAdherents[], nbClients)
|
|
|
{
|
|
|
int NoCarte, nom, prenom, age, pointsCarte, CarteActive, nbActivitéesJour;
|
|
|
printf("Donnez le nom, le prénom, l'âge du client :\n");
|
|
|
scanf("%d%d%d", &nom, &prenom, &age);
|
|
|
pas = rechercheEtCreation(tAdherents, nbClients);
|
|
|
}
|
|
|
|
|
|
int FrequenceCentre()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
*/
|