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.
361 lines
10 KiB
361 lines
10 KiB
#include<stdlib.h>
|
|
#include<stdio.h>
|
|
#include<string.h>
|
|
#include"part3.h"
|
|
|
|
Choix lireC(FILE *fe)//fonction extraite de la partie 2
|
|
{
|
|
Choix c;
|
|
fscanf(fe, "%s%*c", c.ville);
|
|
fgets(c.dptmt, 26, fe);
|
|
c.dptmt[strlen(c.dptmt)-1]= '\0';
|
|
fscanf(fe, "%d %d%*c", &c.dec, &c.valid);
|
|
return c;
|
|
}
|
|
|
|
|
|
Listechx InsertTC(Listechx list, Choix m)//Insert en tête de la liste
|
|
{
|
|
Maillonchx *mchx;
|
|
mchx = (Maillonchx*)malloc(sizeof(Maillonchx));
|
|
if (mchx == NULL){printf("pb malloc"); exit(-1);}
|
|
mchx->chx = m;
|
|
mchx->suivchx = list;
|
|
return mchx;
|
|
}
|
|
|
|
|
|
Listechx InsertC(Listechx list, Choix m)//insert globalement dans liste de choix
|
|
{
|
|
if (list == NULL){return InsertTC(list, m);}
|
|
if (strcmp(list->chx.dptmt, m.dptmt)>0){return InsertTC(list, m);}
|
|
list->suivchx = InsertC(list->suivchx, m);
|
|
return list;
|
|
}
|
|
|
|
|
|
Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste
|
|
{
|
|
Mailloncand *c1;
|
|
|
|
c1 = (Mailloncand*)malloc(sizeof(Mailloncand));
|
|
if (c1 == NULL){printf("pb malloc"); exit;}
|
|
c1->cand.nEtu = c.nEtu;
|
|
strcpy(c1->cand.nom, c.nom);
|
|
strcpy(c1->cand.prenom, c.prenom);
|
|
c1->cand.moymat = c.moymat;
|
|
c1->cand.moyfr = c.moyfr;
|
|
c1->cand.moyen = c.moyen;
|
|
c1->cand.moyspe = c.moyspe;
|
|
c1->cand.noteDoss = c.noteDoss;
|
|
c1->cand.nbchx = c.nbchx;
|
|
c1->cand.lchx = c.lchx;
|
|
c1->suivcand = list;
|
|
return c1;
|
|
}
|
|
|
|
|
|
Listecand Insert(Listecand list, Candidat c)//insert globalement
|
|
{
|
|
if (list == NULL){return InsertT(list, c);}
|
|
if (strcmp(list->cand.nom, c.nom)>0){return InsertT(list, c);}
|
|
list->suivcand = Insert(list->suivcand, c);
|
|
return list;
|
|
}
|
|
|
|
Listecand InsertN(Listecand list, Candidat c)//insert globalement en fonction de la note
|
|
{
|
|
if (list == NULL){return InsertT(list, c);}
|
|
if (list->cand.noteDoss <=+ c.noteDoss){return InsertT(list, c);}
|
|
list->suivcand = InsertN(list->suivcand, c);
|
|
return list;
|
|
}
|
|
|
|
|
|
Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC)// fonction de chargement de la liste des candidats
|
|
{
|
|
int cpt, j;
|
|
fscanf(fe, "%d", nbC);
|
|
for (j = 1; j <= *nbC; j++)
|
|
{
|
|
Candidat Ca;
|
|
fscanf(fe, "%d %s%*c", &Ca.nEtu, Ca.nom);
|
|
fgets(Ca.prenom, 26, fe);
|
|
Ca.prenom[strlen(Ca.prenom)-1]= '\0';
|
|
fscanf(fe,"%f %f %f %f %f %d%*c", &Ca.moymat, &Ca.moyfr, &Ca.moyen, &Ca.moyspe, &Ca.noteDoss, &Ca.nbchx);
|
|
Ca.lchx=NULL;
|
|
|
|
for (cpt = Ca.nbchx; cpt >= 1; cpt--)
|
|
{
|
|
Choix c;
|
|
c = lireC(fe);//lire le maillon avec la fonction plus haut
|
|
Ca.lchx = InsertC(Ca.lchx, c);//insert le maillon à sa bonne place
|
|
}
|
|
lC = Insert(lC, Ca);
|
|
}
|
|
return lC;
|
|
}
|
|
|
|
|
|
|
|
void Save(Listecand lC, int nbC)//fonction de sauvegarde globale
|
|
{
|
|
FILE *fs;
|
|
//FILE *fs2;
|
|
fs=fopen("part3.don", "w");
|
|
if (fs == NULL){printf("pb ouv fichier part2.don\n");exit(-1);}
|
|
fprintf(fs, "%d\n", nbC);
|
|
//fs2=fopen("partatt.don", "w");
|
|
//if (fs2 == NULL){printf("pb ouv fichier part2.don\n");exit(-1);}
|
|
|
|
saveC(lC, fs);
|
|
//saveC(lC2, fs2);
|
|
}
|
|
|
|
void saveC(Listecand lC, FILE *fs)//sauvegarde un candidat
|
|
{
|
|
if (lC == NULL)return;
|
|
fprintf(fs, "%d\n", lC->cand.nEtu);
|
|
fprintf(fs, "%s\n", lC->cand.nom);
|
|
fprintf(fs, "%s\n", lC->cand.prenom);
|
|
fprintf(fs, "%.2f\t %.2f\t %.2f\t %.2f\t %.2f\n", lC->cand.moymat, lC->cand.moyfr, lC->cand.moyen, lC->cand.moyspe, lC->cand.noteDoss);
|
|
fprintf(fs, "%d\n", lC->cand.nbchx);
|
|
saveChx(lC->cand.lchx, fs);
|
|
saveC(lC->suivcand, fs);
|
|
}
|
|
|
|
|
|
void saveChx(Listechx lCh, FILE *fs)//sauvegarde tous les choix d'un candidat
|
|
{
|
|
if (lCh == NULL)return;
|
|
fprintf(fs, "%s\n", lCh->chx.ville);
|
|
fprintf(fs, "%s\n", lCh->chx.dptmt);
|
|
fprintf(fs, "%d\n", lCh->chx.dec);
|
|
fprintf(fs, "%d\n", lCh->chx.valid);
|
|
saveChx(lCh->suivchx, fs);
|
|
}
|
|
|
|
|
|
Listechx searchChx(Listechx lchx, char *ville, char *dptmt)
|
|
{
|
|
if (lchx == NULL){return lchx;}
|
|
if (strcmp(lchx->chx.ville, ville)==0 && strcmp(lchx->chx.dptmt, dptmt)==0)return lchx;
|
|
return searchChx(lchx->suivchx, ville, dptmt);
|
|
}
|
|
|
|
|
|
Listecand AcceptedOrWait(Listecand lC, int *nbC, float noteMin)//créée une liste de candidat en fonction de la note minimum à avoir
|
|
{
|
|
Listecand newlC=NULL;//la nouvelle liste en question
|
|
Listechx found;//pour la recherche si le candidat a le département informatique de Clermont
|
|
int cpt, i = 0;
|
|
for (cpt = 0; cpt < *nbC; cpt++)//en passant par tous les candidats
|
|
{
|
|
found = searchChx(lC->cand.lchx, "Clermont-Ferrand", "Informatique");
|
|
if (lC->cand.noteDoss >= noteMin && found != NULL)//on check s'ils ont la note d'étude de dossier requise et qu'ils ont une candidature informatique clermont
|
|
{
|
|
newlC = InsertN(newlC, lC->cand);//si oui on les ajoute
|
|
i+=1;//et comme on a une nouvelle liste on les recompte
|
|
}
|
|
lC = lC->suivcand;//on passe au suivant peu importe ce qu'il arrive
|
|
}
|
|
*nbC = i;
|
|
return newlC;
|
|
}
|
|
|
|
|
|
void MajDecJury(Listecand lC, int nbC, int nbAcc)
|
|
{
|
|
int cpt;
|
|
if (nbC > nbAcc)//si le nombre de candidats est supérieur ou égal au nombre max de personnes mises en "accepté"
|
|
{
|
|
for (cpt = 0; cpt < nbAcc; cpt++)//tous les acceptés
|
|
{
|
|
Listechx iutclinf;
|
|
iutclinf = searchChx(lC->cand.lchx, "Clermont-Ferrand", "Informatique");
|
|
iutclinf->chx.dec = 1;
|
|
lC = lC->suivcand;
|
|
}
|
|
for (cpt; cpt < nbC; cpt ++)//la liste d'attente
|
|
{
|
|
Listechx iutclinf;
|
|
iutclinf = searchChx(lC->cand.lchx, "Clermont-Ferrand", "Informatique");
|
|
iutclinf->chx.dec = 2;
|
|
lC = lC->suivcand;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (cpt = 0; cpt < nbC; cpt++)//tous acceptés si il y a moins de candidatures que de places
|
|
{
|
|
Listechx iutclinf;
|
|
iutclinf = searchChx(lC->cand.lchx, "Clermont-Ferrand", "Informatique");
|
|
iutclinf->chx.dec = 1;
|
|
lC = lC->suivcand;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Listecand searchCand(Listecand lC, char *nom, char *prenom)
|
|
{
|
|
if (lC == NULL)return lC;
|
|
if (strcmp(lC->cand.nom, nom)==0 && strcmp(lC->cand.prenom, prenom)==0)return lC;
|
|
return searchCand(lC, nom, prenom);
|
|
}
|
|
|
|
|
|
Listecand MajNote(Listecand lC, char *nom, char *prenom, float newNote)
|
|
{
|
|
Listecand c;
|
|
c = searchCand(lC, nom, prenom);//recherche du candidat
|
|
if (c == NULL)
|
|
{
|
|
printf("Aucun candidat n'a été trouvé...\n");
|
|
}
|
|
else
|
|
{
|
|
c->cand.noteDoss = newNote;
|
|
}
|
|
return lC;
|
|
}
|
|
|
|
|
|
Listecand splitAccepted(Listecand origin)
|
|
{
|
|
Listecand lCAcc=NULL;
|
|
while (origin != NULL)
|
|
{
|
|
Listechx iutclinf;
|
|
iutclinf = searchChx(origin->cand.lchx, "Clermont-Ferrand", "Informatique");
|
|
if (iutclinf->chx.dec == 1 && iutclinf !=NULL)
|
|
{
|
|
lCAcc = Insert(lCAcc, origin->cand);
|
|
}
|
|
origin = origin->suivcand;
|
|
}
|
|
return lCAcc;
|
|
}
|
|
|
|
Listecand splitWait(Listecand origin)
|
|
{
|
|
Listecand lCW=NULL;
|
|
Listechx iutclinf;
|
|
iutclinf = searchChx(origin->cand.lchx, "Clermont-Ferrand", "Informatique");
|
|
while (iutclinf->chx.dec == 1 && iutclinf != NULL)
|
|
{
|
|
origin = origin->suivcand;
|
|
if (origin == NULL)break;//on évite le tour de search inutile
|
|
iutclinf = searchChx(origin->cand.lchx, "Clermont-Ferrand", "Informatique");//tant qu'ils sont acceptés, on relis le candidat
|
|
}
|
|
while (iutclinf->chx.dec == 2 && iutclinf != NULL)//si en liste d'attente
|
|
{
|
|
lCW = Insert(lCW, origin->cand);//insertion dans la liste pour liste d'attente
|
|
origin = origin->suivcand;
|
|
if (origin == NULL)break;//on évite le tour de search inutile
|
|
iutclinf = searchChx(origin->cand.lchx, "Clermont-Ferrand", "Informatique");
|
|
}
|
|
return lCW;
|
|
}
|
|
|
|
|
|
void RespAdmin(void)//fonction dédiée au responsable d'admission
|
|
{
|
|
int nbC = 0, nbP;
|
|
float noteMin, note;
|
|
char nom[26], prenom[26];
|
|
Listecand lC=NULL;
|
|
Listecand lCAcc=NULL, lCW=NULL;//ce qui servira pour les 2 listes, l'une des acceptés et l'autre des attentes
|
|
char rep;
|
|
|
|
FILE *fe;
|
|
fe=fopen("part3.don", "r");//ouverture fichier
|
|
if (fe == NULL){printf("pb ouv file"); return;}
|
|
lC = Chargementlistecandidat(fe, lC, &nbC);
|
|
fclose(fe);
|
|
|
|
printf("*********************************************************************\n");
|
|
printf("*----------------Modification note dossier (O/N)--------------------*\n");
|
|
printf("*--ATTENTION IL NE SERA POSSIBLE DE MODIFIER CES NOTES QU'UNE FOIS--*\n");
|
|
printf("*********************************************************************\n");
|
|
scanf("%c", &rep);//on récupère la réponse de la volonté du responsable des adimissions
|
|
while (rep == 'O')
|
|
{
|
|
printf("Quel est le nom du candidat ?\nNom : \t");
|
|
scanf("%s%*c", nom);
|
|
printf("Quel est le prénom du candidat ?\nPrénom : \t");
|
|
fgets(prenom, 26, stdin);
|
|
prenom[strlen(prenom)-1]='\0';
|
|
printf("Quelle sera la nouvelle note ?\nNote : \t");
|
|
scanf("%f%*c", ¬e);
|
|
lC = MajNote(lC, nom, prenom, note);
|
|
printf("Souhaitez-vous changer/renseigner une autre note ?\n");
|
|
scanf("%c", &rep);
|
|
}
|
|
|
|
printf("Quelle est la note minimale d'admission souhaitée ?\nNote :\t");
|
|
scanf("%f", ¬eMin);//on récupère le note minimale requise pour être accepté ou en liste d'attente
|
|
|
|
lC = AcceptedOrWait(lC, &nbC, noteMin);//on créé la nouvelle liste des candidats sélectionnés par note
|
|
|
|
printf("Quel est le nombre de places disponibles ?\nNombre de places :\t");
|
|
scanf("%d", &nbP);//on récupère le nombre qu'il peut y avoir d'acceptés pour savoir qui sera accepté et qui sera en attente
|
|
|
|
MajDecJury(lC, nbC, nbP);//fonction qui maj dec du jury
|
|
lCAcc = splitAccepted(lC);//la liste des acceptés
|
|
|
|
lCW = splitWait(lC);//la liste d'attente
|
|
|
|
|
|
FILE *fA;
|
|
FILE *fW;
|
|
|
|
fA = fopen("partAcc.don", "w");//ouverture du fichier de sauvegarde des acceptés
|
|
if (fA == NULL){printf("pb ouv fichier acc\n"); exit(-1);}
|
|
|
|
fW = fopen("partWait.don", "w");//ouverture du fichier de sauvegarde de l'attente
|
|
if (fW == NULL){printf("pb ouv fichier wait\n"); exit(-1);}
|
|
|
|
saveC(lCAcc, fA);//sauvegarde des acceptés
|
|
saveC(lCW, fW);//sauvegarde de l'attente
|
|
|
|
fclose(fA);
|
|
fclose(fW);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//histoire d'avoir un AFFICHAGE
|
|
|
|
void AffC(Candidat c)
|
|
{
|
|
printf("%d\n", c.nEtu);
|
|
printf("%s\n%s\n", c.nom, c.prenom);
|
|
printf("%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n", c.moymat,c.moyfr, c.moyen, c.moyspe, c.noteDoss);
|
|
printf("%d\n", c.nbchx);
|
|
}
|
|
|
|
void AffCh(Choix c)
|
|
{
|
|
printf("%s \n", c.ville);
|
|
printf("%s \n", c.dptmt);
|
|
printf("%d \n", c.dec);
|
|
printf("%d \n", c.valid);
|
|
}
|
|
|
|
|
|
void AffListeCandidat (Listecand l){
|
|
|
|
if (l == NULL) return;
|
|
AffC(l->cand);
|
|
AffListChoix(l->cand.lchx);
|
|
AffListeCandidat(l->suivcand);
|
|
}
|
|
|
|
|
|
void AffListChoix(Listechx l)
|
|
{
|
|
if (l == NULL) return;
|
|
AffCh(l->chx);
|
|
AffListChoix(l->suivchx);
|
|
}
|