@ -2,3 +2,271 @@
# 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 , 31 , 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 ) ;
}
fclose ( fe ) ;
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 ) //sauvegardetous 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 ;
}
}
}
void RespAdmin ( void ) //fonction dédiée au responsable d'admission
{
int nbC = 0 , nbP ;
float noteMin ;
Listecand lC = NULL ;
char rep ;
FILE * fe ;
fe = fopen ( " part3.don " , " r " ) ; //ouverture fichier
if ( fe = = NULL ) { printf ( " pb ouv file " ) ; return ; }
lC = Chargementlistecandidat ( fe , lC , & nbC ) ;
printf ( " Souhaitez vous modifier les notes de dossier déjà renseignées ?(O/N) \n ATTENTION \n Ce sera la seule fois où vous pourrez modifier ces notes \n " ) ;
scanf ( " %c " , & rep ) ; //on récupère la réponse de la volonté du responsable des adimissions
if ( rep = = ' O ' )
{
//fonction de modifs de notes à faire
return ;
}
//faire le tri des candidats en fonction de leurs noteDoss
//lC=nouveau + maj nbC
printf ( " Quelle est la note minimale d'admission souhaitée ? \n Note : \t " ) ;
scanf ( " %f " , & noteMin ) ; //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 ? \n " ) ;
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
//appeler fonction qui maj dec du jury
MajDecJury ( lC , nbC , nbP ) ;
//appeler fonction qui split en deux
//save séparément
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//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 \n " , c . moymat , c . moyfr , c . moyen , c . moyspe ) ;
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 ) ;
if ( l - > cand . lchx = = NULL ) { printf ( " whybitch " ) ; }
AffListChoix ( l - > cand . lchx ) ;
AffListeCandidat ( l - > suivcand ) ;
}
void AffListChoix ( Listechx l )
{
if ( l = = NULL ) return ;
AffCh ( l - > chx ) ;
AffListChoix ( l - > suivchx ) ;
}