parent
aecaedc0a3
commit
4d64dac498
@ -0,0 +1,300 @@
|
|||||||
|
#include "sae.h"
|
||||||
|
|
||||||
|
int chargement(VilleIUT *tiut[],int *tMax)
|
||||||
|
{
|
||||||
|
FILE *flot;
|
||||||
|
VilleIUT *v;
|
||||||
|
MaillonDept *m;
|
||||||
|
int nb = 0, pos, trouve;
|
||||||
|
flot = fopen("IUT.don", "r");
|
||||||
|
if(flot == NULL)
|
||||||
|
{
|
||||||
|
printf("Problème d'ouverture du fichier\n");
|
||||||
|
fclose(flot);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
while(!feof(flot))
|
||||||
|
{
|
||||||
|
if(nb == *tMax)
|
||||||
|
{
|
||||||
|
tiut = reallocation(tiut,tMax);
|
||||||
|
}
|
||||||
|
v = (VilleIUT *)malloc(sizeof(VilleIUT));
|
||||||
|
if(v == NULL)
|
||||||
|
{
|
||||||
|
printf("Problème allocation ville lors de la lecture du fichier\n");
|
||||||
|
fclose(flot);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
fscanf(flot, "%s", v->nom);
|
||||||
|
printf("Nom de la ville : %s\n", v->nom);
|
||||||
|
pos = rechercheIUT(tiut, nb, v->nom, &trouve);
|
||||||
|
m = (MaillonDept *)malloc(sizeof(MaillonDept));
|
||||||
|
if(m == NULL)
|
||||||
|
{
|
||||||
|
printf("Problème allocation département lors de la lecture du fichier\n");
|
||||||
|
fclose(flot);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
*m = lireDep(flot);
|
||||||
|
if(trouve == 1)
|
||||||
|
{
|
||||||
|
insererDept(*(tiut[pos]), m);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m->suiv = NULL;
|
||||||
|
v->lDept = m;
|
||||||
|
tiut[nb] = v;
|
||||||
|
nb++;
|
||||||
|
}
|
||||||
|
free(v);
|
||||||
|
free(m);
|
||||||
|
}
|
||||||
|
return nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaillonDept lireDep(FILE *flot)
|
||||||
|
{
|
||||||
|
MaillonDept m;
|
||||||
|
fscanf(flot,"%s%d", m.dept, &m.nbP);
|
||||||
|
fgets(m.respAd,31,flot);
|
||||||
|
m.respAd[strlen(m.respAd) - 1] = '\0';
|
||||||
|
afficherDep(m);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficherDep(MaillonDept m)
|
||||||
|
{
|
||||||
|
printf("\t%s\t%d\t%s\n", m.dept, m.nbP, m.respAd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficherVille(VilleIUT v)
|
||||||
|
{
|
||||||
|
printf("%s", v.nom);
|
||||||
|
while(v.lDept != NULL)
|
||||||
|
{
|
||||||
|
afficherDep(*(v.lDept));
|
||||||
|
v.lDept = v.lDept->suiv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficherTIUT(VilleIUT *tiut[], int tLog)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for(i = 0; i < tLog; i++)
|
||||||
|
{
|
||||||
|
afficherVille(*(tiut[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve)
|
||||||
|
{
|
||||||
|
int inf,sup,t;
|
||||||
|
inf = 0;
|
||||||
|
sup = tLog - 1;
|
||||||
|
while(inf <= sup)
|
||||||
|
{
|
||||||
|
t = (inf + sup) / 2;
|
||||||
|
if(strcmp(ville, tiut[t]->nom) == 0)
|
||||||
|
{
|
||||||
|
*trouve = 1;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
if(strcmp(ville, tiut[t]->nom) < 0)
|
||||||
|
{
|
||||||
|
sup = t - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inf = t + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*trouve = 0;
|
||||||
|
return inf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int insererDept(VilleIUT v, MaillonDept *m)
|
||||||
|
{
|
||||||
|
int trouve;
|
||||||
|
MaillonDept *pos;
|
||||||
|
pos = rechercheDept(v.lDept,&trouve,m->dept);
|
||||||
|
printf("Valeur de trouve : %d", trouve);
|
||||||
|
if(trouve == 1)
|
||||||
|
{
|
||||||
|
printf("\nDépartement déjà présent dans cet IUT\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
m->suiv = pos;
|
||||||
|
pos = m;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int insererVille(VilleIUT *tiut[], int *tLog, int *tMax, char *nomV)
|
||||||
|
{
|
||||||
|
VilleIUT **aux;
|
||||||
|
int trouve,i;
|
||||||
|
int pos;
|
||||||
|
pos = rechercheIUT(tiut, tLog, nomV, &trouve);
|
||||||
|
if(trouve == 1)
|
||||||
|
{
|
||||||
|
printf("\nCette ville est déjà présente\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(*tLog == *tMax)
|
||||||
|
{
|
||||||
|
*max = *max+5;
|
||||||
|
aux = (VilleIUT**) realloc(tiut,*max*sizeof(VilleIUT*));
|
||||||
|
if(aux == NULL)
|
||||||
|
{
|
||||||
|
printf("problème de reallocation\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
tiut = aux;
|
||||||
|
}
|
||||||
|
for(i=*tlog-1;i>=pos;i--)
|
||||||
|
tiut[i+1]=tiut[i];
|
||||||
|
tiut[pos]=(VilleIUT*)malloc(sizeof(VilleIUT));
|
||||||
|
if(tiut[pos]==NULL)
|
||||||
|
{
|
||||||
|
printf("problème d'allocation mémoire\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
strcpy(tiut[pos]->nom,nomV);
|
||||||
|
tiut[pos]->lDept = listeDeptNouv();
|
||||||
|
*tlog = *tlog + 1;
|
||||||
|
return tiut;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[])
|
||||||
|
{
|
||||||
|
while(lDept->suiv != NULL)
|
||||||
|
{
|
||||||
|
if(strcmp(nom,lDept->dept) == 0)
|
||||||
|
{
|
||||||
|
*trouve = 1;
|
||||||
|
return lDept;
|
||||||
|
}
|
||||||
|
if(strcmp(nom,lDept->dept) < 0)
|
||||||
|
{
|
||||||
|
*trouve=0;
|
||||||
|
return lDept;
|
||||||
|
}
|
||||||
|
lDept = lDept->suiv;
|
||||||
|
}
|
||||||
|
*trouve = 0;
|
||||||
|
return lDept;
|
||||||
|
}
|
||||||
|
|
||||||
|
VilleIUT** reallocation(VilleIUT *tiut[], int *tMax)
|
||||||
|
{
|
||||||
|
VilleIUT **aux;
|
||||||
|
aux = (VilleIUT **)realloc(tiut, (sizeof(VilleIUT *) * (*tMax)) + 5);
|
||||||
|
*tMax = *tMax + 5;
|
||||||
|
return aux;
|
||||||
|
}
|
||||||
|
|
||||||
|
void globale(void)
|
||||||
|
{
|
||||||
|
int tLog, tMax = 10;
|
||||||
|
VilleIUT **tiut;
|
||||||
|
tiut = (VilleIUT **)malloc(sizeof(VilleIUT *) * 10);
|
||||||
|
if(tiut == NULL)
|
||||||
|
{
|
||||||
|
printf("Problème d'allocation mémoire du tableau tiut\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
tLog = chargement(tiut,&tMax);
|
||||||
|
if(tLog < 0)
|
||||||
|
{
|
||||||
|
printf("Le programme ne peut pas fonctionner\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
afficherTIUT(tiut, tLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearpage(void)
|
||||||
|
{
|
||||||
|
char entre;
|
||||||
|
printf("\nappuyé sur la touche [ENTREE] pour continuer");
|
||||||
|
scanf("%*c%c", &entre);
|
||||||
|
system("clear");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int login(void)
|
||||||
|
{
|
||||||
|
int i=3;
|
||||||
|
char id,mdp[31]="mettez20svp",mdpatrouve[31];
|
||||||
|
system("clear");
|
||||||
|
printf("################################################################\n\tBienvenue!\n\n\n\tSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\t");
|
||||||
|
scanf("%c%*c",&id);
|
||||||
|
if(id=='q')
|
||||||
|
return -1;
|
||||||
|
while(id!='A' && id!='a' && id!='U' && id!='u')
|
||||||
|
{
|
||||||
|
system("clear");
|
||||||
|
printf("################################################################\n\tMauvaise saisie (q pour quitter)\n\n\n\tSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\t");
|
||||||
|
scanf("%c%*c",&id);
|
||||||
|
if(id=='q')
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(id=='A' || id=='a')
|
||||||
|
{
|
||||||
|
while(i!=0)
|
||||||
|
{
|
||||||
|
printf("\n\n\n\tMot de passe :\t");
|
||||||
|
system("stty -echo");
|
||||||
|
fgets(mdpatrouve,31,stdin);
|
||||||
|
mdpatrouve[strlen(mdpatrouve)-1] = '\0';
|
||||||
|
if( strcmp(mdpatrouve,mdp) == 0 )
|
||||||
|
{
|
||||||
|
system("stty echo");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i--;
|
||||||
|
printf("Mot de passe incorrect, il vous reste %d chances\n",i);
|
||||||
|
}
|
||||||
|
system("stty echo");
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else return 0;
|
||||||
|
system("clear");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void afficherPlace(MaillonDept m)
|
||||||
|
{
|
||||||
|
printf("\nPour ce département il y a %d places en 1ère année \n\n",m.nbP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax){
|
||||||
|
int select=0;
|
||||||
|
while(select!=9){
|
||||||
|
system("clear");
|
||||||
|
printf("\t AFFICHAGE ADMIN\n\n");
|
||||||
|
printf("1\tModifier le nombre de places dans un département\n");
|
||||||
|
printf("2\tCréer un nouveau département\n");
|
||||||
|
printf("3\tSupprimer un département\n");
|
||||||
|
printf("4\tLancer/Arrêter la phase de candidature\n");
|
||||||
|
printf("5\tModifer le nom du responsable d'un département\n");
|
||||||
|
scanf("%d",&select);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax){
|
||||||
|
int select=0;
|
||||||
|
while(select!=9){
|
||||||
|
system("clear");
|
||||||
|
printf("\t AFFICHAGE CANDIDAT \n\n");
|
||||||
|
printf("1\tRechercher les villes où il y a un IUT\n");
|
||||||
|
printf("2\tRechercher chaque département dans les IUT\n");
|
||||||
|
printf("3\tNombres de places en 1A\n");
|
||||||
|
printf("4\tRechercher un département dans les IUT\n");
|
||||||
|
scanf("%d",&select);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue