@ -5,29 +5,40 @@
# include <strings.h> // strcasecmp : insensitive case
# include <strings.h> // strcasecmp : insensitive case
# include "trois.h"
# include "trois.h"
void afficherCandidaturesByDept ( ListeCandidats liste , int nbCandidats , char * searchIUT , char * searchDept ) {
void calculerNoteGlobale ( ListeCandidats liste , int nbCandidats ) {
float noteGlobale ;
float noteGlobale ;
for ( int i = 0 ; i < nbCandidats ; i + + ) {
noteGlobale = ( ( liste [ i ] - > moyenneMath ) * 5
+ ( liste [ i ] - > moyenneFrancais ) * 10
+ ( liste [ i ] - > moyenneAnglais ) * 5
+ ( liste [ i ] - > moyenneSpecialite ) * 16 ) / 36 ;
liste [ i ] - > noteGlobale = noteGlobale ;
}
}
void afficherCandidaturesByDept ( ListeCandidats liste , int nbCandidats , char * searchIUT , char * searchDept ) {
char decision [ LEN_MAX ] , validation [ LEN_MAX ] ;
char decision [ LEN_MAX ] , validation [ LEN_MAX ] ;
ListeCandidatures candidatures ;
ListeCandidatures candidatures ;
Candidature * candidature ;
Candidature * candidature ;
ListeCandidats liste2 = ( ListeCandidats ) malloc ( nbCandidats * sizeof ( Candidat * ) ) ;
ListeCandidats liste Triee = ( ListeCandidats ) malloc ( nbCandidats * sizeof ( Candidat * ) ) ;
if ( liste2 = = NULL ) {
if ( liste Triee = = NULL ) {
perror ( " malloc " ) ;
perror ( " malloc " ) ;
exit ( errno ) ;
exit ( errno ) ;
}
}
for ( int i = 0 ; i < nbCandidats ; i + + ) {
for ( int i = 0 ; i < nbCandidats ; i + + ) {
memcpy ( & liste 2 [ i ] , & liste [ i ] , sizeof ( Candidat * ) ) ;
memcpy ( & liste Triee [ i ] , & liste [ i ] , sizeof ( Candidat * ) ) ;
}
}
qsort ( liste 2 , nbCandidats , sizeof ( Candidat * ) , compareCandidats ) ;
qsort ( liste Triee , nbCandidats , sizeof ( Candidat * ) , compareCandidats ) ;
for ( int i = 0 ; i < nbCandidats ; i + + ) {
for ( int i = 0 ; i < nbCandidats ; i + + ) {
candidatures = liste 2 [ i ] - > listeCandidatures ;
candidatures = liste Triee [ i ] - > listeCandidatures ;
for ( int j = 0 ; j < liste 2 [ i ] - > nbCandidatures ; j + + ) {
for ( int j = 0 ; j < liste Triee [ i ] - > nbCandidatures ; j + + ) {
candidature = candidatures [ j ] ;
candidature = candidatures [ j ] ;
if ( strcasecmp ( candidature - > ville , searchIUT ) = = 0 ) {
if ( strcasecmp ( candidature - > ville , searchIUT ) = = 0 ) {
@ -65,37 +76,180 @@ void afficherCandidaturesByDept(ListeCandidats liste, int nbCandidats, char* sea
break ;
break ;
}
}
noteGlobale = ( ( liste2 [ i ] - > moyenneMath ) * 5
+ ( liste2 [ i ] - > moyenneFrancais ) * 10
+ ( liste2 [ i ] - > moyenneAnglais ) * 5
+ ( liste2 [ i ] - > moyenneSpecialite ) * 16 ) / 36 ;
printf ( " \n \ e[4;37mCandidature de '%s %s' pour le département '%s' à l'IUT '%s' : \n \ e[0m "
printf ( " \n \ e[4;37mCandidature de '%s %s' pour le département '%s' à l'IUT '%s' : \n \ e[0m "
" - Décision du département : %s, \n - Décision du candidat : %s, \n - Note globale : %.2f \n \n " ,
" - Décision du département : %s, \n - Décision du candidat : %s, \n - Note globale : %.2f \n \n " ,
liste 2[ i ] - > nom , liste2 [ i ] - > prenom , candidature - > departement , candidature - > ville , decision , validation , noteGlobale ) ;
listeTriee [ i ] - > nom , listeTriee [ i ] - > prenom , candidature - > departement , candidature - > ville , decision , validation , listeTriee [ i ] - > noteGlobale ) ;
}
}
}
}
}
}
}
}
free ( liste2 ) ;
free ( listeTriee ) ;
}
void merge ( ListeCandidats liste , int start , int middle , int end ) {
int i , j , k = start ;
int n1 = middle - start + 1 ;
int n2 = end - middle ;
Candidat * left [ n1 ] , * right [ n2 ] ;
for ( i = 0 ; i < n1 ; i + + )
left [ i ] = liste [ start + i ] ;
for ( j = 0 ; j < n2 ; j + + )
right [ j ] = liste [ middle + 1 + j ] ;
i = 0 ;
j = 0 ;
while ( i < n1 & & j < n2 ) {
if ( left [ i ] - > noteGlobale > = right [ j ] - > noteGlobale )
liste [ k + + ] = left [ i + + ] ;
else
liste [ k + + ] = right [ j + + ] ;
}
while ( i < n1 )
liste [ k + + ] = left [ i + + ] ;
while ( j < n2 )
liste [ k + + ] = right [ j + + ] ;
}
void triDichotomiqueFusion ( ListeCandidats liste , int start , int end ) {
if ( start < end ) {
int middle = ( start + end ) / 2 ;
triDichotomiqueFusion ( liste , start , middle ) ;
triDichotomiqueFusion ( liste , middle + 1 , end ) ;
merge ( liste , start , middle , end ) ;
}
}
void afficherCandidatTraite ( Candidat candidat ) {
printf ( " Candidat n°%d, '%s %s' : "
" \n - Note globale : %f \n \n " ,
candidat . id , candidat . prenom , candidat . nom ,
candidat . noteGlobale ) ;
}
}
void traiterCandidatures ( VilleIUT * * tiut , int nbVilles , ListeCandidats liste , int nbCandidats , int nbCandidatsAccept , float noteMini ) {
void traiterCandidatures ( VilleIUT * * tiut , int nbVilles , ListeCandidats liste , int nbCandidats , int nbCandidatsAccept , float noteMini ) {
char dept [ LEN_MAX ] , ville [ LEN_MAX ] ;
int i , j , nbCandidatsMatch = 0 ;
char dept [ LEN_MAX ] , ville [ LEN_MAX ] , fNameAdmis [ 100 ] , fNameAttente [ 100 ] ;
FILE * fAdmis , * fAttente ;
Candidature * candidature ;
ListeCandidatures candidatures ;
ListeCandidats listeCandidatsMatch ;
Candidat listeAdmis [ nbCandidatsAccept ] , listeAttente [ nbCandidatsAccept ] , listeRefuses [ nbCandidatsAccept ] ;
strcpy ( dept , " Informatique " ) ;
strcpy ( dept , " Informatique " ) ;
strcpy ( ville , " Clermont-Ferrand " ) ;
strcpy ( ville , " Clermont-Ferrand " ) ;
int pos = rechercherVille ( tiut , nbVilles , ville ) ;
listeCandidatsMatch = ( ListeCandidats ) malloc ( nbCandidats * sizeof ( Candidat * ) ) ;
// tiut[pos]
for ( i = 0 ; i < nbCandidats ; i + + ) {
candidatures = liste [ i ] - > listeCandidatures ;
for ( j = 0 ; j < liste [ i ] - > nbCandidatures ; j + + ) {
candidature = candidatures [ j ] ;
if ( strcasecmp ( candidature - > ville , ville ) = = 0 )
if ( strcasecmp ( candidature - > departement , dept ) = = 0 )
listeCandidatsMatch [ nbCandidatsMatch + + ] = liste [ i ] ;
}
}
calculerNoteGlobale ( listeCandidatsMatch , nbCandidatsMatch ) ; // Calcul des notes de chaque candidat
triDichotomiqueFusion ( listeCandidatsMatch , 0 , nbCandidatsMatch - 1 ) ; // Trie les candidats selon leur noteGlobale
int nbAdmis = 0 , nbAttente = 0 , nbRefuse = 0 ;
for ( i = 0 ; i < nbCandidatsMatch ; i + + ) {
if ( listeCandidatsMatch [ i ] - > noteGlobale > = noteMini ) {
if ( nbAdmis < nbCandidatsAccept ) {
for ( j = 0 ; j < listeCandidatsMatch [ i ] - > nbCandidatures ; j + + )
if ( strcasecmp ( listeCandidatsMatch [ i ] - > listeCandidatures [ j ] - > ville , ville ) = = 0 )
if ( strcasecmp ( listeCandidatsMatch [ i ] - > listeCandidatures [ j ] - > departement , dept ) = = 0 )
listeCandidatsMatch [ i ] - > listeCandidatures [ j ] - > decision = 1 ;
listeAdmis [ nbAdmis + + ] = * listeCandidatsMatch [ i ] ;
} else {
for ( j = 0 ; j < listeCandidatsMatch [ i ] - > nbCandidatures ; j + + )
if ( strcasecmp ( listeCandidatsMatch [ i ] - > listeCandidatures [ j ] - > ville , ville ) = = 0 )
if ( strcasecmp ( listeCandidatsMatch [ i ] - > listeCandidatures [ j ] - > departement , dept ) = = 0 )
listeCandidatsMatch [ i ] - > listeCandidatures [ j ] - > decision = 2 ;
listeAttente [ nbAttente + + ] = * listeCandidatsMatch [ i ] ;
}
} else
listeRefuses [ nbRefuse + + ] = * listeCandidatsMatch [ i ] ;
}
strcpy ( fNameAdmis , " donnees/ " ) ;
strcat ( fNameAdmis , ville ) ;
strcat ( fNameAdmis , " _ " ) ;
strcat ( fNameAdmis , dept ) ;
strcat ( fNameAdmis , " _Admis.don " ) ;
fAdmis = fopen ( fNameAdmis , " w " ) ;
if ( fAdmis = = NULL ) {
perror ( " fopen " ) ;
exit ( errno ) ;
}
printf ( " \n Candidats acceptés : \n " ) ;
for ( i = 0 ; i < nbAdmis ; i + + ) {
printf ( " \n %d sur %d : \n \n " , i + 1 , nbCandidatsAccept ) ;
afficherCandidatTraite ( listeAdmis [ i ] ) ;
printf ( " \n " ) ;
fprintf ( fAdmis , " %s %s %.2f %.2f %.2f %.2f %.2f \n " ,
listeAdmis [ i ] . nom , listeAdmis [ i ] . prenom ,
listeAdmis [ i ] . moyenneMath , listeAdmis [ i ] . moyenneFrancais ,
listeAdmis [ i ] . moyenneAnglais , listeAdmis [ i ] . moyenneSpecialite ,
listeAdmis [ i ] . noteGlobale ) ;
}
fclose ( fAdmis ) ;
if ( nbAdmis = = 0 )
printf ( " \t Aucun candidat accepté. \n " ) ;
strcpy ( fNameAttente , " donnees/ " ) ;
strcat ( fNameAttente , ville ) ;
strcat ( fNameAttente , " _ " ) ;
strcat ( fNameAttente , dept ) ;
strcat ( fNameAttente , " _Attente.don " ) ;
fAttente = fopen ( fNameAttente , " w " ) ;
if ( fAttente = = NULL ) {
perror ( " fopen " ) ;
exit ( errno ) ;
}
printf ( " Candidats en liste d'attente : \n \n " ) ;
for ( i = 0 ; i < nbAttente ; i + + ) {
afficherCandidatTraite ( listeAttente [ i ] ) ;
printf ( " \n \n " ) ;
fprintf ( fAttente , " %s %s %.2f %.2f %.2f %.2f %.2f \n " ,
listeAttente [ i ] . nom , listeAttente [ i ] . prenom ,
listeAttente [ i ] . moyenneMath , listeAttente [ i ] . moyenneFrancais ,
listeAttente [ i ] . moyenneAnglais , listeAttente [ i ] . moyenneSpecialite ,
listeAttente [ i ] . noteGlobale ) ;
}
fclose ( fAttente ) ;
ListeDept ldept = tiut [ pos ] - > ldept ;
if ( nbAttente = = 0 )
printf ( " \t Aucun candidat en liste d'attente. \n " ) ;
while ( ldept ! = NULL & & strcmp ( ldept - > departement , dept ) ! = 0 )
printf ( " Candidats refusés : \n \n " ) ;
ldept = ldept - > suiv ;
for ( i = 0 ; i < nbRefuse ; i + + ) {
afficherCandidatTraite ( listeRefuses [ i ] ) ;
printf ( " \n \n " ) ;
}
ldept - > noteMinimale = noteMini ;
if ( nbRefuse = = 0 )
printf ( " \t Aucun candidat refusé. \n " ) ;
//TODO
free ( listeCandidatsMatch ) ;
}
}