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.
327 lines
6.7 KiB
327 lines
6.7 KiB
#include "sae.h"
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
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;
|
|
f = fopen("donneeClient.don", "r");
|
|
if (f == NULL)
|
|
{
|
|
printf("Problème d'ouverture du fichier Clients...");
|
|
return -1;
|
|
}
|
|
int i = 0;
|
|
int numAd, age, state, acti, passeoupas, ptsbought, ptsbonus;
|
|
char categ, fnom[15], fprenom[15];
|
|
|
|
fscanf(f, "%d", &numAd);
|
|
fscanf(f, "%*c%s", fnom);
|
|
fscanf(f, "%*c%s", fprenom);
|
|
fscanf(f, "%*c%d", &age);
|
|
fscanf(f, "%*c%d", &state);
|
|
fscanf(f, "%*c%d", &acti);
|
|
fscanf(f, "%*c%d", &passeoupas);
|
|
fscanf(f, "%*c%d", &ptsbought);
|
|
fscanf(f, "%*c%d%*c", &ptsbonus);
|
|
fscanf(f, "%*c%c", &categ);
|
|
|
|
while (!feof(f))
|
|
{
|
|
if (i == tmax)
|
|
{
|
|
printf("Problème de gestion: trop de clients enregistrés à ce jour");
|
|
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, "%d", &numAd);
|
|
fscanf(f, "%*c%s", fnom);
|
|
fscanf(f, "%*c%s", fprenom);
|
|
fscanf(f, "%*c%d", &age);
|
|
fscanf(f, "%*c%d", &state);
|
|
fscanf(f, "%*c%d", &acti);
|
|
fscanf(f, "%*c%d", &passeoupas);
|
|
fscanf(f, "%*c%d", &ptsbought);
|
|
fscanf(f, "%*c%d%*c", &ptsbonus);
|
|
fscanf(f, "%*c%c", &categ);
|
|
|
|
}
|
|
fclose(f);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
char Card(void)//demande si client a la carte
|
|
{
|
|
char bCard;
|
|
printf("Avez-vous votre numéro de carte adhérent avec vous ?(O/N)\n");
|
|
scanf("%c", &bCard);
|
|
return bCard;
|
|
}
|
|
|
|
|
|
|
|
void Name( char *nom, char *prenom)//demande nom et prénom
|
|
{
|
|
printf("Dans ce cas, quel est votre nom ?\n");
|
|
scanf("%s", nom);
|
|
|
|
printf("Et votre prénom ?\n");
|
|
scanf("%s", prenom);
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
i = 0;
|
|
testnom = strcmp(tnom[i], nom);//comparer nom du fichier et nom donné
|
|
testpnom = strcmp(tpnom[i], pnom);//comparer prénom du fichier et prénom donné
|
|
while (found == 0 && i < tmax)
|
|
{
|
|
if (testnom == 0)
|
|
{
|
|
if (testpnom == 0)
|
|
found = 1;
|
|
break;
|
|
}
|
|
i++;
|
|
testnom = strcmp(tnom[i], nom);
|
|
testpnom = strcmp(tpnom[i], pnom);
|
|
}
|
|
|
|
if (found == 0)
|
|
{
|
|
printf("Recherche non aboutie : numéro non enregistré...\n");//si le client n'est au final pas enregistré
|
|
return -1;
|
|
}
|
|
|
|
if (found == 1)//si trouvé
|
|
{
|
|
if (tpasseoupas[i] == 1)//si client déjà passé
|
|
{
|
|
printf("Déjà passé, nombre possible de passage dans une journée : 1...\n");
|
|
return -1;
|
|
}
|
|
printf("Carte trouvée !\n");
|
|
return i;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int FindN(int *tAd, int numAd, int *tpasseoupas, int tmax)
|
|
{
|
|
int i, found = 0;
|
|
i = 0;
|
|
while (found == 0 && i < tmax)
|
|
{
|
|
if(tAd[i] == numAd)
|
|
{
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
|
|
if (found == 0)
|
|
{
|
|
printf("Recherche non aboutie : numéro non enregistré...\n");//si le client n'est au final pas enregistré
|
|
return -1;
|
|
}
|
|
|
|
if (found == 1)//si trouvé
|
|
{
|
|
if (tpasseoupas[i] == 1)//si client déjà passé
|
|
{
|
|
printf("Déjà passé, nombre possible de passage dans une journée : 1...\n");
|
|
return -1;
|
|
}
|
|
printf("Carte trouvée !\n");
|
|
return i;
|
|
}
|
|
}
|
|
|
|
|
|
void Recharge(int *tptsbought, int place, char *tcateg)
|
|
{
|
|
int dizpts, topay, nbpts;
|
|
printf("Combien de dizaines de points souhaitez-vous acheter ?\n");
|
|
scanf("%d", &dizpts);
|
|
while (dizpts > 100 || dizpts < 0)
|
|
{
|
|
printf("Veuillez entrer un nombre correct de dizaines de points\n");
|
|
scanf("%d", &dizpts);
|
|
}
|
|
|
|
if (tcateg[place] == 'E')
|
|
{
|
|
nbpts = dizpts * 10;
|
|
topay = dizpts * 2;
|
|
tptsbought[place] += nbpts;
|
|
|
|
printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay);
|
|
}
|
|
|
|
if (tcateg[place] == 'S')
|
|
{
|
|
nbpts = dizpts * 10;
|
|
topay = dizpts * 4;
|
|
tptsbought[place] += nbpts;
|
|
|
|
printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay);
|
|
}
|
|
|
|
if (tcateg[place] == 'A')
|
|
{
|
|
nbpts = dizpts * 10;
|
|
topay = dizpts * 6;
|
|
tptsbought[place] += nbpts;
|
|
|
|
printf("Vous avez désormais %d points sur la carte, vous nous devez %d\n", tptsbought[place], topay);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Acti(int i)
|
|
{
|
|
int acti;
|
|
printf("Choix de l'activité %d: badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5) \n", i);
|
|
scanf("%*c%d", &acti);
|
|
while (acti != 1 && acti != 2 && acti != 3 && acti != 4 && acti != 5)
|
|
{
|
|
printf("Veuillez entrer un nombre d'activité correct (badminton (1) | football (2) | zumba (3) | musculation (4) | squash (5))\n");
|
|
scanf("%d%*c", &acti);
|
|
}
|
|
return acti;
|
|
}
|
|
|
|
|
|
|
|
int ChoiceActi(int nbacti, int *tacti)
|
|
{
|
|
int chxacti, chx1, chx2, chx3;
|
|
|
|
if (nbacti == 1)
|
|
{
|
|
chxacti = Acti(nbacti);
|
|
}
|
|
|
|
|
|
if (nbacti == 2)
|
|
{
|
|
chx1 = Acti(nbacti-1);
|
|
chx2 = Acti(nbacti);
|
|
chxacti = chx1 + chx2*10 ;
|
|
|
|
}
|
|
|
|
if (nbacti == 3)
|
|
{
|
|
chx1 = Acti(nbacti-2);
|
|
chx2 = Acti(nbacti-1);
|
|
chx3 = Acti(nbacti);
|
|
chxacti = chx1 + chx2*10 + chx3*100;
|
|
}
|
|
return chxacti;
|
|
}
|
|
|
|
|
|
|
|
void ChoiceMenu(char *choix)
|
|
{
|
|
printf("Recharge carte (R) | Afficher points (A) | Choix activités (C) | Quitter (Q)\n");
|
|
scanf("%*c%c%*c", choix);
|
|
while (*choix != 'R' && *choix != 'A' && *choix != 'C' && *choix != 'Q')
|
|
{
|
|
printf("Entrer un caractère correct R | A | C | Q \n");
|
|
scanf("%c%*c", choix);
|
|
}
|
|
}
|
|
|
|
|
|
void CheckPts(int *tptsbonus, int *tptsbought, int *tpasseoupas, int *tacti, char *tcateg, int place, int acti, int *insuf)
|
|
{
|
|
printf("%d\n", acti);
|
|
int u , d, c, actu = 0, actd = 0, actc = 0, ptsneeded;
|
|
char confirm;
|
|
u = acti % 10;//acti1
|
|
d = (acti % 100 )/10 ;//acti2
|
|
c = acti / 100;//acti3
|
|
actu = CheckActi(u);
|
|
actd = CheckActi(d);
|
|
actc = CheckActi(c);
|
|
ptsneeded = actu + actd + actc;
|
|
|
|
if (ptsneeded <= tptsbought[place])
|
|
{
|
|
("Points suffisants, confirmation ? (O/N) \n");
|
|
scanf("%*c%c%*c", &confirm);
|
|
if (confirm == 'O')
|
|
{
|
|
tptsbought[place] -= ptsneeded;
|
|
tptsbonus[place] += ptsneeded;
|
|
if (tptsbonus[place] >= 100)
|
|
{
|
|
tptsbought[place] += 15;
|
|
tptsbonus[place] -= 100;
|
|
}
|
|
|
|
tacti[place] = acti;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
*insuf = 1;
|
|
}
|
|
}
|
|
|
|
|
|
int CheckActi(int nb)
|
|
{
|
|
if (nb == 1)//badminton
|
|
{
|
|
return 8;
|
|
}
|
|
|
|
if (nb == 2)//football
|
|
{
|
|
return 5;
|
|
}
|
|
|
|
if (nb == 3)//zumba
|
|
{
|
|
return 5;
|
|
}
|
|
|
|
if (nb == 4)//muscu
|
|
{
|
|
return 15;
|
|
}
|
|
|
|
if (nb == 5)//squash
|
|
{
|
|
return 10;
|
|
}
|
|
}
|
|
|