You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
saeAlgo/GestionAdherents.c

153 lines
4.7 KiB

#include "Fonctions.h"
int RechercheAdherent(int tNoCarte[], int nbElem, int noCarte, int *trouve)
{
int i;
for (i = 0; i < nbElem; i++)
{
if (tNoCarte[i] == noCarte)
{
*trouve = 1;
return i;
}
if (tNoCarte[i] > noCarte)
{
*trouve = 0;
return i + 1;
}
}
}
int AjoutAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int tMax, int nbElem)
{
int noCarte, age, pointsCarte, pas, trouve, j;
char reponse;
printf("Vous voulez créer un nouvel adhérent.\n");
printf("Donnez l'âge de l'adhérent : ");
scanf("%d", &age);
pas = RechercheAdherent(tNoCarte, nbElem, noCarte, &trouve);
printf("%d\n", pas);
for (j = nbElem; j > pas; j--)
{
if (j == tMax)
{
printf("Tableau plein, impossible d'ajouter un adhérent.\n");
return -1;
}
tNoCarte[j] = tNoCarte[j - 1];
tAge[j] = tAge[j - 1];
tPointsCarte[j] = tPointsCarte[j - 1];
tCarteActive[j] = tCarteActive[j - 1];
}
tNoCarte[pas] = pas + 1;
printf("%d\n", tNoCarte[pas]);
tAge[pas] = age;
tPointsCarte[pas] = 0;
tCarteActive[pas] = 0;
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.\nVoulez-vous en ajouter ? (o/n)\n", tNoCarte[pas], tAge[pas]);
scanf("%*c%c", &reponse);
if (reponse == 'O' || reponse == 'o')
{
AjoutPoints(tNoCarte, tPointsCarte, tCarteActive, nbElem);
}
else
{
printf("La carte n'est pas active.\n");
return nbElem;
}
return nbElem;
}
void ModificationAge(int tNoCarte[], int tAge[], int nbElem)
{
int pas, noCarte, age, trouve;
printf("Entrez le numéro de la carte de l'adhérent recherché : ");
scanf("%d", &noCarte);
pas = RechercheAdherent(tNoCarte, nbElem, noCarte, &trouve);
if (trouve == 1)
{
printf("Entrez le nouvel âge de l'adhérent : ");
scanf("%d", &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);
}
else
{
printf("Ce numéro d'adhérent n'existe pas. Veuillez réessayer.\n");
return;
}
}
int SupprimerAdherent(int tNoCarte[], int tAge[], int tPointsCarte[], int tCarteActive[], int nbElem)
{
int pas, i, noCarte, trouve;
printf("Entrez le numéro de la carte de l'adhérent recherché : ");
scanf("%d", &noCarte);
pas = RechercheAdherent(tNoCarte, nbElem, noCarte, &trouve);
if (trouve == 1)
{
for (i = pas; i < nbElem; i++)
{
tNoCarte[i] = tNoCarte[i + 1];
tAge[i] = tAge[i + 1];
tPointsCarte[i] = tPointsCarte[i + 1];
tCarteActive[i] = tCarteActive[i + 1];
}
nbElem = nbElem - 1;
printf("Vous avez bien supprimé l'adhérent numéro %d.\n", noCarte);
return nbElem;
}
else
{
printf("Ce numéro d'adhérent n'existe pas. Veuillez réessayer.\n");
return -1;
}
}
void ModificationActivationCarte(int tNoCarte[], int tCarteActive[], int nbElem)
{
int noCarte, trouve, pas, choix, choixRaison;
printf("Entrez le numéro de la carte de l'adhérent recherché : ");
scanf("%d", &noCarte);
pas = RechercheAdherent(tNoCarte, nbElem, noCarte, &trouve);
if (trouve == 1)
{
printf("\nQue voulez-vous faire ?\n1.\tActiver la carte\n2.\tDésactiver la carte\n");
printf("Entrez votre choix : ");
scanf("%d", &choix);
if (choix == 1)
{
printf("\nPourquoi voulez-vous activer la carte ?\n1.\tCarte retrouvée\n2.\tNouvelle carte\n3.\tLevée de sanction\n");
printf("Option choisie : ");
scanf("%d", &choixRaison);
if (tCarteActive[pas] == 1)
{
printf("La carte est déjà activée.\n");
return;
}
tCarteActive[pas] = 1;
printf("La carte numéro %d est désormais activée.\n", noCarte);
}
else if (choix == 2)
{
printf("\nPourquoi voulez-vous désactiver la carte ?\n1.\tPerte\n2.\tVol\n3.\tSanction\n");
printf("Option choisie : ");
scanf("%d", &choixRaison);
if (tCarteActive[pas] == 0)
{
printf("La carte est déjà désactivée.\n");
return;
}
tCarteActive[pas] = 0;
printf("La carte numéro %d est désormais désactivée.\n", noCarte);
}
}
else
{
printf("Ce numéro d'adhérent n'existe pas. Veuillez réessayer.\n");
return;
}
}