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.
194 lines
4.0 KiB
194 lines
4.0 KiB
|
|
#include "sae.h"
|
|
|
|
int ajoutClient (void)
|
|
|
|
{
|
|
int numeroclient,suspension,verif;
|
|
float cagnotte;
|
|
|
|
FILE *fichierclient;
|
|
printf("ajout d'un client au programme de fidélité...\nquel est le numéro de ce client ?\n");
|
|
scanf("%d",&numeroclient);
|
|
while (numeroclient<0)
|
|
{
|
|
printf("le numéro du client ne peut être négatif , réessayez\n");
|
|
scanf("%d",&numeroclient);
|
|
}
|
|
|
|
fichierclient=fopen("fichierclient.don","r");
|
|
if (fichierclient==NULL)
|
|
{
|
|
printf("Probléme d'ouverture");
|
|
return -2;
|
|
}
|
|
|
|
fscanf(fichierclient,"%d%f%d",&verif,&cagnotte,&suspension);
|
|
|
|
while (feof(fichierclient)==0)
|
|
{
|
|
if (verif==numeroclient)
|
|
{
|
|
while(numeroclient==verif)
|
|
{
|
|
printf("le numéro client existe déja ,veuillez ressaissir\n");
|
|
scanf("%*c%d",&numeroclient);
|
|
}
|
|
}
|
|
|
|
fscanf(fichierclient,"%d%f%d",&verif,&cagnotte,&suspension);
|
|
|
|
}
|
|
fclose(fichierclient);
|
|
fichierclient=fopen("fichierclient.don","a");
|
|
if (fichierclient==NULL)
|
|
{
|
|
printf("Probléme d'ouverture");
|
|
return -2;
|
|
}
|
|
|
|
fprintf(fichierclient,"\t%d\t%*.2f\t%d\n",numeroclient,100,0);
|
|
fclose(fichierclient);
|
|
printf("client ajouté au programme de fidélité ! \n");
|
|
return numeroclient;
|
|
|
|
}
|
|
|
|
int supensioncarte (void)
|
|
|
|
{
|
|
int tabNC [100]={0};
|
|
float tabCAG [100]={0};
|
|
int tabSUS [100]={0};
|
|
|
|
int nc,sus,compteur=0,rapportcagnotte,taillemax=100,recherche,n;
|
|
float cagnotte;
|
|
|
|
FILE *fichierClientmegacool;
|
|
|
|
n=compteurtaillelogique();
|
|
|
|
|
|
fichierClientmegacool=fopen("fichierclient.don","r");
|
|
if (fichierClientmegacool==NULL)
|
|
{
|
|
printf("Probléme d'ouverture");
|
|
return -2;
|
|
}
|
|
|
|
fscanf(fichierClientmegacool,"%d%f%d",&nc,&cagnotte,&sus);
|
|
while(feof(fichierClientmegacool)==0)
|
|
{
|
|
tabNC[compteur]=nc;
|
|
tabCAG[compteur]=cagnotte;
|
|
tabSUS[compteur]=sus;
|
|
compteur=compteur+1;
|
|
if (compteur>n)
|
|
{
|
|
printf("erreur de taille\n");
|
|
return 0;
|
|
}
|
|
fscanf(fichierClientmegacool,"%d%f%d",&nc,&cagnotte,&sus);
|
|
}
|
|
fclose(fichierClientmegacool);
|
|
|
|
printf("quel carte souhaitez vous suspendre ou désuspendre (entrez numéro client)\n");
|
|
scanf("%d",&recherche);
|
|
while(recherche<0)
|
|
{
|
|
printf("numéro non valide , veuillez réessayez\n");
|
|
scanf("%d",&recherche);
|
|
}
|
|
for (compteur=0;compteur<taillemax;compteur++)
|
|
{
|
|
if (tabNC[compteur]==recherche)
|
|
{
|
|
compteur=rapportcagnotte;
|
|
|
|
printf("l'état de la carte de ce client est %d\n",tabSUS[compteur]);
|
|
printf("modifiez l'état (0 pour non suspendu) (1 pour suspendu)\n");
|
|
scanf("%d",&sus);
|
|
tabSUS[compteur]=sus;
|
|
}
|
|
|
|
compteur=compteur+1;
|
|
|
|
if (compteur>taillemax)
|
|
{
|
|
printf("le client n'existe pas\n");
|
|
return -2;
|
|
}
|
|
}
|
|
|
|
if (tabSUS[rapportcagnotte]==1)
|
|
{
|
|
printf("création d'une nouvelle carte pour le client %d",tabNC[compteur]);
|
|
|
|
nc=ajoutClient();
|
|
|
|
recherche=nc;
|
|
|
|
for (compteur=0;compteur<n;compteur++)
|
|
{
|
|
if (tabNC[compteur]==recherche)
|
|
{
|
|
tabCAG[compteur]=rapportcagnotte;
|
|
}
|
|
|
|
compteur=compteur+1;
|
|
|
|
if (compteur>n)
|
|
{
|
|
printf("le client n'existe pas\n");
|
|
return -2;
|
|
}
|
|
|
|
}
|
|
|
|
for (compteur=0;compteur<n;compteur++)
|
|
|
|
fprintf(fichierClientmegacool, "\t%d\t%*.2f\t%d\n",tabNC[compteur],tabCAG[compteur],tabSUS[compteur]);
|
|
|
|
printf("youpi di skoop état de suspension modifié et nouveau compte créé !\n");
|
|
|
|
}
|
|
|
|
else
|
|
{
|
|
|
|
|
|
for (compteur=0;compteur<n;compteur++)
|
|
|
|
fprintf(fichierClientmegacool, "\t%d\t%*.2f\t%d\n",tabNC[compteur],tabCAG[compteur],tabSUS[compteur]);
|
|
|
|
printf("youpi di skoop état de suspension modifié et nouveau compte créé !\n");
|
|
}
|
|
|
|
|
|
|
|
fclose(fichierClientmegacool);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
int compteurtaillelogique (void)
|
|
|
|
{
|
|
int i=0,placeholder1,placeholder2;
|
|
float placeholder3;
|
|
FILE *flot;
|
|
flot=fopen("fichierclient.don","r");
|
|
fscanf(flot,"%d%f%d",&placeholder1,&placeholder3,&placeholder2);
|
|
while(feof(flot)==0)
|
|
{
|
|
i=i+1;
|
|
fscanf(flot,"%d%f%d",&placeholder1,&placeholder3,&placeholder2);
|
|
|
|
}
|
|
fclose(flot);
|
|
return i;
|
|
|
|
} |