diff --git a/Commun.c b/Commun.c index d952b8d..156d500 100644 --- a/Commun.c +++ b/Commun.c @@ -1,4 +1,4 @@ -#include "Commun.h" +#include "Msae.h" /*********************************************************** Fonctions de listes **************************************************************/ /**********************************************************************************************************************************************/ @@ -168,7 +168,7 @@ void afficherVilleDep(VilleIUT v) /* Permet d'afficher une ville passée en para l = v.lDept; while(l != NULL) { - printf("| %-32s | %-32s | %3d | %-32s |\n", v.nom, l->d.dept, l->d.nbP, l->d.respAd); + printf("| %-32s| %-32s| %3d |%-32s|\n", v.nom, l->d.dept, l->d.nbP, l->d.respAd); printf("|----------------------------------|----------------------------------------------------------------------------|\n"); l = l->suiv; } @@ -194,7 +194,7 @@ void afficheDeptDesIUT(VilleIUT *tiut[], int tLog) rechercherDept(tiut[i]->lDept,dept,&trouve); if (trouve==1) { - printf("|%s",tiut[i]->nom); + printf("* %s\n",tiut[i]->nom); } } printf("|\n"); @@ -528,27 +528,80 @@ void miseAJourGlobale(VilleIUT *tiut[], int tLog) clearpage(); } +void lancerPhaseCandidature(int *phaseCandidature) +{ + char choix; + system("clear"); + if (*phaseCandidature==0) + { + printf("La phase de candidature n'a pas été lancée.\n"); + printf("\nÊtes-vous sur de lancer la phase de candidature?(o/n)\t"); + scanf("%c%*c",&choix); + if(choix!='O' && choix!='o') + { + printf("La phase de candidature n'a pas été lancée.\n"); + clearpage(); + return; + } + *phaseCandidature=1; + printf("\nLa phase de candidature a été lancée.\n"); + } + else if(*phaseCandidature==1) + { + printf("La phase de candidature est en court.\n"); + printf("\nÊtes-vous sur d'arrêter la phase de candidature?(o/n)\t"); + scanf("%c%*c",&choix); + if(choix!='O' && choix!='o') + { + printf("La phase de candidature n'a pas été arrêtée.\n"); + clearpage(); + return; + } + *phaseCandidature=2; + printf("\nLa phase de candidature a été arrêtée.\n"); + } + clearpage(); +} +/*autre*/ +int comptClermont(Candidat *tCand[],int tMax) +{ + int i=0,compt=0,j=0; + for(i=0;inombreChoix;j++) + { + + if(strcmp(tCand[i]->tChoix[j]->ville,"Clermont-Ferrand")==0 && strcmp(tCand[i]->tChoix[j]->dep,"Informatique")==0) + { + compt++; + } + } + } + return compt; +} + + // ########################################################################################### // ########################################################################################### // ################################ Commun au 2 parties ###################################### // ########################################################################################### // ########################################################################################### -int login(void) /* Affiche un menu de connexion pour ensuite adapter l'affichage et les fonctionnalités au type d'utilisateur */ +int login(Candidat *tCand[],int *tMax,int *pos) /* Affiche un menu de connexion pour ensuite adapter l'affichage et les fonctionnalités au type d'utilisateur */ { - int i = 3; - char id, mdp[31] = "mettez20svp", mdpatrouve[31]; /* Déclaration d'un motdepasse administrateur */ + int i = 3,trouve,numC; + char id, mdp[31] = "mettez20svp", mdpatrouve[31],choix; /* Déclaration d'un motdepasse administrateur */ system("clear"); - printf("\t################################ Bienvenue! ################################\nSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur ? (C/A)\nSaisie : "); + printf("\t################################ Bienvenue! ################################\nSouhaitez-vous vous connecter en tant que candidat, administeur ou responsable d'admissions ? (C/A/R)\nSaisie : "); scanf("%c%*c",&id); if(id == 'q') /* Si l'utilisateur saisie la lettre 'q', le programme s'arrête */ { return -1; } - while(id != 'A' && id != 'a' && id != 'C' && id != 'c') /* Effectue une saisie contrôlée si la saisie ne correspond à aucune option */ + while(id != 'A' && id != 'a' && id != 'C' && id != 'c' && id != 'r' && id != 'R') /* Effectue une saisie contrôlée si la saisie ne correspond à aucune option */ { system("clear"); - printf("\t#################### Mauvaise saisie ('q' pour quitter) ####################\nSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (C/A)\nSaisie : "); + printf("\t#################### Mauvaise saisie ('q' pour quitter) ####################\nSouhaitez-vous vous connecter en tant que candidat, administrateur ou responsable d'admissions ? (C/A/R)\nSaisie : "); scanf("%c%*c",&id); if(id == 'q') { @@ -579,20 +632,47 @@ int login(void) /* Affiche un menu de connexion pour ensuite adapter l'affichage } return -1; } - else /* Si l'utilisateur sélectionne candidat, la fonction retourne 0 */ + if(id == 'C' || id == 'c')/* Si l'utilisateur sélectionne candidat, la fonction retourne 0 */ { - system("clear"); - return 0; + printf("Êtes-vous déjà enregistré / Avez-vous un numéro de candidat ?(o/n)\t"); + scanf("%c%*c",&choix); + while(choix!='o'&&choix!='O'&&choix!='n'&&choix!='N') + { + printf("Êtes-vous déjà enregistré / Avez-vous un numéro de candidat ?(o/n)\t"); + scanf("%c%*c",&choix); + } + if(choix=='o'|| choix=='O') + { + printf("\nInsérer votre numéro de Candidat :\t"); + scanf("%d%*c",&numC); + *pos=rechercherCandidat(tCand,*tMax,numC,&trouve); + while(trouve==0) + { + printf("\nCe numéro n'existe pas. Veuillez Re-saisir :\t"); + scanf("%d%*c",&numC); + *pos=rechercherCandidat(tCand,*tMax,numC,&trouve); + } + return 0; + } + if(choix=='n'|| choix=='N') + { + tCand=creerCandidat(tCand,tMax,pos); + return 0; + } + + } + if(id == 'R' || id == 'r') + { + return 3; } } - - -void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax) /* Affiche un menu de choix adaptés pour un administrateur et appelle les fonctions en conséquence */ +void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax,Candidat *tCand[],int tMaxC,int *phaseCandidature,FileCand *f,ListeCand *ladmis)/* Affiche un menu de choix adaptés pour un administrateur et appelle les fonctions en conséquence */ { int select, pos; - int trouve; + int trouve,nbClfd; char ville[31], choix; + Candidat **tIntermediaire; ListeDept l; printf("__________________________________________________________\n"); printf("| MENU ADMIN |\n"); @@ -635,52 +715,76 @@ void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax) /* Affiche un menu de choi { creerDept(tiut, *tLog); } - if(select == 4) - { - retirerDept(tiut, *tLog); - } - if(select == 5) - { - miseAJourGlobale(tiut, tLog); - } - if(select == 6) + if(*phaseCandidature==0) { - printf("Quel est le nom de la ville à insérer ?\nSaisie : "); /* Demande le nom de la ville à insérer */ - scanf("%s%*c", ville); - printf("\n"); - pos = rechercheIUT(tiut, *tLog, ville, &trouve); /* Vérifie que la ville existe */ - if(trouve == 1) /* Si elle existe, affiche un message d'erreur */ + if(select == 4) { - printf("Erreur, cette ville existe déjà !\n"); + retirerDept(tiut, *tLog); } - else /* Sinon, appelle la fonction d'insertion */ + if(select == 5) { - insererVille(tiut, ville, tLog, tMax, pos); + miseAJourGlobale(tiut, *tLog); } - } - if(select == 7) - { - printf("Quel est le nom de la ville à supprimer ?\nSaisie : "); /* Demande le nom de la ville à supprimer */ - scanf("%s%*c", ville); - printf("\n"); - pos = rechercheIUT(tiut, *tLog, ville, &trouve); /* Vérifie qu'elle existe */ - if(trouve == 0) /* Si elle n'existe pas, affiche un message d'erreur */ + if(select == 6) { - printf("Erreur, cette ville n'existe pas !\n"); + printf("Quel est le nom de la ville à insérer ?\nSaisie : "); /* Demande le nom de la ville à insérer */ + scanf("%s%*c", ville); + printf("\n"); + pos = rechercheIUT(tiut, *tLog, ville, &trouve); /* Vérifie que la ville existe */ + if(trouve == 1) /* Si elle existe, affiche un message d'erreur */ + { + printf("Erreur, cette ville existe déjà !\n"); + } + else /* Sinon, appelle la fonction d'insertion */ + { + insererVille(tiut, ville, tLog, tMax, pos); + } } - else /* Sinon, demande confirmation, si confirmé, supprime la ville, sinon annule la suppression */ + if(select == 7) { - printf("Êtes-vous sur de vouloir supprimer cette ville ? (O/n)\nSaisie : "); /* Demande confirmation de la suppression */ - scanf("%c%*c", &choix); + printf("Quel est le nom de la ville à supprimer ?\nSaisie : "); /* Demande le nom de la ville à supprimer */ + scanf("%s%*c", ville); printf("\n"); - if(choix == 'N' || choix == 'n') /* Si le choix et non, annule la supression */ + pos = rechercheIUT(tiut, *tLog, ville, &trouve); /* Vérifie qu'elle existe */ + if(trouve == 0) /* Si elle n'existe pas, affiche un message d'erreur */ { - printf("Suppression annulée\n"); + printf("Erreur, cette ville n'existe pas !\n"); } - else + else /* Sinon, demande confirmation, si confirmé, supprime la ville, sinon annule la suppression */ + { + printf("Êtes-vous sur de vouloir supprimer cette ville ? (O/n)\nSaisie : "); /* Demande confirmation de la suppression */ + scanf("%c%*c", &choix); + printf("\n"); + if(choix == 'N' || choix == 'n') /* Si le choix et non, annule la supression */ + { + printf("Suppression annulée\n"); + } + else + { + supprimerVille(tiut, ville, tLog, pos); + } + } + } + } + if(select==8) + { + lancerPhaseCandidature(phaseCandidature); + printf("Phase de candidature : %d\n", *phaseCandidature); + clearpage(); + if(*phaseCandidature==2) + { + nbClfd=comptClermont(tCand,tMaxC); + printf("Nombre de Clermont : %d\n", nbClfd); + clearpage(); + tIntermediaire=(Candidat **)malloc(nbClfd*sizeof(Candidat*)); + if(tIntermediaire==NULL) { - supprimerVille(tiut, ville, tLog, pos); + printf("Problème d'allocation\n"); + exit(1); } + tIntermediaire=remplirCandCl(tCand,tIntermediaire,tMaxC,nbClfd); + afficherCandChoix(tIntermediaire, nbClfd); + *f=insertFile(tIntermediaire,nbClfd); } } printf("__________________________________________________________\n"); @@ -701,22 +805,31 @@ void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax) /* Affiche un menu de choi } } -void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax,Candidat *tCand[],int tMaxC) +void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax,Candidat *tCand[],int tMaxC,int posC,int phaseCandidature,FileCand *f,ListeCand *ladmis,float mini) { - int select, pos; + int select, pos,i,retour,majChoix,j=0; char ville[31], dept[31]; int trouve; + ListeCand suppr; MaillonDept *m; system("clear"); - printf("_____________________________________________________\n"); - printf("| MENU CANDIDAT |\n"); - printf("|---------------------------------------------------|\n"); - printf("| 1 Afficher les villes où il y a un IUT |\n"); - printf("| 2 Afficher tous les départements dans chaque IUT |\n"); - printf("| 3 Nombres de places en première année |\n"); - printf("| 4 Afficher les IUT possédant le département voulu |\n"); - printf("| 9 Quitter |\n"); - printf("|___________________________________________________|\n"); + printf("______________________________________________________________\n"); + printf("| MENU CANDIDAT |\n"); + printf("|------------------------------------------------------------|\n"); + printf("| Bienvenue %-32s |\n", tCand[posC]->prenom); + printf("|------------------------------------------------------------|\n"); + printf("| Que souhaitez-vous faire ? |\n"); + printf("|------------------------------------------------------------|\n"); + printf("| 1 Afficher les villes où il y a un IUT |\n"); + printf("| 2 Afficher tous les départements dans un IUT |\n"); + printf("| 3 Nombres de places en première année |\n"); + printf("| 4 Afficher les IUT possédant le département voulu |\n"); + printf("| 5 Afficher vos choix |\n"); + printf("| 6 Ajouter un choix |\n"); + printf("| 7 Supprimer un choix |\n"); + printf("| 8 Mettre à jour votre décision concernant un établissement |\n"); + printf("| 9 Quitter |\n"); + printf("|____________________________________________________________|\n"); printf("Saisie : "); scanf("%d%*c",&select); while(select != 9) @@ -743,7 +856,7 @@ void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax,Candidat *tCand[],int tM } if(select==3) { - printf("Quel IUT ?\nSaisie :"); + printf("Quel IUT ?\nSaisie : "); scanf("%s%*c",ville); pos=rechercheIUT(tiut,*tLog,ville,&trouve); while(trouve==0) @@ -769,20 +882,248 @@ void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax,Candidat *tCand[],int tM { afficheDeptDesIUT(tiut,*tLog); } - printf("_____________________________________________________\n"); - printf("| MENU CANDIDAT |\n"); - printf("|---------------------------------------------------|\n"); - printf("| 1 Afficher les villes où il y a un IUT |\n"); - printf("| 2 Afficher tous les départements dans chaque IUT |\n"); - printf("| 3 Nombres de places en première année |\n"); - printf("| 4 Afficher les IUT possédant le département voulu |\n"); - printf("| 9 Quitter |\n"); - printf("|___________________________________________________|\n"); + if(phaseCandidature==1) + { + if(select == 5) + { + for(i = 0; i < tCand[posC]->nombreChoix; i++) + { + afficherChoix(tCand[posC]->tChoix[i]); + } + } + if(select == 6) + { + tCand[posC]->tChoix = insererChoix(tCand[posC]->tChoix, &tCand[posC]->nombreChoix); + for(i = 0; i < tCand[posC]->nombreChoix; i++) + { + afficherChoix(tCand[posC]->tChoix[i]); + } + clearpage(); + } + if(select == 7) + { + tCand[posC]->tChoix = supprimerChoix(tCand[posC]->tChoix, &tCand[posC]->nombreChoix); + for(i = 0; i < tCand[posC]->nombreChoix; i++) + { + afficherChoix(tCand[posC]->tChoix[i]); + } + clearpage(); + } + } + if(phaseCandidature==2) + { + if(select == 8) + { + if (majChoix==1) + { + printf("Vous-avez déjà validé votre choix vous ne pouvez plus changer à présent.\n"); + clearpage(); + } + else + { + retour=miseAJourChoixCand(tCand[posC]->tChoix, tCand[posC]->nombreChoix); + if (retour==-2 || retour==0) + { + printf("Vos choix n'ont pas été mis à jour.\n"); + clearpage(); + } + if (retour==1) + { + while(jnombreChoix) + { + if (tCand[posC]->tChoix[j]->decisionCand!=1) + { + tCand[posC]->tChoix[j]->decisionCand=-1; + j++; + } + + } + majChoix=1; + } + if(retour==-1) + { + while (jnombreChoix) + { + if(strcmp(tCand[posC]->tChoix[j]->ville, "Clermont-Ferrand") == 0 && strcmp(tCand[posC]->tChoix[j]->dep, "Informatique") == 0) + { + tCand[posC]->tChoix[j]->decisionCand=-1; + break; + } + } + suppr=rechercherCandListe(*ladmis,tCand[posC]->numeroC,&trouve); + *ladmis=supprimerCand(*ladmis,tCand[posC]); + *f=fileToAdmis(*f,ladmis,1,mini); + } + } + } + } + printf("______________________________________________________________\n"); + printf("| MENU CANDIDAT |\n"); + printf("|------------------------------------------------------------|\n"); + printf("| Bienvenue %-32s |\n", tCand[posC]->prenom); + printf("|------------------------------------------------------------|\n"); + printf("| Que souhaitez-vous faire ? |\n"); + printf("|------------------------------------------------------------|\n"); + printf("| 1 Afficher les villes où il y a un IUT |\n"); + printf("| 2 Afficher tous les départements dans chaque IUT |\n"); + printf("| 3 Nombres de places en première année |\n"); + printf("| 4 Afficher les IUT possédant le département voulu |\n"); + printf("| 5 Afficher vos choix |\n"); + printf("| 6 Ajouter un choix |\n"); + printf("| 7 Supprimer un choix |\n"); + printf("| 8 Mettre à jour votre décision concernant un établissement |\n"); + printf("| 9 Quitter |\n"); + printf("|____________________________________________________________|\n"); printf("Saisie :"); scanf("%d%*c",&select); } } + +void menuResp(Candidat *tCand[],int tMax,int phaseCandidature,FileCand *f,ListeCand *ladmis,float *mini) +{ + int select=0; + while(select!=9) + { + system("clear"); + printf("___________________________________________________________\n"); + printf("| Menu Responsable |\n"); + printf("|---------------------------------------------------------|\n"); + printf("| 1 Déclarez une moyenne minimale (obligatoire) |\n"); + printf("| 2 Gérer les admissions |\n"); + printf("| 3 Afficher la liste des admissions ou la file d'attente |\n"); + printf("| 9 Quitter |\n"); + printf("|_________________________________________________________|\n"); + printf("\nSaisie :\t"); + scanf("%d%*c",&select); + if(select==1) + { + printf("Quelle est la moyenne minimale pour entrer dans votre département?\t"); + scanf("%f%*c",mini); + } + if(select==2) + { + gererAdmis(f,ladmis,*mini); + } + if(select==3) + { + afficherCandidatsParCategorie(*f,*ladmis); + } + } + clearpage(); +} + +void gererAdmis(FileCand *f, ListeCand *l,float mini) +{ + int select=0,admis,i=0; + char choix; + Candidat *c; + while (select!=9) + { + system("clear"); + printf("1 Accepter des candidats\n"); + printf("2 Refuser des candidats\n"); + printf("9 Quitter\n"); + scanf("%d%*c",&select); + if(select==1) + { + afficher(*f); + printf("\nCombien de candidats voulez vous accepter?\t"); + scanf("%d%*c",&admis); + *f=fileToAdmis(*f,l,admis,mini); + afficherListeCand(*l); + } + if(select==2) + { + c=tete(*f); + afficherCandidat(c); + printf("Refuser le candidat?(o/n)"); + scanf("%c",&choix); + if(choix=='o'||choix=='O') + { + *f=supt(*f); + while(inombreChoix) + { + if (strcmp(c->tChoix[i]->ville, "Clermont-Ferrand") == 0 && strcmp(c->tChoix[i]->dep, "Informatique") == 0) + { + c->tChoix[i]->decisionResp=-1; + } + i++; + } + } + } + + } + clearpage(); +} + +FileCand fileToAdmis(FileCand f, ListeCand *l, int nbAdmis,float mini) +{ + int j; + Candidat *c; + while(nbAdmis!=0) + { + if(f.t->c->moyenne>=mini) + { + c=f.t->c; + f=supt(f); + *l=insererCandEntete(*l,c); + for(j = 0; j < c->nombreChoix; j++) + { + if(strcmp(c->tChoix[j]->ville, "Clermont-Ferrand") == 0 && strcmp(c->tChoix[j]->dep, "Informatique") == 0) + { + c->tChoix[j]->decisionResp = 1; + } + } + nbAdmis--; + } + else f=supt(f); + } + return f; +} + + +FileCand insertFile(Candidat *tCand[],int nbClfd) +{ + int i, j; + FileCand f; + f=filenouv(); + printf("Début insertion dans file\n"); + clearpage(); + for(i=0;imoyenne); + clearpage(); + if(tCand[i]->moyenne >= 12.0) + { + printf("Début adjonction\n"); + f=adjq(f,tCand[i]); + printf("Adjonction réussie\n"); + for(j = 0; j < tCand[i]->nombreChoix; j++) + { + if(strcmp(tCand[i]->tChoix[j]->ville, "Clermont-Ferrand") == 0 && strcmp(tCand[i]->tChoix[j]->dep, "Informatique") == 0) + { + tCand[i]->tChoix[j]->decisionResp = 2; + } + } + } + else + { + if(strcmp(tCand[i]->tChoix[j]->ville, "Clermont-Ferrand") == 0 && strcmp(tCand[i]->tChoix[j]->dep, "Informatique") == 0) + { + tCand[i]->tChoix[j]->decisionResp = -1; + } + } + + } + printf("Fin insertion dans file\n"); + clearpage(); + 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; @@ -791,11 +1132,14 @@ void clearpage(void) /* Permet de demander à l'utilisateur pour continuer à la system("clear"); } - void globale(void) /* Permet l'initialisation du tableau, le chargement de celui-ci et l'appel des fonctions login, menus et enregistrement */ { - int tLog, retour; + int tLog, retour,tMax,numC,phaseCandidature=0,pos; + float mini; + Candidat **tCand; VilleIUT *tiut[100]; /* Déclaration du tableau de pointeurs tiut */ + FileCand f; + ListeCand ladmis; if(tiut == NULL) /* En cas de problème de mémoire, affiche un message d'erreur et quitte le programme */ { printf("Problème d'allocation mémoire du tableau tiut\n"); @@ -807,22 +1151,34 @@ void globale(void) /* Permet l'initialisation du tableau, le chargement de celui printf("Le programme ne peut pas fonctionner\n"); exit(1); } - retour = login(); /* Appelle la fonction login */ + // Chargement des candidats + tCand = chargementCandidats(&tMax); + triCandidats(tCand, tMax); + + retour = login(tCand,&tMax,&pos); /* Appelle la fonction login */ while(retour != -1) /* Tant que login ne retourne pas -1, la fonction appelle le menu adaptée en fonction du retour de login puis appelle de nouveau login */ { if(retour == 1) { - menuAdmin(tiut, &tLog, 100); + menuAdmin(tiut, &tLog, 100,tCand,tMax,&phaseCandidature,&f,&ladmis); } if(retour == 0) { - menuCandidat(tiut, &tLog, 100); + menuCandidat(tiut, &tLog, 100,tCand,tMax,pos,phaseCandidature,&f,&ladmis,mini); + } + retour = login(tCand,&tMax,&pos); + if(retour==3) + { + menuResp(tCand,tMax,phaseCandidature,&f,&ladmis,&mini); } - retour = login(); } enregistrement(tiut, tLog); } + + + + void enregistrement(VilleIUT *tiut[],int tLog) /* Permet l'enregistrement du tableau tiut dans le fichier IUT.don */ { int i; @@ -853,7 +1209,6 @@ void enregistrement(VilleIUT *tiut[],int tLog) /* Permet l'enregistrement du tab // ########################################################################################### // ########################################################################################### - /************************************** Fonctions de Chargement ********************************************/ /****************************************** Et de sauvegarde*************************************************/ /************************************************************************************************************/ @@ -871,6 +1226,7 @@ Candidat ** chargementCandidats(int *tMax) /* Permet de charger le contenu du fi exit(1); } fscanf(flot, "%d", tMax); /* Lecture du nombre de candidats pour déterminer la taille physique du tableau */ + printf("tMax : %d\n", *tMax); tCand = (Candidat **)malloc(sizeof(Candidat *) * (*tMax)); /* Allocation dynamique du tableau de candidats*/ if(tCand == NULL) { @@ -905,7 +1261,7 @@ Candidat * lireCandidat(FILE *flot) /* Fonction permettant de lire un candidat d fgets(c->prenom, 31, flot); c->prenom[strlen(c->prenom) - 1] = '\0'; fscanf(flot, "%f%f%f%f%*c", &c->notes[0], &c->notes[1], &c->notes[2], &c->notes[3]); - c->moyenne = (c->notes[0] + c->notes[1] + c->notes[2] + c->notes[3]) / 4; + c->moyenne = (c->notes[0] + c->notes[1] + c->notes[2] + c->notes[3]) / 4; fscanf(flot, "%d%*c", &c->nombreChoix); c->tChoix = (Choix **)malloc(sizeof(Choix *) * c->nombreChoix); /* Allocation dynamique du tableau de pointeurs vers des structures Choix*/ if(c->tChoix == NULL) /* pour le chargement des choix du candidats */ @@ -987,12 +1343,12 @@ void afficherCandChoix(Candidat *tCand[],int tMax) /* Fonction permettant d'aff int i, j; for(i = 0; i < tMax; i++) { - printf("_____________________________________________________________________________________________________________________\n"); - printf("| Candidat |\n"); + printf("_______________________________________________________________________________________________________________________\n"); + printf("| Candidat |\n"); afficherCandidat(tCand[i]); printf("\n"); - printf("_________________________________________________________________________________\n"); - printf("| Choix |\n"); + printf("_______________________________________________________________________________\n"); + printf("| Choix |\n"); for(j = 0; j < tCand[i]->nombreChoix; j++) { afficherChoix(tCand[i]->tChoix[j]); @@ -1023,27 +1379,6 @@ void afficherCandDep(Candidat *tCand[], int tMax) /* Fonction permettant d'affic } -void afficherCandidatsParCatégorie(Candidat *tCand[], char ville[], char dep[], int tMax) -{ - int categ, i, pos, trouve; - printf("Quelle catégorie de candidats souhaitez-vous afficher ? (admis = 1 / attente = 2)\nSaisie : "); - saisie("%d%*c", &categ); - printf("\n"); - for(i = 0; i < tMax; i++) - { - pos = rechercherChoix(tCand[i]->tChoix, nombreChoix, ville, dep, &trouve); - if(trouve == 1) - { - if(tCand[i]->tChoix[pos]->decisionResp == categ) - { - afficherCandidat(tCand[i]); - afficherChoix(tCand[i]->tChoix[pos]); - } - } - } -} - - /************************************ Fonctions de réallocation *********************************************/ /************************************************************************************************************/ /************************************************************************************************************/ @@ -1092,13 +1427,6 @@ int plusGrandCand(Candidat *tCand[], int tMax) /* Fonction permettant de trouver int maxi = 0, i; for(i = 1; i < tMax; i++) { - if(strcmp(tCand[i]->nom, tCand[maxi]->nom) == 0) - { - if(strcmp(tCand[i]->prenom, tCand[maxi]->prenom) > 0) - { - maxi = i; - } - } if(strcmp(tCand[i]->nom, tCand[maxi]->nom) > 0) { maxi = i; @@ -1109,6 +1437,7 @@ int plusGrandCand(Candidat *tCand[], int tMax) /* Fonction permettant de trouver void echangerCand(Candidat *tCand[], int i, int j) /* Fonction permettant d'échanger deux éléments dans un tableau de candidats*/ { + printf("Echange\n"); Candidat *aux; aux = tCand[i]; tCand[i] = tCand[j]; @@ -1159,6 +1488,62 @@ void echangerChoix(Choix *tChoix[], int i, int j) /* Fonction permettant d'écha /************************************************************************************************************/ /************************************************************************************************************/ +Candidat ** creerCandidat(Candidat *tCand[], int *tMax,int *pos) +{ + int trouve, i, numeroC; + char nom[31], prenom[31]; + float notes[4]; + Candidat *c; + printf("Quel est votre numéro de candidat ?\nSaisie : "); /* Demande à l'utilisateur le numéro du candidat pour l'insertion */ + scanf("%d%*c", &numeroC); + printf("\n"); + *pos = rechercherCandidat(tCand, *tMax, numeroC, &trouve); /* Vérifie que le numero de candidat n'existe pas déjà */ + if(trouve == 1) + { + printf("Erreur, votre numéro de candidat existe déjà dans la base de données\n"); + return tCand; + } + c = (Candidat *)malloc(sizeof(Candidat)); /* Allocation dynamique du candidat à insérer */ + if(c == NULL) + { + printf("Erreur d'allocation mémoire lors de l'insertion du candidat\n"); + return tCand; + } + printf("Quel est votre nom ?\n"); + scanf("%s%*c", nom); + printf("\n"); + printf("Quel est votre prenom ?\n"); + scanf("%s%*c", prenom); + printf("\n"); + printf("Quel est votre moyenne de maths ?\n"); + scanf("%f%*c", ¬es[0]); + printf("\n"); + printf("Quel est votre moyenne de français ?\n"); + scanf("%f%*c", ¬es[1]); + printf("\n"); + printf("Quel est votre moyenne d'anglais ?\n"); + scanf("%f%*c", ¬es[2]); + printf("\n"); + printf("Quel est votre moyenne de spécialité ?\n"); + scanf("%f%*c", ¬es[3]); + printf("\n"); + c->numeroC = numeroC; + strcpy(c->nom, nom); /* Ajout des valeurs dans le candidat à insérer */ + strcpy(c->prenom, prenom); + c->notes[0] = notes[0]; + c->notes[1] = notes[1]; + c->notes[2] = notes[2]; + c->notes[3] = notes[3]; + tCand = reallocationCand(tCand, *tMax); /* Réallocation du tableau de candidats pour ajouter une place */ + for(i = *tMax; i > *pos; i--) /* Décalage à droite des éléments du tableau à partir de la position d'insertion */ + { + tCand[i] = tCand[i - 1]; + } + tCand[*pos] = c; /* Ajout du candidat dans le tableau */ + *tMax = *tMax + 1; /* Mise à jour de la taille physique du tableau */ + return tCand; +} + Choix ** insererChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettant d'ajouter un nouveau choix dans un tableau de choix et retournant le tableau*/ { int pos, trouve, i; @@ -1198,7 +1583,7 @@ Choix ** insererChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettant Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettant de supprimer un choix d'un tableau de choix */ { - Choix **aux, *temp; /* Déclaration d'une variable aux prenant la valeur du tableau */ + Choix **aux; /* Déclaration d'une variable aux prenant la valeur du tableau */ int i, pos, trouve; char ville[31], dep[31], saisie; printf("Dans quelle ville se trouve la formation que vous souhaitez retirer de vos choix ?\nSaisie : "); /* Demande au candidat dans quelle ville supprimer le choix */ @@ -1220,7 +1605,6 @@ Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettan { return tChoix; } - temp = tChoix[pos]; for(i = pos; i < *nombreChoix - 1; i++) /* Décalage à gauche des éléments du tableau à partir du dernier jusqu'au choix à supprimer */ { tChoix[i] = tChoix[i + 1]; @@ -1230,10 +1614,8 @@ Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettan if(aux == NULL) { printf("Problème avec la réallocation lors de la suppression\n"); - free(temp); return tChoix; } - free(temp); return aux; } @@ -1252,7 +1634,7 @@ int miseAJourChoixCand(Choix *tChoix[], int nombreChoix) /* Fontcion permettant if(trouve == 0) { printf("Erreur, ce choix ne figure pas dans votre liste\n"); - return -2; + return -2; // retour d'erreur } system("clear"); if(tChoix[pos]->decisionCand == 0) @@ -1271,146 +1653,20 @@ int miseAJourChoixCand(Choix *tChoix[], int nombreChoix) /* Fontcion permettant if(saisie == 1) { tChoix[pos]->decisionCand = 1; - return 1; + return 1; // choix accepté } if(saisie == 2) { tChoix[pos]->decisionCand = -1; - return -1; + return -1; // choix refusé } if(saisie == 3) { - return 0; + return 0; // n'a rien fait } } } - -// void miseAJourChoixResp(Choix *tChoix[], int pos) /* Fontcion permettant de mettre à jour la décision d'un responsable d'admission concernant un candidat */ -// { -// int saisie; -// system("clear"); -// if(tChoix[pos]->decisionCand == 0) /* Affichage d'un menu adapté pour chaque cas ; le candidat peut choisir entre deux option ou bien ne rien faire */ -// { -// printf("Votre décision est actuellement en attente\n\n"); -// printf("|---------------------------------------|\n"); -// printf("| Que souhaitez-vous faire ? |\n"); -// printf("|---------------------------------------|\n"); -// printf("| 1 Accepter la demande d'admission |\n"); -// printf("| 2 Mettre sur liste d'attente |\n"); -// printf("| 3 Refuser la demande d'admission |\n"); -// printf("| 4 Ne rien changer |\n"); -// printf("|---------------------------------------|\n"); -// printf("Saisie : "); -// scanf("%d%*c", &saisie); -// printf("\n"); -// if(saisie == 1) -// { -// tChoix[pos]->decisionResp = 1; -// return; -// } -// if(saisie == 2) -// { -// tChoix[pos]->decisionCand = 2; -// return; -// } -// if(saisie == 3) -// { -// tChoix[pos]->decisionCand = -1; -// return; -// } -// if(saisie == 4) -// { -// return; -// } -// } -// if(tChoix[pos]->decisionCand == 2) /* Affichage d'un menu adapté pour chaque cas ; le candidat peut choisir entre deux option ou bien ne rien faire */ -// { -// printf("Votre décision est actuellement en attente\n\n"); -// printf("|---------------------------------------|\n"); -// printf("| Que souhaitez-vous faire ? |\n"); -// printf("|---------------------------------------|\n"); -// printf("| 1 Accepter la demande d'admission |\n"); -// printf("| 2 Refuser la demande d'admission |\n"); -// printf("| 3 Ne rien changer |\n"); -// printf("|---------------------------------------|\n"); -// printf("Saisie : "); -// scanf("%d%*c", &saisie); -// printf("\n"); -// if(saisie == 1) -// { -// tChoix[pos]->decisionResp = 1; -// return; -// } -// if(saisie == 2) -// { -// tChoix[pos]->decisionCand = -1; -// return; -// } -// if(saisie == 3) -// { -// return; -// } -// } -// } - - -Candidat ** creerCandidat(Candidat *tCand[], int *tMax) -{ - int pos, trouve, i, numeroC; - char nom[31], prenom[31]; - float notes[4]; - Candidat *c; - printf("Quel est votre numéro de candidat ?\nSaisie : "); /* Demande à l'utilisateur le numéro du candidat pour l'insertion */ - scanf("%d%*c", &numeroC); - printf("\n"); - pos = rechercherCandidat(tCand, *tMax, numeroC, &trouve); /* Vérifie que le numero de candidat n'existe pas déjà */ - if(trouve == 1) - { - printf("Erreur, votre numéro de candidat existe déjà dans la base de données\n"); - return tCand; - } - c = (Candidat *)malloc(sizeof(Candidat)); /* Allocation dynamique du candidat à insérer */ - if(c == NULL) - { - printf("Erreur d'allocation mémoire lors de l'insertion du candidat\n"); - return tCand; - } - printf("Quel est votre nom ?\n"); - scanf("%s%*c", nom); - printf("\n"); - printf("Quel est votre prenom ?\n"); - scanf("%s%*c", prenom); - printf("\n"); - printf("Quel est votre moyenne de maths ?\n"); - scanf("%f%*c", ¬es[0]); - printf("\n"); - printf("Quel est votre moyenne de français ?\n"); - scanf("%f%*c", ¬es[1]); - printf("\n"); - printf("Quel est votre moyenne d'anglais ?\n"); - scanf("%f%*c", ¬es[2]); - printf("\n"); - printf("Quel est votre moyenne de spécialité ?\n"); - scanf("%f%*c", ¬es[3]); - printf("\n"); - c->numeroC = numeroC; - strcpy(c->nom, nom); /* Ajout des valeurs dans le candidat à insérer */ - strcpy(c->prenom, prenom); - c->notes[0] = notes[0]; - c->notes[1] = notes[1]; - c->notes[2] = notes[2]; - c->notes[3] = notes[3]; - tCand = reallocationCand(tCand, *tMax); /* Réallocation du tableau de candidats pour ajouter une place */ - for(i = *tMax; i > pos; i--) /* Décalage à droite des éléments du tableau à partir de la position d'insertion */ - { - tCand[i] = tCand[i - 1]; - } - tCand[pos] = c; /* Ajout du candidat dans le tableau */ - *tMax = *tMax + 1; /* Mise à jour de la taille physique du tableau */ - return tCand; -} - /*********************************** Fonctions de recherche *************************************************/ /************************************************************************************************************/ /************************************************************************************************************/ @@ -1479,94 +1735,87 @@ int rechercherCandidat(Candidat *tCand[], int tMax, int numeroC, int *trouve) /* FileCand filenouv(void) { - FileCand f; - f.t = NULL; - f.q = NULL; - return f; + FileCand f; + f.t = NULL; + f.q = NULL; + return f; } FileCand adjq(FileCand f, Candidat *c) { - MaillonCandidat *m; - m = (MaillonCandidat *)malloc(sizeof(MaillonCandidat)); - if(m == NULL) - { - printf("Erreur de malloc pour la file d'attente\n"); - exit(1); - } - m->c = c; - m->suiv = NULL; - if(videFile(f)) - { - f.t = m; - f.q = m; - return f; - } - f.q->suiv = m; - f.q = m; - return f; + MaillonCandidat *m; + m = (MaillonCandidat *)malloc(sizeof(MaillonCandidat)); + if(m == NULL) + { + printf("Erreur de malloc pour la file d'attente\n"); + exit(1); + } + m->c = c; + m->suiv = NULL; + if(videFile(f)) + { + f.t = m; + f.q = m; + return f; + } + f.q->suiv = m; + f.q = m; + return f; } FileCand supt(FileCand f) { - MaillonCandidat *aux; - if(videFile(f)) - { - printf("Opération interdite\n"); - exit(1); - } - if(f.t == f.q) - { - free(f.t); - return filenouv(); - } - aux = f.t; - f.t = f.t->suiv; - free(aux); - return f; + MaillonCandidat *aux; + if(videFile(f)) + { + printf("Opération interdite\n"); + exit(1); + } + if(f.t == f.q) + { + free(f.t); + return filenouv(); + } + aux = f.t; + f.t = f.t->suiv; + free(aux); + return f; } Candidat * tete(FileCand f) { - if(videFile(f)) - { - printf("File d'attente vide\n"); - exit(1); - } - return f.t->c; + if(videFile(f)) + { + printf("File d'attente vide\n"); + exit(1); + } + return f.t->c; } int longueurFile(FileCand f) { - int i = 0; - while(f.t != NULL) - { - f.t = f.t->suiv; - i++; - } - return i; + int i = 0; + while(f.t != NULL) + { + f.t = f.t->suiv; + i++; + } + return i; } int positionFileAttente(FileCand f, int numeroC) { - int i = 0; - while(f.t != NULL) - { + int i = 0; + while(f.t != NULL) + { if(numeroC == f.t->c->numeroC) { return i; } - f.t = f.t->suiv; - i++; - } - return i; -} - -bool videFile(FileCand f) -{ - if(f.t == NULL && f.q == NULL) - return true; - return false; + f.t = f.t->suiv; + i++; + } + return i; } void afficher(FileCand f) @@ -1574,13 +1823,22 @@ void afficher(FileCand f) printf("|----------------------------------------------------------------------------|\n"); printf("| Liste d'attente |\n"); printf("|----------------------------------------------------------------------------|\n"); - while(f.t != NULL) - { - printf("| %-4d | %-32s | %-32s |\n",f.t->c->numeroC, f.t->c->nom, f.t->c->prenom); + while(f.t != NULL) + { + printf("| %-4d | %-32s | %-32s |\n",f.t->c->numeroC, f.t->c->nom, f.t->c->prenom); printf("|----------------------------------------------------------------------------|\n"); - f.t = f.t->suiv; + f.t = f.t->suiv; + } + printf("\n"); +} + +bool videFile(FileCand f) +{ + if(f.t == NULL && f.q == NULL) + { + return true; } - printf("\n"); + return false; } /************************************* Fonctions de liste d'admission ***************************************/ @@ -1589,211 +1847,176 @@ void afficher(FileCand f) ListeCand listeCandNouv(void) /*Permet de créer un liste vide puis la retourne à la fonction appelante.*/ { - ListeCand lCand; - lCand = NULL; - return lCand; + 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; + 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; + 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 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; + 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 longueur(ListeCand lCand) /* Permet d'obtenir la longueur d'une liste passée en paramètre et retourne le nombre de maillons */ +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; + 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; + 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 */ + 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 */ } - - -/********************************** Fonction globale et menus ***********************************************/ -/************************************************************************************************************/ -/************************************************************************************************************/ - -void globale2(void) /* Permet de gérer l'exécution du programme */ +Candidat** remplirCandCl(Candidat *tCand[], Candidat *tempC[], int tMax, int nbCl) /* Permet d'insérer une ville dans le tableau tiut et renvoie un entier dépendant du déroulement de l'insertion */ { - int tMax, pos, trouve, i = 0, j, mini = i; - Candidat **tCand, c, **aux, *temp; /* Initialisation du tableau de candidats */ - tCand = chargementCandidats(&tMax); /* Remplissage du tableau par chargement */ - triCandidats(tCand, tMax); /* Tri du tableau */ - for(i = 0; i < tMax; i++) /* Tri du tableau choix pour chaque candidat */ - { - triChoix(tCand[i]->tChoix, tCand[i]->nombreChoix); - } - aux = tCand; - for(i = 0; i < tMax - 1; i++) + int i, j, k = 0; + for(i = 0; i < tMax; i++) /* On décale tous les éléments vers la droite depuis le dernier élément du tableau jusqu'à la position d'insertion passée en paramètre */ { - for(j = i + 1; j < tMax; j++) + for(j = 0; j < tCand[i]->nombreChoix; j++) { - if(tCand[j]->moyenne < tCand[i]->moyenne) + if(strcmp(tCand[i]->tChoix[j]->ville, "Clermont-Ferrand") == 0 && strcmp(tCand[i]->tChoix[j]->dep, "Informatique") == 0) { - mini = j; + tempC[k] = tCand[i]; + k = k + 1; } } - temp = tCand[i]; - tCand[i] = tCand[mini]; - tCand[mini] = temp; } - //menuCandidat(tCand, tMax); /* Appel du menu adapté au candidat */ - afficherCandChoix(aux, tMax); - sauvegarder(tCand, tMax); /* Sauvegarde du tableau de candidats */ + printf("Remplissage terminé\n"); + printf("Taille du tableau : %d\n",k); + afficherCandChoix(tempC, nbCl); + triTemp(tempC, nbCl); + return tempC; } -void menuCandidat2(Candidat *tCand[], int tMax) /* Fonction affichant un menu adapté pour un candidat */ +void triTemp(Candidat *tCand[], int nbCl) /* Fonction permettant de trier un tableau de candidats en effectuant un tri par échange */ { - int pos,trouve, saisie, i, numeroC; - system("clear"); - printf("Quel est votre numéro de candidat ?\nSaisie : "); /* Demande le numéro de candidat pour qu'il ne puisse accéder qu'à ses informations */ - scanf("%d%*c", &numeroC); - printf("\n"); - pos = rechercherCandidat(tCand, tMax, numeroC, &trouve); /* Vérifie que le numéro de candidat est correct */ - if(trouve == 0) + int mini; + while(nbCl > 1) { - printf("Erreur, vous n'êtes pas inscrit dans la base de données\n"); - return; + mini = plusGrandCandTemp(tCand, nbCl); /* Appel de la fonction plusGrand pour déterminer le plus grand élément du tableau */ + printf("Plus petit : %d\n", mini); + echangerCand(tCand, mini, nbCl - 1); /* Appel de la fonction échange pour placer le plus grnad élément du tableau en dernière position */ + nbCl = nbCl - 1; } - system("clear"); - printf("|------------------------------------------------------------|\n"); - printf("| Bienvenue %-32s |\n", tCand[pos]->prenom); - printf("|------------------------------------------------------------|\n"); - printf("| Que souhaitez-vous faire ? |\n"); - printf("|------------------------------------------------------------|\n"); - printf("| 1 Afficher vos choix |\n"); - printf("| 2 Ajouter un choix |\n"); - printf("| 3 Supprimer un choix |\n"); - printf("| 4 Mettre à jour votre décision concernant un établissement |\n"); - printf("| 9 Quitter |\n"); - printf("|------------------------------------------------------------|\n"); - printf("Saisie : "); - scanf("%d%*c", &saisie); - printf("\n"); - while(saisie != 9) /* Saisie contrôlée et affichage du menu tant que le candidat ne demande pas à quitter */ +} + +int plusGrandCandTemp(Candidat *tCand[], int nbCl) /* Fonction permettant de trouver le plus grand élément du tableau candidat en le parcourant et en*/ +{ /* comparant ses éléments. Elle renvoie ensuite l'indice du plus grand élément */ + int mini = 0, i; + for(i = 1; i < nbCl; i++) { - system("clear"); - if(saisie == 1) + if(tCand[i]->moyenne < tCand[mini]->moyenne) { - for(i = 0; i < tCand[pos]->nombreChoix; i++) - { - afficherChoix(tCand[pos]->tChoix[i]); - } + mini = i; } - if(saisie == 2) - { - tCand[pos]->tChoix = insererChoix(tCand[pos]->tChoix, &tCand[pos]->nombreChoix); - } - if(saisie == 3) - { - tCand[pos]->tChoix = supprimerChoix(tCand[pos]->tChoix, &tCand[pos]->nombreChoix); - } - if(saisie == 4) - { - miseAJourChoixCand(tCand[pos]->tChoix, tCand[pos]->nombreChoix); - } - clearpage(); - printf("|------------------------------------------------------------|\n"); - printf("| Que souhaitez-vous faire ? |\n"); - printf("|------------------------------------------------------------|\n"); - printf("| 1 Afficher vos choix |\n"); - printf("| 2 Ajouter un choix |\n"); - printf("| 3 Supprimer un choix |\n"); - printf("| 4 Mettre à jour votre décision concernant un établissement |\n"); - printf("| 9 Quitter |\n"); - printf("|------------------------------------------------------------|\n"); - printf("Saisie : "); - scanf("%d%*c", &saisie); - printf("\n"); } + return mini; +} + +void afficherCandidatsParCategorie(FileCand f,ListeCand l) +{ + int categ, i, pos, trouve; + printf("Quelle catégorie de candidats souhaitez-vous afficher ? (admis = 1 / attente = 2)\nSaisie : "); + scanf("%d%*c", &categ); + printf("\n"); + if(categ==1) + { + afficherListeCand(l); + } } + +void afficherListeCand(ListeCand l) +{ + while(l->suiv!=NULL) + { + afficherCandidat(l->c); + } +} \ No newline at end of file