diff --git a/Msae.c b/Msae.c index 8435fd1..939d382 100644 --- a/Msae.c +++ b/Msae.c @@ -771,7 +771,7 @@ void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax,int *phaseCandidature) /* A void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax,Candidat *tCand[],int tMaxC,int posC,int phaseCandidature) { - int select, pos,i; + int select, pos,i,retour,majChoix,j=0; char ville[31], dept[31]; int trouve; MaillonDept *m; @@ -877,7 +877,34 @@ void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax,Candidat *tCand[],int tM { if(select == 8) { - miseAJourChoixCand(tCand[pos]->tChoix, tCand[pos]->nombreChoix); + if (majChoix==1) + { + printf("Vous-avez déjà validé votre choix vous ne pouvez plus changer à présent.\n"); + clearpage(); + } + else + { + retour=miseAJourChoixCand(tCand[pos]->tChoix, tCand[pos]->nombreChoix); + if (retour==-2 || retour==0) + { + printf("Vos choix n'ont pas été mis à jour.\n"); + clearpage(); + } + if (retour==1) + { + while(jnombreChoix) + { + if (tCand[pos]->tChoix[j]->decisionCand!=1) + { + tCand[pos]->tChoix[j]->decisionCand=-1; + j++; + } + + } + majChoix=1; + } + + } } } printf("______________________________________________________________\n"); @@ -902,6 +929,81 @@ void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax,Candidat *tCand[],int tM } } + +void menuResp(Candidat *tCand[],int tMax,int phaseCandidature) +{ + int admis,deci,trouve,pos,posC,i; + float mini; + FileCand f; + ListeCand ladmis; + system("clear"); + printf("Quel est le nombre de candidat admis ?\t"); + scanf("%d",&admis); + printf("\nQuelle moyenne minimale les candidats doivent avoir ?\t"); + scanf("%f",&mini); + f=insertCroiFile(tCand,tMax,mini); + printf("\n\nVoici les candidats ayant sélectionner votre département :\t"); + afficher(f); + printf("Voulez-vous en refuser ? (insérer son numéro ou 0 pour quitter)\t"); + scanf("%d",&deci); + while (deci!=0) + { + pos=rechercherCandidat(tCand,tMax,deci, &trouve); + if(trouve==1) + { + posC=rechercherChoix(tCand[pos]->tChoix,tCand[pos]->nombreChoix,"Clermont-Ferrand","Informatique",&trouve); + tCand[pos]->tChoix[posC]->decisionResp=-1; + } + else printf("Mauvais numéro. Taper 0 pour quitter\n"); + printf("Voulez-vous en refuser ? (insérer son numéro ou 0 pour quitter)\t"); + scanf("%d",&deci); + } + ladmis=listeCandNouv(); + f=fileToAdmis(f,&ladmis,admis); + printf("Voi"); + +} + +FileCand fileToAdmis(FileCand f, ListeCand *l, int nbAdmis) +{ + Candidat *c; + while(nbAdmis!=0) + { + c=f.t->c; + f=supt(f); + *l=insererCandEntete(*l,c); + nbAdmis--; + } + return f; +} + + +FileCand insertCroiFile(Candidat *tCand[],int tMax,float mini) +{ + int i,j; + FileCand f; + f=filenouv(); + for(i=0;inombreChoix;j++) + { + + if(strcmp(tCand[i]->tChoix[j]->ville,"Clermont-Ferrand")==0 && strcmp(tCand[i]->tChoix[j]->dep,"Informatique")==0) + { + if(tCand[i]->moyenne>=mini) + { + f=adjq(f,tCand[i]); + tCand[i]->tChoix[j]->decisionResp=2; + } + else tCand[i]->tChoix[j]->decisionResp=-1; + } + } + } + return f; +} + + + void clearpage(void) /* Permet de demander à l'utilisateur pour continuer à la suite d'une action et efface le contenu affiché à l'écran */ { char entre; @@ -1390,7 +1492,7 @@ Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettan } -void miseAJourChoixCand(Choix *tChoix[], int nombreChoix) /* Fontcion permettant de mettre à jour la décision d'un candidat concernant un de ses choix */ +int miseAJourChoixCand(Choix *tChoix[], int nombreChoix) /* Fontcion permettant de mettre à jour la décision d'un candidat concernant un de ses choix */ { int pos, trouve, saisie; char ville[31], dep[31]; @@ -1404,91 +1506,35 @@ void miseAJourChoixCand(Choix *tChoix[], int nombreChoix) /* Fontcion permettant if(trouve == 0) { printf("Erreur, ce choix ne figure pas dans votre liste\n"); - return; + return -2; // retour d'erreur } system("clear"); - if(tChoix[pos]->decisionCand == -1) /* Affichage d'un menu adapté pour chaque cas ; le candidat peut choisir entre deux option ou bien ne rien faire */ - { - printf("Vous avez actuellement refusé la proposition d'admission de l'établissement\n\n"); - printf("|---------------------------------------|\n"); - printf("| Que souhaitez-vous faire ? |\n"); - printf("|---------------------------------------|\n"); - printf("| 1 Accepter la proposition d'admission |\n"); - printf("| 2 Prendre un temps de réflexion |\n"); - printf("| 3 Ne rien changer |\n"); - printf("|---------------------------------------|\n"); - printf("Saisie : "); - scanf("%d%*c", &saisie); - printf("\n"); - if(saisie == 1) - { - tChoix[pos]->decisionCand = 1; - return; - } - if(saisie == 2) - { - tChoix[pos]->decisionCand = 0; - return; - } - if(saisie == 3) - { - return; - } - } - else if(tChoix[pos]->decisionCand == 0) + if(tChoix[pos]->decisionCand == 0) { printf("Vous n'avez actuellement pris aucune décision\n\n"); printf("|---------------------------------------|\n"); printf("| Que souhaitez-vous faire ? |\n"); printf("|---------------------------------------|\n"); - printf("| 1 Refuser la proposition d'admission |\n"); - printf("| 2 Accepter la proposition d'admission |\n"); + printf("| 1 Accepter la proposition d'admission |\n"); + printf("| 2 Refuser la proposition d'admission |\n"); printf("| 3 Ne rien changer |\n"); printf("|---------------------------------------|\n"); printf("Saisie : "); scanf("%d%*c", &saisie); printf("\n"); if(saisie == 1) - { - tChoix[pos]->decisionCand = -1; - return; - } - if(saisie == 2) { tChoix[pos]->decisionCand = 1; - return; - } - if(saisie == 3) - { - return; - } - } - else if(tChoix[pos]->decisionCand == 1) - { - printf("Vous avez actuellement accepté la proposition d'admission de l'établissement\n\n"); - printf("|---------------------------------------|\n"); - printf("| Que souhaitez-vous faire ? |\n"); - printf("|---------------------------------------|\n"); - printf("| 1 Refuser la proposition d'admission |\n"); - printf("| 2 Prendre un temps de réflexion |\n"); - printf("| 3 Ne rien changer |\n"); - printf("|---------------------------------------|\n"); - printf("Saisie : "); - scanf("%d%*c", &saisie); - printf("\n"); - if(saisie == 1) - { - tChoix[pos]->decisionCand = -1; - return; + return 1; // choix accepté } if(saisie == 2) { - tChoix[pos]->decisionCand = 0; - return; + tChoix[pos]->decisionCand = -1; + return -1; // choix refusé } if(saisie == 3) { - return; + return 0; // n'a rien fait } } } @@ -1608,11 +1654,6 @@ FileCand supt(FileCand f) return f; } -FileCand supCand(FileCand f, int numeroC) -{ - -} - Candidat * tete(FileCand f) { if(videFile(f)) @@ -1623,7 +1664,7 @@ Candidat * tete(FileCand f) return f.t->c; } -int longueur(FileCand f) +int longueurFile(FileCand f) { int i = 0; while(f.t != NULL) @@ -1649,13 +1690,6 @@ int positionFileAttente(FileCand f, int numeroC) return i; } -bool vide(FileCand f) -{ - if(f.t == NULL && f.q == NULL) - return true; - return false; -} - void afficher(FileCand f) { printf("|----------------------------------------------------------------------------|\n"); @@ -1677,4 +1711,118 @@ bool videFile(FileCand f) return true; } return false; -} \ No newline at end of file +} + +/************************************* Fonctions de liste d'admission ***************************************/ +/************************************************************************************************************/ +/************************************************************************************************************/ + +ListeCand listeCandNouv(void) /*Permet de créer un liste vide puis la retourne à la fonction appelante.*/ +{ + ListeCand lCand; + lCand = NULL; + return lCand; +} + +ListeCand insererCandEntete(ListeCand lCand,Candidat *c) /*Permet d'insérer un MaillonCand en début d'une liste passée en paramètre puis renvoie cette même liste*/ +{ + MaillonCandidat *m; /* Création d'un pointeur vers une structure MaillonCand */ + m = (MaillonCandidat *)malloc(sizeof(MaillonCandidat)); /* Allocation d'un espace mémoire pour le nouveau maillon */ + if(m == NULL) + { + printf("Problème d'allocation mémoire lors de l'insertion d'un candidat dans la liste d'admission\n"); /* Message d'erreur en cas de problème de malloc */ + exit(1); + } + m->c = c; /* Affecte le département passé en paramètre à l'attribut d du nouveau maillon */ + m->suiv = lCand; + return m; +} + +ListeCand insererCand(ListeCand lCand, Candidat *c) /* Permet d'insérer un maillon dans une liste donnée en paramètre dans l'ordre alphabétique/croissant et retourne cette liste */ +{ + if(lCand == NULL) /* Si la liste est vide, insère le nouveau maillon en tête */ + { + return insererCandEntete(lCand, c); + } + if(c->numeroC < lCand->c->numeroC) /* Si le numéro de candidat est inférieur à celui de la liste testé, le maillon est inséré en tête*/ + { + return insererCandEntete(lCand, c); + } + if(c->numeroC == lCand->c->numeroC) /* Si le maillon existe déjà, retourne la liste sans changement */ + { + printf("Candidat déjà présent dans la liste\n"); + return lCand; + } + lCand->suiv = insererCand(lCand->suiv, c); /* Si aucun cas précédent n'est respecté, recommence avec le maillon suivant de la liste */ + return lCand; +} + +ListeCand supprimerCandEntete(ListeCand lCand) /* Permet de supprimer un maillon en tête de la liste donnée en paramètre et retourne cette liste */ +{ + ListeCand aux; + if(lCand == NULL) /* Si la liste est vide, quitte le programme car cela provoquerait une erreur */ + { + printf("Opération interdite\n"); + exit(1); + } + aux = lCand; /* On affecte l'adresse de la liste actuelle à une variable temporaire */ + lCand = lCand->suiv; /* On supprime le maillon */ + free(aux); /* On libère l'espace mémoire du maillon supprimer*/ + return lCand; +} + +ListeCand supprimerCand(ListeCand lCand, Candidat *c) /* Permet de supprimer un maillon d'une liste lDept passée en paramètre à partir de son attribut nom de département (dept) et retourne cette liste */ +{ + if(lCand == NULL) /* La liste est vide, on la retourne sans changements */ + { + return lCand; + } + if(c->numeroC < lCand->c->numeroC) /* Le maillon à supprimer n'existe pas, on retourne la liste sans changement */ + { + return lCand; + } + if(c->numeroC == lCand->c->numeroC) /* Le maillon à supprimer est trouvé, on le supprime */ + { + return supprimerCandEntete(lCand); + } + lCand->suiv = supprimerCand(lCand->suiv, c); /* Aucune des conditions précédentes n'a été respectée, on recommence avec le maillon suivant */ + return lCand; +} + +int longueurListe(ListeCand lCand) /* Permet d'obtenir la longueur d'une liste passée en paramètre et retourne le nombre de maillons */ +{ + int compt = 0; /* On déclare un compteur pour compter le nombre de maillons */ + while(lCand != NULL) /* Tant que la liste n'est pas vide, on incrémente le compteur de 1 et on passe au maillon suivant */ + { + compt = compt + 1; + lCand = lCand->suiv; + } + return compt; +} + +bool videListe(ListeCand lCand) /* Permet de savoir si une liste est vide et retourne un booléen */ +{ + if(lCand == NULL) + return true; + return false; +} + +ListeCand rechercherCandListe(ListeCand lCand, int numeroC, int *trouve) /* Permet de recherche un maillon dans une liste de départements passée en paramètre pour ensuite renvoyer son adresse*/ +{ + if(videListe(lCand)) /* Si la liste est vide, la variable trouve passée en pointeur prend la valeur 0 et on retourne la liste */ + { + *trouve = 0; + return lCand; + } + if(numeroC < lCand->c->numeroC) /* Même procédé que la condition précédente si le département recherché n'est pas trouvé*/ + { + *trouve = 0; + return lCand; + } + if(numeroC == lCand->c->numeroC) /* Si le département recherché est trouvé, trouve prend la valeur 1 et on retourne la liste */ + { + *trouve = 1; + return lCand; + } + return rechercherCandListe(lCand->suiv, numeroC, trouve); /* Si aucune condition n'est respectée, renvoie la même recherche pour le maillon suivant */ +}