change version of lo.c in commun and .h

master
L0ol4X 2 years ago
parent 9c211d289d
commit 37f349a24a

@ -9,152 +9,107 @@
int Fillvar(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax)//lis le fichier et met les valeurs dans les tableaux int Fillvar(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax)//lis le fichier et met les valeurs dans les tableaux
{ {
FILE *f; FILE *f;
f = fopen("donneeClient.don", "r"); f = fopen("donneeClient.don", "r");
if (f == NULL) if (f == NULL)
{ {
printf("Problème d'ouverture du fichier Clients..."); printf("Problème d'ouverture du fichier Clients...");
return -1; return -1;
} }
int i = 0; int i = 0;
int numAd, age, state, acti, passeoupas, ptsbought, ptsbonus; int numAd, age, state, acti, passeoupas, ptsbought, ptsbonus;
char categ, fnom[15], fprenom[15]; char categ, fnom[15], fprenom[15];
fscanf(f, "%6d", &numAd); fscanf(f, "%d%*c", &numAd);
fscanf(f, "%s", fnom); fscanf(f, "%s%*c", fnom);
fscanf(f, "%s", fprenom); fscanf(f, "%s%*c", fprenom);
fscanf(f, "%2d", &age); fscanf(f, "%d%*c", &age);
fscanf(f, "%d", &state); fscanf(f, "%d%*c", &state);
fscanf(f, "%d", &acti); fscanf(f, "%d%*c", &acti);
fscanf(f, "%d", &passeoupas); fscanf(f, "%d%*c", &passeoupas);
fscanf(f, "%2d", &ptsbought); fscanf(f, "%d%*c", &ptsbought);
fscanf(f, "%2d%*c", &ptsbonus); fscanf(f, "%d%*c", &ptsbonus);
fscanf(f, "%c", &categ); fscanf(f, "%c%*c", &categ);
while (!feof(f)) while (!feof(f))
{ {
if (i == tmax) if (i == tmax)
{ {
printf("Problème de gestion: trop de clients enregistrés à ce jour"); printf("Problème de gestion: trop de clients enregistrés à ce jour");
return -1; return -1;
} }
tAd[i] = numAd;
strcpy(tnom[i], fnom);
strcpy(tpnom[i], fprenom);
tage[i] = age;
tstate[i] = state;
tacti[i] = acti;
tpasseoupas[i] = passeoupas;
tptsbought[i] = ptsbought;
tptsbonus[i] = ptsbonus;
tcateg[i] = categ;
i++;
fscanf(f, "%6d", &numAd);
fscanf(f, "%s", fnom);
fscanf(f, "%s", fprenom);
fscanf(f, "%2d", &age);
fscanf(f, "%d", &state);
fscanf(f, "%d", &acti);
fscanf(f, "%d", &passeoupas);
fscanf(f, "%2d", &ptsbought);
fscanf(f, "%2d%*c", &ptsbonus);
fscanf(f, "%c", &categ);
}
fclose(f);
return i;
}
void GereAdhérent(void)
{
int tAd[TAILLE], tage[TAILLE], tstate[TAILLE], tacti[TAILLE], tpasseoupas[TAILLE], tptsbought[TAILLE], tptsbonus[TAILLE], place, nbacti, chxacti, numAd, ret, insuf;
char tcateg[TAILLE], nom[TAILLE], pnom[TAILLE], fnom[TAILLE], fpnom[TAILLE], bCard, tnom[TAILLE][15], tpnom[TAILLE][15], action, choix, recharge;
place = Fillvar(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500);
bCard = Card();//demande si carte avec client ou non
tAd[i] = numAd;
strcpy(tnom[i], fnom);
strcpy(tpnom[i], fprenom);
tage[i] = age;
tstate[i] = state;
tacti[i] = acti;
tpasseoupas[i] = passeoupas;
tptsbought[i] = ptsbought;
tptsbonus[i] = ptsbonus;
tcateg[i] = categ;
if (bCard == 'N')// si client n'a pas la carte i++;
{
Name(nom, pnom);
puts("Recherche de la carte !"); fscanf(f, "%d%*c", &numAd);
fscanf(f, "%s%*c", fnom);
fscanf(f, "%s%*c", fprenom);
fscanf(f, "%d%*c", &age);
fscanf(f, "%d%*c", &state);
fscanf(f, "%d%*c", &acti);
fscanf(f, "%d%*c", &passeoupas);
fscanf(f, "%d%*c", &ptsbought);
fscanf(f, "%d%*c", &ptsbonus);
fscanf(f, "%c%*c", &categ);
place = FindData(nom, pnom, tnom, tpnom, tpasseoupas, tptsbought, &action, 500);
if (place == -1)
{
return;
}
} }
if (bCard == 'O') fclose(f);
{ return i;
printf("Numéro carte : \t"); }
scanf("%*c%d", &numAd);
ret = FindN(tAd, numAd, tpasseoupas, 500);
if (ret == -1)
{
GereAdhérent();
}
}
ChoiceMenu(&choix);
if (choix == 'A')
{
printf("La carte dispose de %d points.\n", tptsbought[place]);//infos sur ses points
ChoiceMenu(&choix);
}
if (choix == 'R') void GereAdhérent(void)
{ {
Recharge(tptsbought, place, tcateg); int tAd[TAILLE], tage[TAILLE], tstate[TAILLE], tacti[TAILLE], tpasseoupas[TAILLE], tptsbought[TAILLE], tptsbonus[TAILLE], place, nbacti, choix, chxacti, numAd, ret, insuf, day = 0;
ChoiceMenu(&choix); char tcateg[TAILLE], nom[TAILLE], pnom[TAILLE], fnom[TAILLE], fpnom[TAILLE], bCard, tnom[TAILLE][15], tpnom[TAILLE][15], action, recharge;
} place = Fillvar(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500);
bCard = Card();//demande si carte avec client ou non
if (choix == 'C')
{
printf("Nombre d'activités souhaitées ? (max 3)\n");
scanf("%d", &nbacti);
while (nbacti < 0 || nbacti > 3)
{
printf("Nombre d'activités incorrect (max 3)\n");
scanf("%d", &nbacti);
}
chxacti = ChoiceActi(nbacti, tacti); if (bCard == 'N')// si client n'a pas la carte
CheckPts(tptsbonus, tptsbought, tpasseoupas, tacti, tcateg, place, chxacti, &insuf);
if (insuf == 1)
{ {
printf("Nombre de points insuffisants : Recharge (R) ou Quitter (Q)"); Name(nom, pnom);
scanf("%c%*c", &recharge);
if (recharge == 'R') puts("Recherche de la carte !");
place = FindData(nom, pnom, tnom, tpnom, tpasseoupas, tptsbought, &action, 500);
if (place == -1)
{ {
Recharge(tptsbought, place, tcateg); return;
} }
else }
if (bCard == 'O')
{
printf("Numéro carte : \t");
scanf("%*c%d", &numAd);
ret = FindN(tAd, numAd, tpasseoupas, 500);
if (ret == -1)
{ {
ChoiceMenu(&choix); main();
} }
} }
ChoiceMenu(&choix); choix = ChoiceMenu();
Loop(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, &choix, &insuf, place, nbacti);
}
if (choix == 'Q')
{
//menuglobal()
return;
}
} }
char Card(void)//demande si client a la carte char Card(void)//demande si client a la carte
{ {
char bCard; char bCard;
@ -177,6 +132,7 @@ void Name( char *nom, char *prenom)//demande nom et prénom
int FindData(char *nom, char *pnom, char tnom[][15], char tpnom[][15], int *tpasseoupas, int *tptsbought, char *action, int tmax) int FindData(char *nom, char *pnom, char tnom[][15], char tpnom[][15], int *tpasseoupas, int *tptsbought, char *action, int tmax)
{ {
int i, found = 0, testnom, testpnom; int i, found = 0, testnom, testpnom;
@ -252,12 +208,7 @@ void Recharge(int *tptsbought, int place, char *tcateg)
{ {
int dizpts, topay, nbpts; int dizpts, topay, nbpts;
printf("Combien de dizaines de points souhaitez-vous acheter ?\n"); printf("Combien de dizaines de points souhaitez-vous acheter ?\n");
scanf("%d", &dizpts); scanf("%d%*c", &dizpts);
while (dizpts > 100 || dizpts < 0)
{
printf("Veuillez entrer un nombre correct de dizaines de points\n");
scanf("%d", &dizpts);
}
if (tcateg[place] == 'E') if (tcateg[place] == 'E')
{ {
@ -265,7 +216,7 @@ void Recharge(int *tptsbought, int place, char *tcateg)
topay = dizpts * 2; topay = dizpts * 2;
tptsbought[place] += nbpts; tptsbought[place] += nbpts;
printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay); printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay);
} }
if (tcateg[place] == 'S') if (tcateg[place] == 'S')
@ -274,7 +225,7 @@ void Recharge(int *tptsbought, int place, char *tcateg)
topay = dizpts * 4; topay = dizpts * 4;
tptsbought[place] += nbpts; tptsbought[place] += nbpts;
printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay); printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay);
} }
if (tcateg[place] == 'A') if (tcateg[place] == 'A')
@ -283,7 +234,7 @@ void Recharge(int *tptsbought, int place, char *tcateg)
topay = dizpts * 6; topay = dizpts * 6;
tptsbought[place] += nbpts; tptsbought[place] += nbpts;
printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay); printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay);
} }
} }
@ -294,8 +245,8 @@ int Acti(int i)
{ {
int acti; int acti;
printf("Choix de l'activité %d: badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5) \n", i); printf("Choix de l'activité %d: badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5) \n", i);
scanf("%*c%d%*c", &acti); scanf("%d%*c", &acti);
while (acti != 1 && acti != 2 && acti != 3 && acti != 4 && acti != 5) while (acti <= 0 && acti >= 6)
{ {
printf("Veuillez entrer un nombre d'activité correct (badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5))\n"); printf("Veuillez entrer un nombre d'activité correct (badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5))\n");
scanf("%d%*c", &acti); scanf("%d%*c", &acti);
@ -335,15 +286,17 @@ int ChoiceActi(int nbacti, int *tacti)
void ChoiceMenu(char *choix) int ChoiceMenu(void)
{ {
printf("Recharge carte (R) | Afficher points (A) | Choix activités (C) | Quitter (Q)\n"); int choix;
scanf("%c%*c", choix); printf("Recharge carte (1) | Afficher points (2) | Choix activités (3) | Quitter (4)\n");
while (*choix != 'R' && *choix != 'A' && *choix != 'C' && *choix != 'Q') scanf("%d", &choix);
while (choix > 4 || choix < 1)
{ {
printf("Entrer un caractère correct R | A | C | Q \n"); printf("Entrer un caractère correct 1 | 2 | 3 | 4 \n");
scanf("%c%*c%*c", choix); scanf("%d%*c", &choix);
} }
return choix;
} }
@ -362,7 +315,7 @@ void CheckPts(int *tptsbonus, int *tptsbought, int *tpasseoupas, int *tacti, cha
if (ptsneeded <= tptsbought[place]) if (ptsneeded <= tptsbought[place])
{ {
("Points suffisants, confirmation ? (O/N) \n"); ("Points suffisants, confirmation ? (O/N) \n");
scanf("%c%*c", &confirm); scanf("%*c%c%*c", &confirm);
if (confirm == 'O') if (confirm == 'O')
{ {
tptsbought[place] -= ptsneeded; tptsbought[place] -= ptsneeded;
@ -457,6 +410,54 @@ void Save(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, i
void Loop(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int *choix, int *insuf, int place, int nbacti)
{
int chxacti;
char recharge;
while (*choix != 4)
{
if (*choix == 2)
{
printf("La carte dispose de %d points.\n", tptsbought[place]);//infos sur ses points
}
if (*choix == 1)
{
Recharge(tptsbought, place, tcateg);
}
if (*choix == 3)
{
printf("Nombre d'activités souhaitées ? (max 3)\n");
scanf("%*c%d", &nbacti);
while (nbacti < 0 || nbacti > 3)
{
printf("Nombre d'activités incorrect (max 3)\n");
scanf("%*c%d", &nbacti);
}
chxacti = ChoiceActi(nbacti, tacti);
CheckPts(tptsbonus, tptsbought, tpasseoupas, tacti, tcateg, place, chxacti, insuf);
if (*insuf == 1)
{
printf("Nombre de points insuffisants : Recharge (R) ou Quitter (Q)");
scanf("%*c%c%*c", &recharge);
if (recharge == 'R')
{
Recharge(tptsbought, place, tcateg);
}
}
}
*choix = ChoiceMenu();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -505,8 +506,8 @@ void fAffichage1Client(int *tAd, char tnom[][15], char tpnom[][15], int *tage,in
if(noClient==-1) if(noClient==-1)
{ {
return; return;
} }
} }
} }
printf(" N° Client\t Nom\t Prénom\t Age\t Tarif\t Nombre de points \t \n"); printf(" N° Client\t Nom\t Prénom\t Age\t Tarif\t Nombre de points \t \n");
@ -553,7 +554,7 @@ void cptAct(int *bad, int *muscu, int *foot, int *squa, int * zumba, int chx)
} }
//Calcul et affiche le nombre d'entrée //Calcul et affiche le nombre d'entrée
void affNbParAct(int *tacti, int tlog) void affNbParAct(int *tacti, int tlog)
{ {
int chx1, chx2, chx3, bad, muscu, foot, squa, zumba, totbad, totmuscu, totfoot, totsqua, totzumba, i; int chx1, chx2, chx3, bad, muscu, foot, squa, zumba, totbad, totmuscu, totfoot, totsqua, totzumba, i;
@ -678,12 +679,12 @@ void Index(void)
int tAd[TAILLE], tage[TAILLE], tstate[TAILLE], tacti[TAILLE], tpasseoupas[TAILLE], tptsbought[TAILLE], tptsbonus[TAILLE], place, nbacti, chxacti, numAd, ret, n, VSUIVANTE, next, choix=0; int tAd[TAILLE], tage[TAILLE], tstate[TAILLE], tacti[TAILLE], tpasseoupas[TAILLE], tptsbought[TAILLE], tptsbonus[TAILLE], place, nbacti, chxacti, numAd, ret, n, VSUIVANTE, next, choix=0;
char tcateg[TAILLE], nom[TAILLE], pnom[TAILLE], fnom[TAILLE], fpnom[TAILLE], bCard, member, tnom[TAILLE][15], tpnom[TAILLE][15], action, retourmenu; char tcateg[TAILLE], nom[TAILLE], pnom[TAILLE], fnom[TAILLE], fpnom[TAILLE], bCard, member, tnom[TAILLE][15], tpnom[TAILLE][15], action, retourmenu;
n=Fillvar(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500); n=Fillvar(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500);
FILE *fx; FILE *fx;
fx=fopen("x.don","r"); fx=fopen("x.don","r");
if (fx==NULL) if (fx==NULL)
{printf("erreur"); {printf("erreur");
return;} return;}
@ -693,7 +694,7 @@ void Index(void)
while(!feof(fx)) while(!feof(fx))
{ {
fscanf(fx, "%d", &next); fscanf(fx, "%d", &next);
if ( next> VSUIVANTE) if ( next> VSUIVANTE)
{ {
VSUIVANTE=next; VSUIVANTE=next;
@ -713,7 +714,7 @@ void Index(void)
//printf("\nTapez h pour une aide\n"); //printf("\nTapez h pour une aide\n");
scanf("%d%*c", &choix); scanf("%d%*c", &choix);
while (1 > choix || choix> 6) while (1 > choix || choix> 6)
{ {
printf("\nEntrez soit 1, soit 2.\t"); printf("\nEntrez soit 1, soit 2.\t");
@ -734,17 +735,17 @@ void Index(void)
printf("\nTapez la lettre O pour revenir au menu.\t"); printf("\nTapez la lettre O pour revenir au menu.\t");
scanf("%*c%c%*c", &retourmenu); scanf("%*c%c%*c", &retourmenu);
} }
if (retourmenu == 'O') if (retourmenu == 'O')
Index(); Index();
} }
*/ */
if (choix == 1) if (choix == 1)
{ {
creationCompte( &VSUIVANTE); creationCompte( &VSUIVANTE);
} }
if (choix == 2) if (choix == 2)
{ {
menuAff(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500, n); menuAff(tAd, tnom, tpnom, tage, tstate, tacti, tpasseoupas, tptsbought, tptsbonus, tcateg, 500, n);
@ -764,26 +765,26 @@ void creationCompte(int *VSUIVANTE)
FILE *fe, *fx, *fn; FILE *fe, *fx, *fn;
fe= fopen("donneClient.don", "a"); fe= fopen("donneClient.don", "a");
fx= fopen("x.don","a"); fx= fopen("x.don","a");
if (fe==NULL) if (fe==NULL)
{ {
printf(" Erreur ouverture fichier"); printf(" Erreur ouverture fichier");
} }
printf("\nEntrez votre nom\n"); printf("\nEntrez votre nom\n");
scanf("%s%*c", nom); scanf("%s%*c", nom);
printf("\nEntrez votre prenom\n"); printf("\nEntrez votre prenom\n");
scanf("%s%*c", prenom); scanf("%s%*c", prenom);
printf("\nEntrez votre age\n"); printf("\nEntrez votre age\n");
scanf("%d%*c", &age); scanf("%d%*c", &age);
printf("Avez-vous un tarif spécial: Etudiant(E), Senior(S), aucun(A)?\n"); printf("Avez-vous un tarif spécial: Etudiant(E), Senior(S), aucun(A)?\n");
scanf("%c%*c", &categorie); scanf("%c%*c", &categorie);
fprintf(fe,"\n%d\t",*VSUIVANTE); fprintf(fe,"\n%d\t",*VSUIVANTE);
fprintf(fe,"%s\t",nom); fprintf(fe,"%s\t",nom);
fprintf(fe,"%s\t",prenom); fprintf(fe,"%s\t",prenom);
@ -798,17 +799,17 @@ void creationCompte(int *VSUIVANTE)
*VSUIVANTE=*VSUIVANTE+1; *VSUIVANTE=*VSUIVANTE+1;
fprintf(fx,"\n%d",*VSUIVANTE); fprintf(fx,"\n%d",*VSUIVANTE);
printf("Ajoutez un contact?(O/N)\n"); printf("Ajoutez un contact?(O/N)\n");
scanf("%c%*c", &retour); scanf("%c%*c", &retour);
if (retour == 'O') if (retour == 'O')
creationCompte(VSUIVANTE); creationCompte(VSUIVANTE);
else else
return; return;
} }
void menuAff (int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int n) void menuAff (int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int n)
{ {
int choix, noClient; int choix, noClient;
@ -825,4 +826,3 @@ void menuAff (int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstat
fAffichage1Client(tAd, tnom, tpnom, tage, tstate, n, noClient, tptsbought, tcateg); fAffichage1Client(tAd, tnom, tpnom, tage, tstate, n, noClient, tptsbought, tcateg);
} }
} }

@ -7,7 +7,7 @@ int affNbmEntree( int *tpasseoupas, int tlog);
void cptAct(int *bad, int *muscu, int *foot, int *squa, int * zumba, int chx); void cptAct(int *bad, int *muscu, int *foot, int *squa, int * zumba, int chx);
void affNbParAct(int *tacti, int tlog); void affNbParAct(int *tacti, int tlog);
void suppr1Client(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int *n, int tmax); void suppr1Client(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int *n, int tmax);
char Card(void);//check si le client a la carte char Card(void);//check si le client a la carte
void Index(void); void Index(void);
void creationCompte(int *VSUIVANTE); void creationCompte(int *VSUIVANTE);
void fRecherche(int *tAd, int n, int noClient, int *coderet, int *rang); void fRecherche(int *tAd, int n, int noClient, int *coderet, int *rang);
@ -22,4 +22,5 @@ int FindN(int *tAd, int numAd, int *tpasseoupas, int tmax);
void CheckPts(int *tptsbonus, int *tptsbought, int *tpasseoupas, int *tacti, char *tcateg, int place, int acti, int *insuf); void CheckPts(int *tptsbonus, int *tptsbought, int *tpasseoupas, int *tacti, char *tcateg, int place, int acti, int *insuf);
void GereAdhérent(void); void GereAdhérent(void);
void Save(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int place); void Save(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int place);
void Loop(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int *choix, int *insuf, int place, int nbacti);
void menuAff (int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int n); void menuAff (int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax, int n);

Loading…
Cancel
Save