diff --git a/header/sae.h b/header/sae.h index ca0ea12..fc1b9fc 100644 --- a/header/sae.h +++ b/header/sae.h @@ -138,10 +138,6 @@ lChoix creerCandidature(lChoix choixCandid, char ville[50], char departement[50] ListeDeptV2 configurationDeptV2( ListeDept ldept ); -void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept ); -ListeCandidats trierListeCandidats( ListeCandidats l ); -ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l ); -ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l ); // listeDeparements.c ListeDept ajouterEnTete(ListeDept ldept, char nomDept[], char resp[], int nbP); @@ -176,4 +172,17 @@ VilleIut * initialiseIut(void); VilleIut * lireIut (FILE * fichier); VilleIut ** chargeIutDon(char nomFichier[], int * nbIut, int * nbMax); VilleIut ** initialiseTabIut(void); -void tailleSupTabIut(VilleIut ** tIut, int *nbMax); \ No newline at end of file +void tailleSupTabIut(VilleIut ** tIut, int *nbMax); +void fusionIut(VilleIut ** tIut, int * nbIut); +int existe(char * nom, VilleIut ** tIut, int nbIut, int iDepart, int * indice); +void fusion(VilleIut ** tIut, int nbIut, int i, int j); +void supprimerIut(VilleIut ** tIut, int nbIut, int j); + + +// candidat.c + +Candidat *modifierCandidat(Candidat *c); +void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept ); +ListeCandidats trierListeCandidats( ListeCandidats l ); +ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l ); +ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l ); diff --git a/source/candidat.c b/source/candidat.c new file mode 100644 index 0000000..2932cf3 --- /dev/null +++ b/source/candidat.c @@ -0,0 +1,32 @@ +#include "../header/sae.h" + +/** + + @brief Modifie les informations d'un candidat + @param c Pointeur vers le candidat à modifier + @return Pointeur vers le candidat modifié +*/ +Candidat *modifierCandidat(Candidat *c) +{ + int choix; + printf("Que voulez vous modifier\n1-Le nom\n2-Le Prenom\n3-Les notes\n"); + scanf("%d", &choix); + switch (choix) + { + case 1: + printf("Nom actuel : %s\nVeuillez saisir le nouveau nom\n", c->nom); + fgets(c->nom, 50, stdin); + c->nom[strlen(c->nom) - 1] = '\0'; + break; + case 2: + printf("Prenom actuel : %s\nVeuillez saisir le nouveau prenom\n", c->prenom); + fgets(c->nom, 50, stdin); + c->prenom[strlen(c->prenom) - 1] = '\0'; + break; + case 3: + printf("Voici les notes actuels : %.2f %.2f %.2f %.2f\nVeuillez saisir les nouvelles notes(note1/note2/note3/note4)", c->notes[0], c->notes[1], c->notes[2], c->notes[3]); + scanf("%f/%f/%f/%f", &c->notes[0], &c->notes[1], &c->notes[2], &c->notes[3]); + break; + } + return c; +} \ No newline at end of file diff --git a/source/chargEtSauvFich.c b/source/chargEtSauvFich.c index 43712d3..f9ff82d 100644 --- a/source/chargEtSauvFich.c +++ b/source/chargEtSauvFich.c @@ -27,6 +27,8 @@ VilleIut ** chargeIutDon(char nomFichier[], int * nbIut, int * nbMax) *nbMax = 5; + + i = 0; while (!feof(fichier)) { @@ -42,6 +44,10 @@ VilleIut ** chargeIutDon(char nomFichier[], int * nbIut, int * nbMax) } *nbIut = i-1; + fclose(fichier); + + fusionIut(tIut, nbIut); + return tIut; } @@ -169,6 +175,7 @@ void lectureDep(ListeDept ldept, FILE * fichier) fscanf(fichier, "%s %d ", ldept->nomDept, &ldept->nbP); fgets(ldept->resp, 30, fichier); ldept->resp[strlen(ldept->resp)-1] = '\0'; + ldept->suiv = NULL; } /** @@ -178,117 +185,89 @@ void testCharge(void) { int nbIut, nbMax; VilleIut ** tIut = chargeIutDon("../donnees/iut.don", &nbIut, &nbMax); + fusionIut(tIut, &nbIut); for (int i = 0; i < nbIut; i++) { - printf("[ %s | %s | %d | %s ]\n", tIut[i]->nom, tIut[i]->lDept->nomDept, tIut[i]->lDept->nbP, tIut[i]->lDept->resp); + printf("\nVille : %s\n", tIut[i]->nom); + afficherListe(tIut[i]->lDept); } } - - -/*int chargIutDon(VilleIut *tVilleIut[], int nbMax, char nomFich[]) +/** + * @brief Fusionne la liste de département de toutes les villes du même nom de tIut + * + * @param tIut Tableau de pointeur de VilleIut + * @param nbIut [Taille Logique] + */ +void fusionIut(VilleIut ** tIut, int *nbIut) { - FILE *flot; - int i=0, nbP, trouve, indice; - char nom[30], nomDept[30], resp[30]; + int indice; - flot = fopen(nomFich, "r"); - if(flot==NULL) + for (int i = 0; i < *nbIut; i++) { - printf("Probleme d'ouverture du fichier\n"); - exit(1); - } - fscanf(flot, "%s", nom); - lireDep(flot, nomDept, &nbP, resp); - while(!feof(flot)) - { - if(i==nbMax) - { - printf("Tableau plein\n"); - return -1; - } - indice = appartientIut(tVilleIut, i, nom, &trouve); - if(trouve==0) + if(existe(tIut[i]->nom, tIut, *nbIut, i, &indice)) { - tVilleIut[i] = (VilleIut*)malloc(sizeof(VilleIut)); - if(tVilleIut[i]==NULL) - { - printf("Probleme malloc\n"); - fclose(flot); - exit(1); - } - strcpy(tVilleIut[i]->nom, nom); - tVilleIut[i]->lDept = listenouv(); - ajouterDept(tVilleIut[i]->lDept, nomDept, resp, nbP); - i = i + 1; + fusion(tIut, *nbIut, i, indice); + (*nbIut)--; + i--; } - if(trouve==1) - tVilleIut[indice]->lDept = ajouterDept(tVilleIut[indice]->lDept, nomDept, resp, nbP); - fscanf(flot, "%s", nom); - lireDep(flot, nomDept, &nbP, resp); } - return i; -} - -void lireDep(FILE *flot, char nomDept[], int *nbP, char resp[]) -{ - fscanf(flot,"%s%d\t", nomDept, nbP); - fgets(resp, 30, flot); - - #ifdef _WIN32 - resp[strlen(resp) - 1] = '\0'; - #endif - - #ifdef __linux__ - resp[strlen(resp) - 2] = '\0'; - #endif } -int appartientIut(VilleIut *tVilleIut[], int nb, char nom[], int *trouve) +/** + * @brief Verifie l'existance d'une VilleIut dans le tableau de pointeur de VilleIut + * + * @param nom [CHAINE DE CARACTERES] + * @param tIut Tableau de pointeur de VilleIut + * @param nbIut [Taille Logique] + * @param iDepart Indice à partir du quel rechercher + * @param indice Indice de la valeur si trouvée + * @return int 1 -> Trouvé | 0 -> Inexistante + */ +int existe(char * nom, VilleIut ** tIut, int nbIut, int iDepart, int * indice) { - int i = 0; - - while(i < nb) + for (int i = iDepart+1; i < nbIut; i++) { - if(strcmp(tVilleIut[i]->nom, nom) == 0) + if (strcmp(nom, tIut[i]->nom) == 0) { - *trouve = 1; - return i; + *indice = i; + return 1; } - i = i + 1; } - *trouve = 0; - return i; + + return 0; } -void sauvegarderFichierIutDon(VilleIut *tVilleIut[], int nbVille, char nomFich[]) +/** + * @brief Fusionne la liste de département de deux VilleIut du même nom + * + * @param tIut Tableau de pointeur de VilleIut + * @param nbIut [Taille Logique] + * @param i Indice liste d'accueil + * @param j Indice ville à supprimer + */ +void fusion(VilleIut ** tIut, int nbIut, int i, int j) { - FILE *flot; - int i=0; + ListeDept aux; + aux = tIut[i]->lDept; + tIut[i]->lDept = tIut[j]->lDept; + tIut[i]->lDept->suiv = aux; - flot = fopen(nomFich, "w"); - if(flot==NULL) - { - printf("Probleme lors de l'ouverture du fichier\n"); - exit(1); - } - while(ilDept != NULL) - { - printf("%s %s %d %s", tVilleIut[i]->nom, tVilleIut[i]->lDept->nomDept, tVilleIut[i]->lDept->nbP, tVilleIut[i]->lDept->resp); - fprintf(flot, "%s %s %d %s", tVilleIut[i]->nom, tVilleIut[i]->lDept->nomDept, tVilleIut[i]->lDept->nbP, tVilleIut[i]->lDept->resp); - tVilleIut[i]->lDept = tVilleIut[i]->lDept->suiv; - } - i = i + 1; - } - fclose(flot); + supprimerIut(tIut, nbIut, j); } -*/ - -/* - -*/ \ No newline at end of file +/** + * @brief Supprime une ville du tableau de pointeur de VilleIut + * + * @param tIut Tableau de pointeur de VilleIut + * @param nbIut [Taille Logique] + * @param j Indice ville à supprimer + */ +void supprimerIut(VilleIut ** tIut, int nbIut, int j) +{ + for (int i = j ; i < nbIut-1 ; i++) + { + tIut[i] = tIut[i+1]; + } +} \ No newline at end of file diff --git a/source/main.c b/source/main.c index 08240ef..44200a6 100644 --- a/source/main.c +++ b/source/main.c @@ -10,7 +10,7 @@ int main(void) // #endif //guillaume(); //testCharge(); - //Globale(); + Globale(); //testJean(); return 0; diff --git a/source/sae.c b/source/sae.c index 6ef521c..4973d53 100644 --- a/source/sae.c +++ b/source/sae.c @@ -14,21 +14,25 @@ */ void Globale(void) { - printf(" \n ---> lancement de la fonction globale.... \n\n"); + //printf(" \n ---> lancement de la fonction globale.... \n\n"); Log * tLog; - VilleIut *tIut[50] ; + VilleIut ** tIut; int nbVilles; int nbLog; + int nbIut, nbIutMax; //Chargement des fichiers tLog = chargementLog("../donnees/log.don", &nbLog); + tIut = chargeIutDon("../donnees/iut.don", &nbIut, &nbIutMax); + //nbVilles = chargIutDon(tIut, 50, "../donnees/iut.don"); //Appel du menu visiteur - menuVisiteur(tLog, nbLog, tIut, nbVilles); + menuVisiteur(tLog, nbLog, tIut, nbIut); //Sauvegarde dans les fichiers + } /** @@ -77,10 +81,8 @@ Log * chargementLog(char * nomFichier, int * nbLog) } fscanf(fichier, "%s %s %s", tLog[i].utilisateur, tLog[i].mdp, tLog[i].status); - printf("%s\n", tLog[i].status); i++; } - *nbLog = i; return tLog; } @@ -99,7 +101,7 @@ void test(VilleIut * tIut[], int nbVilles) * choixMenuVisiteur. Selon le choix de l'utilisateur, la fonction appelle la fonction correspondante * ou met fin à l'exécution de la fonction. */ -void menuVisiteur(Log * tLog, int nbLog, VilleIut *tIut[], int nbVilles) +void menuVisiteur(Log * tLog, int nbLog, VilleIut *tIut[], int nbIut) //void menuVisiteur(VilleIut *villeIut, int nbVilles) { int choix; @@ -114,15 +116,14 @@ void menuVisiteur(Log * tLog, int nbLog, VilleIut *tIut[], int nbVilles) switch(choix) { case 1: - //test(tIut, nbVilles); - afficheVillesIUT(tIut, nbVilles); - //printf("Affiche les Villes contenant des IUT (En attente d'une fonction de chargement fonctionnelle)\n"); + afficheVillesIUT(tIut, nbIut); break; case 2: printf("Affiche le nombre de place dans un departement (En attente de Guillaume)\n"); break; case 3 : - afficherDeptIutDonne(tIut, nbVilles); + printf("Afficher departement d'un Iut\n"); + //afficherDeptIutDonne(tIut, nbIut); break; case 4 : printf("Affiche les IUT possedant un departement donne (En attente de Jean)\n"); @@ -581,8 +582,12 @@ void afficheVillesIUT(VilleIut *tiut[], int nbVilles) { // Affichage du nom de la ville printf(" -> %s\n", tiut[i]-> nom); - } - printf(" \n\n\n"); + } + + printf("\nAppuyez sur entree pour continuer...\n"); + scanf("%*c"); + + clean } /** @@ -786,6 +791,44 @@ int creerCandidat(Candidat *tCand[], int nbCandidats) return nbCandidats + 1; } +/** + * @brief Supprime un choix de la liste de choix d'un candidat + * + * @param lchoix la liste de choix à modifier + * @param nbchoix le nombre de choix dans la liste de choix + * + * @return la liste avec le choix en moins + */ +lChoix supprimerCandidature( lChoix l, int * nbchoix) +{ + if ( l == NULL ) + { + printf(" \n --> Le candidat ne possede aucun choix...\n\n"); + return l; + } + + printf("\n Voici les choix du candidat : \n"); + printf( " -----------------------------\n\n"); + int rep = 0, c = 0; + + for( int i = 0; i < *nbchoix; i ++ ) + { + printf(" %d.) Ville : %10s ; Departement : %10s \n",i + 1, l -> ville, l -> departement); + } + + printf(" \n\n --> Quel choix supprimer ? : "); + scanf("%d%*c", &rep); + + while ( c != rep - 1 ) + { + l = l -> suiv; + c = c + 1; + } + + l = supprimerEnTeteC( l ); + *nbchoix = *nbchoix - 1; + return l; +} /** * @brief Permet de créer une candidature à un candidat @@ -869,108 +912,4 @@ ListeDeptV2 configurationDeptV2( ListeDept ldept ) } return lDeptV2; -} - -/* -================================================ - Partie 4 -================================================ -*/ - -/** - * @brief Affiche une liste de candidats après l'avoir triée par ordre alphabétique - * - * @param lcand liste de candidats à trier et afficher - * @param type type de liste à afficher ( en attente ou admis ) - * @param nomDept nom du departement dont est issu la liste - */ -void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept ) -{ - lcand = trierListeCandidats( lcand ); - - printf( " Liste des candidats %s du departement %10s \n -------------------------------------------------------\n\n", type, nomDept); - - while ( lcand != NULL) - { - printf(" | Nom : %10s | Prenom : %10s | Numero : %8s |\n", - lcand -> candidat.nom, lcand -> candidat.prenom, lcand -> candidat.numero); - - lcand = lcand -> suiv; - } -} -/** - * @brief Trie par ordre alphabétique les candidats d'une liste - * - * @param l liste de candidats à trier. - * - * @return La liste triée - */ -ListeCandidats trierListeCandidats( ListeCandidats l ) -{ - ListeCandidats nvL; - - while ( l != NULL ) - { - nvL = insertionCroissanteCand( nvL, l ); - l = l -> suiv; - } - - return nvL; -} - -/** - * @brief Permet d'insérer un nouveau Maillon de candidats dans la liste par ordre alphabétique - * @param l la liste dont est issu le maillon à insérer - * @param nvL la nouvelle liste où est inséré le maillon - * - * @return La nouvelle liste avec le maillon au bon endroit - */ -ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l ) -{ - if ( l == NULL) - { - nvL = insertionTeteCand( nvL, l ); - return nvL; - } - - if ( strcmp( l -> candidat.nom, nvL -> candidat.nom ) < 0 ) - { - nvL = insertionTeteCand( nvL, l ); - return nvL; - } - - if ( strcmp( l -> candidat.nom, nvL -> candidat.nom ) == 0 ) - { - if ( strcmp( l -> candidat.prenom, nvL -> candidat.prenom ) < 0 ) - { - nvL = insertionTeteCand( nvL, l ); - return nvL; - } - } - - nvL -> suiv = insertionCroissanteCand( nvL -> suiv, l ); - return nvL; -} - -/** - * @brief Insère en tête de la nouvelle liste un nouveau maillon - * @param l liste d'où est issu le nouveau maillon à intégrer - * @param nvL Liste où est insérer le nouveau Maillon - * @return La nouvelle liste avec le maillon au bon endroit - */ -ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l ) -{ - MaillonCandidat * m = ( MaillonCandidat * ) malloc ( sizeof( MaillonCandidat )); - if ( m == NULL ) - { - printf("\n -> Erreur allocation memoire...\n"); - exit(1); - } - - m -> candidat = l -> candidat; - m -> suiv = nvL; - nvL = m; - free( l ); - - return nvL; } \ No newline at end of file