@ -1,25 +1,25 @@
# include "SAE.h"
int Ouverture ( int tNoCarte [ ] , int tage [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int tNbActivitesJour [ ] , int tDate [ ] , int tmax )
int Ouverture ( int tNoCarte [ ] , int tage [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int tNbActivitesJour [ ] , int tDate [ ] , int tmax , int * pasAct )
{
int i = 0 , j = 0 ;
int pasMembres ;
pasMembres = OuvertureMembres ( tNoCarte , tage , tPointsCarte , tCarteActive , tmax ) ;
* pasAct = OuvertureActivitesJour ( tNbActivitesJour , tDate , tmax ) ;
return pasMembres ;
}
int OuvertureMembres ( int tNoCarte [ ] , int tage [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int tmax )
{
int i = 0 ;
int NoCarte , age , pointsCarte , CarteActive ;
int Date , nbActivitesJour ;
FILE * flot , * jour ;
FILE * flot ;
flot = fopen ( " membres.don " , " r " ) ;
jour = fopen ( " ActivitesJour.don " , " r " ) ;
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 ;
}
fscanf ( flot , " %d%d%d%d%d%d%d " , & NoCarte , & age , & pointsCarte , & CarteActive ) ;
fscanf ( jour , " %d%d " , & Date , & nbActivitesJour ) ;
fscanf ( flot , " %d%d%d%d " , & NoCarte , & age , & pointsCarte , & CarteActive ) ;
while ( ! feof ( flot ) )
{
if ( i = = tmax )
@ -35,97 +35,452 @@ int Ouverture(int tNoCarte[], int tage[], int tPointsCarte[], int tCarteActive[]
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 ( j = = tmax )
if ( i = = tmax )
{
printf ( " Tableau plein \n " ) ;
fclose ( jour ) ;
return - 1 ;
}
tDate [ j ] = Date ;
tNbActivitesJour [ j ] = nbActivitesJour ;
tDate [ i ] = Date ;
tNbActivitesJour [ i ] = nbActivitesJour ;
fscanf ( jour , " %d%d " , & Date , & nbActivitesJour ) ;
j + + ;
i + + ;
}
fclose ( jour ) ;
fclose ( flot ) ;
return i ;
}
int recherche ( int tab [ ] , int tailleLog , int valeur , int * trouve )
int choixMenu ( void )
{
int choix ;
printf ( " \t Gestion des matières \n " ) ;
printf ( " 1. \t Affichage \n " ) ;
printf ( " 2. \t Ajouter un adhérent \n " ) ;
printf ( " 3. \t Modifier l'âge d'un adhérent \n " ) ;
printf ( " 4. \t Suppression d'un adhérent \n " ) ;
printf ( " 5. \t Ajout de points sur une carte \n " ) ;
printf ( " 6. \t Modification de l'état de la carte \n " ) ;
printf ( " 7. \t Créditer une activité à une carte \n " ) ;
printf ( " 8. \t Quitter \n " ) ;
printf ( " \n option choisie : \n " ) ;
scanf ( " %d " , & choix ) ;
return choix ;
}
int choixMenuAffichage ( void )
{
for ( int i = 0 ; i < tailleLog ; i + + )
int choix ;
printf ( " \t Gestion des matières \n " ) ;
printf ( " 1. \t Affichage des informations d'un adhérent \n " ) ;
printf ( " 2. \t Affichage des informations de tous les adhérents \n " ) ;
printf ( " 3. \t Affichage du nombre d’ entrées totale de toutes les journée \n " ) ;
printf ( " 4. \t Affichage du nombre d'entrées totale depuis le début \n " ) ;
printf ( " 5. \t Affichage du nombre total d'adhérents \n " ) ;
printf ( " 6. \t quitter \n " ) ;
printf ( " \n option choisie : \n " ) ;
scanf ( " %d " , & choix ) ;
return choix ;
}
int rechercheAdherent ( int tNoCarte [ ] , int nbelem , int NoCarte , int * trouve )
{
int i ;
for ( i = 0 ; i < nbelem ; i + + )
{
if ( tab [ i ] = = valeur )
if ( tNoCarte [ i ] = = NoCarte )
{
* trouve = 1 ;
return i ;
}
else if ( tab [ i ] > valeur )
if( tNoCarte [ i ] > NoCarte )
{
* trouve = 0 ;
return i ;
}
}
* trouve = 0 ;
return tailleLog ;
}
void ajouterPoints ( int tNumCarte [ ] , int tPoints [ ] , int tailleLog )
int rechercheAdherent ( int tNoCarte [ ] , int tmax , int nbelem )
{
int i = 0 , NoCarte ;
printf ( " Entrez le numéro de la carte de l'adhérent recherché : " ) ;
scanf ( " %d " , & NoCarte ) ;
while ( i < tmax & & tNoCarte [ i ] ! = NoCarte )
{
i + + ;
}
if ( i = = tmax )
{
printf ( " Ce numéro d'adhérant n'existe pas, veuillez réessayer \n " ) ;
return - 1 ;
}
else
{
return i ;
}
}
int numCarte , nbPoints , trouve , index ;
char choix ;
void Affichage1Adherent ( int tNoCarte [ ] , int tage [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int nbelem )
{
int pas , NoCarte , CarteActive , trouve ;
printf ( " Entrez le numéro de la carte de l'adhérent recherché : " ) ;
scanf ( " %d " , & NoCarte ) ;
pas = rechercheAdherant ( tNoCarte , nbelem , NoCarte , & trouve ) ;
if ( trouve = = 1 )
{
printf ( " N°_de_carte \t Age Points Carte_active \n " ) ;
printf ( " \t %d \t %d \t %d \t %d \n " , tNoCarte [ pas ] , tage [ pas ] , tPointsCarte [ pas ] , tCarteActive [ pas ] ) ;
}
else
{
printf ( " Ce numéro d'adhérant n'existe pas, veuillez réessayer \n " ) ;
return ;
}
}
printf ( " Entrez le numéro d'adhérent : " ) ;
scanf ( " %d " , & numCarte ) ;
index = recherche ( tNumCarte , tailleLog , numCarte , & trouve ) ;
while ( trouve = = 0 )
void AffichageTousAdherents ( int tNoCarte [ ] , int tage [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int nbelem )
{
int i ;
printf ( " N°_de_carte \t Age Points Carte_active \n " ) ;
for ( i = 0 ; i < nbelem ; i + + )
{
printf ( " Numéro de carte non trouvé. Veuillez réessayer. \n Entrez le numéro d'adhérent : " ) ;
scanf ( " %d " , & numCarte ) ;
index = recherche ( tNumCarte , tailleLog , numCarte , & trouve ) ;
printf ( " \t %d \t %d \t %d \t %d \n " , tNoCarte [ i ] , tage [ i ] , tPointsCarte [ i ] , tCarteActive [ i ] ) ;
}
}
void AffichageNbEntreesTousJour ( int tNbActivitesJour [ ] , int tDate [ ] , int nbelem )
{
int i ;
printf ( " Date \t Nb_Activites \n " ) ;
for ( i = 0 ; i < nbelem ; i + + )
{
printf ( " \t %d \t %d \n " , tDate [ i ] , tNbActivitesJour [ i ] ) ;
}
}
void AffichageNbEntreesTotal ( int tNbActivitesJour [ ] , int nbelem )
{
int i , somme = 0 ;
for ( i = 0 ; i < nbelem ; i + + )
{
somme = somme + tNbActivitesJour [ i ] ;
}
printf ( " Le nombre total d'entrées est de %d depuis le début. \n " , somme ) ;
}
void AffichageNbAdherents ( int nbelem )
{
int i , somme = 0 ;
for ( i = 0 ; i < nbelem ; i + + )
{
somme = somme + 1 ;
}
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 ( " Le nombre total d'adhérents est de %d. \n " , somme ) ;
}
void gestionMenus ( 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 ( " Annulation " ) ;
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 )
{
Affichage1Adherent ( tNoCarte , tage , tPointsCarte , tCarteActive , nbelem ) ;
}
if ( choix = = 2 )
{
AffichageTousAdherents ( tNoCarte , tage , tPointsCarte , tCarteActive , nbelem ) ;
}
if ( choix = = 3 )
{
AffichageNbEntreesTousJour ( tNbActivitesJour , tDate , nbelem ) ;
}
if ( choix = = 4 )
{
AffichageNbEntreesTotal ( tNbActivitesJour , nbelem ) ;
}
if ( choix = = 5 )
{
AffichageNbAdherents ( nbelem ) ;
}
choix = choixMenuAffichage ( ) ;
}
}
if ( choix = = 2 )
{
nbelem = AjoutAdherent ( tNoCarte , tage , tPointsCarte , tCarteActive , tmax , nbelem ) ;
}
if ( choix = = 3 )
{
ModificationAge ( tNoCarte , tage , nbelem ) ;
}
if ( choix = = 4 )
{
nbelem = SupprimmerAdherent ( tNoCarte , tage , tPointsCarte , tCarteActive , nbelem ) ;
}
if ( choix = = 5 )
{
AjoutPoints ( tNoCarte , tPointsCarte , nbelem ) ;
}
if ( choix = = 6 )
{
}
if ( choix = = 7 )
{
}
choix = choixMenu ( ) ;
}
Sauvegarde ( tNoCarte , tage , tPointsCarte , tCarteActive , tNbActivitesJour , tDate , nbelem ) ;
exit ( 1 ) ;
}
void ModificationAge ( int tNoCarte [ ] , int tage [ ] , int nbelem )
{
int pas , NoCarte , age ;
printf ( " Entrez le numéro de la carte de l'adhérent recherché : " ) ;
scanf ( " %d " , & NoCarte ) ;
pas = rechercheAdherant ( tNoCarte , nbelem , NoCarte , & trouve ) ;
if ( trouve = = 1 )
{
printf ( " Entrez l'age de l'adhérent : " ) ;
scanf ( " %d " , & age ) ;
tage [ pas ] = age ;
}
else
{
modifierPoints ( tNumCarte , tPoints , tailleLog , numCarte , nbPoints ) ;
printf( " Ce numéro d'adhérant n'existe pas, veuillez réessayer \n " ) ;
return ;
}
}
int modifierPoints ( int tNumCarte [ ] , int tPoints [ ] , int tailleLog , int numCarte , int nbPoints )
int SupprimmerAdherent( int tNoCarte [ ] , int tage [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int nbelem )
{
int index , trouve ;
int pas , i , NoCarte , trouve ;
printf ( " Entrez le numéro de la carte de l'adhérent recherché : " ) ;
scanf ( " %d " , & NoCarte ) ;
pas = rechercheAdherant ( 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 ;
return nbelem ;
}
else
{
printf ( " Ce numéro d'adhérant n'existe pas, veuillez réessayer \n " ) ;
return - 1 ;
}
}
index = recherche ( tNumCarte , tailleLog , numCarte , & trouve ) ;
int AjoutAdherent ( int tNoCarte [ ] , int tage [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int tmax , int nbelem )
{
int NoCarte , age , pointsCarte , CarteActive , pas ;
char reponse ;
printf ( " Donnez l'âge de l'adhérent : \n " ) ;
scanf ( " %d " , & age ) ;
pas = rechercheAdherant ( tNoCarte , nbelem ) ;
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 ;
tage [ pas ] = age ;
tPointsCarte [ pas ] = 0 ;
tCarteActive [ pas ] = 0 ;
nbelem + + ;
printf ( " Le numero de carte de l'adherent qui a %d ans est %d. \n La carte n'est pas active car il n'y a pas de points dessus. \n Voulez-vous en ajouter ? (O / N) " , tage [ pas ] , tNoCarte [ pas ] ) ;
scanf ( " %*c%c " , & reponse ) ;
if ( reponse = = ' O ' | | reponse = = ' o ' )
{
AjoutPoints ( tNoCarte , tPointsCarte , tCarteActive , nbelem , pas ) ;
}
else
{
printf ( " La carte n'est pas active. \n " ) ;
return nbelem ;
}
return nbelem ;
}
void AjoutPoints ( int tNoCarte [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int nbelem , int pas )
{
int pointsCarte , NoCarte , trouve ;
printf ( " Entrez le numéro de la carte de l'adhérent recherché : " ) ;
scanf ( " %d " , & NoCarte ) ;
pas = rechercheAdherant ( tNoCarte , nbelem , NoCarte , & trouve ) ;
if ( trouve = = 1 )
{
printf ( " Entrez le nombre de points a ajouter: " ) ;
scanf ( " %d " , & pointsCarte ) ;
if ( pointsCarte > 0 & & pointsCarte < 20 )
{
tPointsCarte [ pas ] = pointsCarte ;
tCarteActive [ pas ] = 1 ;
printf ( " La carte est active. \n " ) ;
}
if ( pointsCarte > 20 & & pointsCarte < 50 )
{
tPointsCarte [ pas ] = pointsCarte + pointsCarte * ( 1 + ( 5 / 100.0 ) ) ;
tCarteActive [ pas ] = 1 ;
printf ( " Merci pour votre achat. Nous vous offrons 5%% supplémentaires. De plus, votre carte est active. \n " ) ;
}
if ( pointsCarte > 50 & & pointsCarte < 100 )
{
tPointsCarte [ pas ] = pointsCarte + pointsCarte * ( 1 + ( 10 / 100.0 ) ) ;
tCarteActive [ pas ] = 1 ;
printf ( " Merci pour votre achat. Nous vous offrons 10%% supplémentaires. De plus, votre carte est active. \n " ) ;
}
if ( pointsCarte > 100 )
{
tPointsCarte [ pas ] = pointsCarte + pointsCarte * ( 1 + ( 15 / 100.0 ) ) ;
tCarteActive [ pas ] = 1 ;
printf ( " Merci pour votre achat. Nous vous offrons 15%% supplémentaires. De plus, votre carte est active. \n " ) ;
}
else
{
printf ( " Le nombre de points est incorrect. \n " ) ;
printf ( " Veuillez ressaisir le nombre de points a ajouter: " ) ;
scanf ( " %d " , & pointsCarte ) ;
}
}
else
{
printf ( " Ce numéro d'adhérant n'existe pas, veuillez réessayer \n " ) ;
return - 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 ) ;
}
if ( trouve = = 0 )
void DebitActivitee ( int tNoCarte [ ] , int tage [ ] , int tPointsCarte [ ] , int tCarteActive [ ] , int tNbActivitesJour [ ] , int tDate [ ] , int nbelem )
{
int NoCarte , trouve , pas , pointsCarte ;
char reponse ;
printf ( " Entrez le numéro de la carte de l'adhérent recherché : " ) ;
scanf ( " %d " , & NoCarte ) ;
pas = rechercheAdherant ( tNoCarte , nbelem , NoCarte , & trouve ) ;
if ( trouve = = 1 )
{
printf ( " Numéro de carte non trouvé. Annulation de l'opétation. " ) ;
return 0 ;
if ( tCarteActive [ pas ] = = 1 )
{
printf ( " Voulez-vous desactiver cette carte ? (O/N) \n " ) ;
scanf ( " %*c%c " , & reponse ) ;
if ( reponse = = ' O ' | | reponse = = ' o ' )
{
tCarteActive [ pas ] = 0 ;
printf ( " La carte est desactivée. \n " ) ;
}
else
{
printf ( " La carte est toujours active. \n " ) ;
}
}
else
{
printf ( " La carte est desactivée. Voulez-vous la réactiver ? (O/N) \n " ) ;
scanf ( " %*c%c " , & reponse ) ;
if ( reponse = = ' O ' | | reponse = = ' o ' )
{
tCarteActive [ pas ] = 1 ;
printf ( " La carte est activée. \n " ) ;
}
else
{
printf ( " La carte est toujours desactivée. \n " ) ;
}
}
}
else
{
tPoints [ index ] + = nbPoints ;
return 1 ;
printf ( " Ce numéro d'adhérant n'existe pas, veuillez réessayer \n " ) ;
return - 1 ;
}
}
void modifierAge ( int tNumCarte [ ] , int tAge [ ] , int tailleLog )
void modifi cationEtat( int tNumCarte [ ] , int tEtat [ ] , int tailleLog )
{
int numCarte , age , index , trouve ;
char choix ;
printf ( " Entrez le numéro d'adhérent : " ) ;
int choix , numCarte , index , trouve ;
printf ( " Que voulez-vous faire ? \n 1. \t Activer une carte \n 2. \t Désactiver une carte " ) ;
scanf ( " %d " , & choix ) ;
while ( choix ! = 1 | | choix ! = 2 )
{
printf ( " Choix invalide. Veuillez réessayer. \n Que voulez-vous faire ? \n 1. \t Activer une carte \n 2. \t Désactiver une carte " ) ;
scanf ( " %d " , & choix ) ;
}
printf ( " Entrez le numéro de la carte dont vous voulez modifier l'état. " ) ;
scanf ( " %d " , & numCarte ) ;
index = recherche ( tNumCarte , tailleLog , numCarte , & trouve ) ;
while ( trouve = = 0 )
@ -135,25 +490,31 @@ void modifierAge(int tNumCarte[], int tAge[], int tailleLog)
index = recherche ( tNumCarte , tailleLog , numCarte , & trouve ) ;
}
printf ( " Entrez le nouvel âge : " ) ;
scanf ( " %d " , & age ) ;
while ( age < = 0 )
{
printf ( " Âge non valide. Veuillez réessayer. \n Entrez 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 ' )
if ( choix = = 1 )
{
printf ( " Annulation " ) ;
return ;
if ( tEtat [ index ] = = 1 )
{
printf ( " La carte n°%d est déjà active " ) ;
return ;
}
else
{
printf ( " La carte n°%d a été activée " ) ;
return ;
}
}
else
else if ( choix = = 2 )
{
tAge [ index ] = age ;
return ;
if ( tEtat [ index ] = = 0 )
{
printf ( " La carte n°%d est déjà désactivée " ) ;
return ;
}
else
{
printf ( " La carte n°%d a été désactivée. " )
return ;
}
}
}
@ -260,16 +621,11 @@ int CreationAdherents(int tNoCarte[], int tage[], int tPointsCarte[], int tCarte
nbelem = nbelem + 1 ;
}
/*
void pointsBonus ( )
{
}
int CreationAdherents ( int tAdherents [ ] , nbClients )
{
int NoCarte , nom , prenom , age , pointsCarte , CarteActive , nbActivit é esJour ;