From 42b91953e417df7f57a9242d7b2820491177640d Mon Sep 17 00:00:00 2001 From: johnny Date: Fri, 6 Jan 2023 14:50:08 +0100 Subject: [PATCH] modification de mes fichiers --- Jsae.c | 437 ++++++++++++++++++++++++++++++++++++++++++++++++++------- Jsae.h | 2 +- 2 files changed, 389 insertions(+), 50 deletions(-) diff --git a/Jsae.c b/Jsae.c index d844eca..f6a8d93 100644 --- a/Jsae.c +++ b/Jsae.c @@ -1,5 +1,393 @@ #include "Jsae.h" +ListeDept listeDeptNouv(void) +{ + ListeDept lDept; + lDept = NULL; + return lDept; +} + +ListeDept insererEntete(ListeDept lDept,Departement d) +{ + MaillonDept *m; + m = (MaillonDept *)malloc(sizeof(MaillonDept)); + if(m == NULL) + { + printf("Problème d'allocation mémoire lors de l'insertion\n"); + exit(1); + } + m->d = d; + m->suiv = lDept; + return m; +} + +ListeDept insererDept(ListeDept lDept, Departement d) +{ + if(lDept == NULL) + return insererEntete(lDept,d); + if(strcmp(d.dept, lDept->d.dept) < 0) + return insererEntete(lDept,d); + if(strcmp(d.dept,lDept->d.dept) == 0) + printf("Département déjà présent dans cet IUT\n"); + return lDept; + lDept->suiv = insererDept(lDept->suiv,d); + return lDept; +} + +ListeDept supprimerEntete(ListeDept lDept) +{ + ListeDept aux; + if(lDept == NULL) + { + printf("Opération interdite\n"); + exit(1); + } + aux = lDept; + lDept = lDept->suiv; + free(aux); + return lDept; +} + +ListeDept supprimerDept(ListeDept lDept, char *dep) +{ + if(lDept == NULL) + return lDept; + if(strcmp(dep, lDept->d.dept) < 0) + return lDept; + if(strcmp(dep,lDept->d.dept) == 0) + return supprimerEntete(lDept); + lDept->suiv = supprimerDept(lDept->suiv,dep); + return lDept; +} + +int longueur(ListeDept lDept) +{ + int compt = 0; + while(lDept != NULL) + { + compt = compt + 1; + lDept = lDept->suiv; + } + return compt; +} + +bool vide(ListeDept lDept) +{ + if(lDept == NULL) + return true; + return false; +} + + +/*int tete(Liste l){ + if(l==NULL){ + printf("Opération interdite\n"); + exit(1) + } + return l->v; +}*/ + +ListeDept rechercherDept(ListeDept lDept, char dept[], int *trouve) +{ + if(vide(lDept)) + { + *trouve = 0; + return lDept; + } + if(strcmp(dept, lDept->d.dept) < 0) + { + trouve = 0; + return lDept; + } + if(strcmp(dept,lDept->d.dept) == 0) + { + *trouve = 1; + return lDept; + } + return rechercherDept(lDept->suiv, dept, trouve); +} + +void miseAJourPlaces(VilleIUT *tiut[], int tLog) +{ + int trouve, pos, places; + char ville[31], dept[31], choix; + ListeDept l; + printf("Dans quelle ville se situe le département concerné ?\nSaisie : "); + scanf("%s%*c", ville); + printf("\n"); + pos = rechercheIUT(tiut, tLog, ville, &trouve); + while(trouve == 0) + { + printf("Cette ville n'existe pas, veuillez re-saisir : "); + scanf("%s%*c", ville); + printf("\n"); + pos = rechercheIUT(tiut, tLog, ville, &trouve); + } + l = tiut[pos]->lDept; + printf("Quel département souhaitez-vous mettre à jour ?\nSaisie : "); + scanf("%s%*c", dept); + printf("\n"); + l = rechercherDept(l, dept, &trouve); + while(trouve == 0) + { + printf("Ce département n'existe pas, veuillez-resaisir : "); + scanf("%s%*c", dept); + printf("\n"); + l = rechercherDept(l, dept, &trouve); + } + printf("Vous avez sélectionné le département %s dans la ville de %s.\nSouhaitez-vous continuez ? (O/N)\nSaisie : ", dept, ville); + scanf("%c%*c", &choix); + printf("\n"); + if(choix == 'N') + { + return; + } + printf("Il y a actuellement %d places.\nQuel est le nouveau nombre de places ?\nSaisie : ", l->d.nbP); + scanf("%d%*c", &places); + printf("\nVous avez saisie %d places, veuillez confirmez (O/N)\nSaisie : ", places); + scanf("%c%*c", &choix); + printf("\n"); + if(choix == 'O') + { + l->d.nbP = places; + printf("La mise à jour a bien été effectuée.\n"); + } + return; +} + +void afficherPlace(Departement d) +{ + printf("\nPour ce département il y a %d places en 1ère année \n\n",d.nbP); +} + +void creerDept(VilleIUT *tiut[],int tLog) +{ + Departement d; + int pos, trouve; + char ville[31]; + printf("Dans quelle ville souhaitez-vous créer un nouveau département ?\nSaisie : "); + scanf("%s%*c", ville); + printf("\n"); + pos = rechercheIUT(tiut, tLog, ville, &trouve); + while(trouve == 0) + { + printf("Cette ville n'existe pas, veuillez re-saisir : "); + scanf("%s%*c", ville); + printf("\n"); + pos = rechercheIUT(tiut, tLog, ville, &trouve); + } + printf("Quel est le nom du département à insérer ?\nSaisie : "); + scanf("%s%*c", d.dept); + rechercherDept(tiut[pos]->lDept, d.dept, &trouve); + if(trouve == 1) + { + printf("Erreur, le département %s existe déjà dans cet IUT\n", d.dept); + return; + } + printf("Combien de place y a-t-il pour dans ce département ?\nSaisie : "); + scanf("%d%*c", &d.nbP); + printf("\n"); + printf("Quel est le nom du responsable du département ?\nSaisie : "); + fgets(d.respAd, 31, stdin); + d.respAd[strlen(d.respAd) - 1] = '\0'; + afficherDep(d); + printf("pos : %d\n", pos); + tiut[pos]->lDept = insererDept(tiut[pos]->lDept, d); + afficherVilleDep(*tiut[pos]); + return; +} + + +void retirerDept(VilleIUT *tiut[], int tLog) +{ + int trouve, pos; + char ville[31], dep[31]; + printf("Dans quelle ville souhaitez-vous supprimer un département ?\nSaisie : "); + scanf("%s%*c", ville); + printf("\n"); + pos = rechercheIUT(tiut, tLog, ville, &trouve); + while(trouve == 0) + { + printf("Cette ville n'existe pas, veuillez re-saisir : "); + scanf("%s%*c", ville); + printf("\n"); + pos = rechercheIUT(tiut, tLog, ville, &trouve); + } + printf("Quel est le nom du département à supprimer ?\nSaisie : "); + scanf("%s%*c", dep); + rechercherDept(tiut[pos]->lDept, dep, &trouve); + if(trouve == 0) + { + printf("Erreur, le département %s n'existe pas dans cet IUT\n", dep); + return; + } + tiut[pos]->lDept = supprimerDept(tiut[pos]->lDept, dep); + return; +} + +int login(void) +{ + int i = 3; + char id, mdp[31] = "mettez20svp", mdpatrouve[31]; + system("clear"); + printf("\t################################ Bienvenue! ################################\nSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur ? (U/A)\nSaisie : "); + scanf("%c%*c",&id); + if(id == 'q') + { + return -1; + } + while(id != 'A' && id != 'a' && id != 'U' && id != 'u') + { + system("clear"); + printf("\t#################### Mauvaise saisie ('q' pour quitter) ####################\nSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\nSaisie : "); + scanf("%c%*c",&id); + if(id == 'q') + { + return -1; + } + } + if(id == 'A' || id == 'a') + { + while(i != 0) + { + printf("\n\nMot de passe : "); + system("stty -echo"); + fgets(mdpatrouve, 31, stdin); + mdpatrouve[strlen(mdpatrouve) - 1] = '\0'; + printf("\n"); + if(strcmp(mdpatrouve, mdp) == 0 ) + { + system("stty echo"); + system("clear"); + return 1; + } + else + { + i--; + printf("Mot de passe incorrect, il vous reste %d chances\n",i); + } + system("stty echo"); + } + return -1; + } + else + { + system("clear"); + return 0; + } +} + + +void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax) +{ + int select = 0, pos; + int trouve; + char ville[31]; + ListeDept l; + printf("_______________________________________________________\n"); + printf("| MENU ADMIN |\n"); + printf("|-----------------------------------------------------|\n"); + printf("| 1 Afficher les villes possédant un IUT |\n"); + printf("| 2 Afficher les départements d'un IUT |\n"); + printf("| 3 Créer un nouveau département |\n"); + printf("| 4 Supprimer un département |\n"); + printf("| 5 Modifier le nombre de places dans un département |\n"); + printf("| 6 Modifier l'intitulé d'un département |\n"); + printf("| 7 Modifer le nom du responsable d'un département |\n"); + printf("| 8 Lancer/Arrêter la phase de candidature |\n"); + printf("| 9 Quitter |\n"); + printf("|-----------------------------------------------------|\n\n"); + printf("Saisie : "); + scanf("%d%*c",&select); + while(select != 9) + { + system("clear"); + if(select == 1) + { + afficherTIUT(tiut, *tLog); + } + if(select == 2) + { + printf("Pour quelle ville souhaitez-vous afficher les départements ?\nSaisie : "); + scanf("%s%*c", ville); + printf("\n"); + pos = rechercheIUT(tiut, *tLog, ville, &trouve); + while(trouve == 0) + { + printf("Cette ville n'existe pas, veuillez re-sasisir : "); + scanf("%s%*c", ville); + pos = rechercheIUT(tiut, *tLog, ville , &trouve); + printf("\n"); + } + afficherVilleDep(*tiut[pos]); + } + if(select == 3) + { + creerDept(tiut, *tLog); + } + if(select == 4) + { + retirerDept(tiut, *tLog); + } + if(select == 5) + { + miseAJourPlaces(tiut, *tLog); + } + /*if(select == 6) + { + miseAJourNomDept(tiut, *tLog); + } + if(select == 7) + { + miseAJourResp(tiut, *tLog); + }*/ + printf("_______________________________________________________\n"); + printf("| MENU ADMIN |\n"); + printf("|-----------------------------------------------------|\n"); + printf("| 1 Afficher les villes possédant un IUT |\n"); + printf("| 2 Afficher les départements d'un IUT |\n"); + printf("| 3 Créer un nouveau département |\n"); + printf("| 4 Supprimer un département |\n"); + printf("| 5 Modifier le nombre de places dans un département |\n"); + printf("| 6 Modifier l'intitulé d'un département |\n"); + printf("| 7 Modifer le nom du responsable d'un département |\n"); + printf("| 8 Lancer/Arrêter la phase de candidature |\n"); + printf("| 9 Quitter |\n"); + printf("|-----------------------------------------------------|\n\n"); + printf("Saisie : "); + scanf("%d%*c",&select); + } +} + +void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax) +{ + int select = 0; + while(select != 9) + { + system("clear"); + printf("_____________________________________________________\n"); + printf("| AFFICHAGE CANDIDAT |\n\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 Rechercher un département dans les IUT |\n"); + printf("| 9 Quitter |\n"); + printf("|---------------------------------------------------|"); + scanf("%d%*c",&select); + } +} + + + +void clearpage(void) +{ + char entre; + printf("\nappuyé sur la touche [ENTREE] pour continuer"); + scanf("%*c%c", &entre); + system("clear"); +} + int chargement(VilleIUT *tiut[],int tMax) { FILE *flot; @@ -118,7 +506,6 @@ int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve) int inf,sup,t; inf = 0; sup = tLog - 1; - printf("Ville recherchée : %s\n", ville); while(inf <= sup) { t = (inf + sup) / 2; @@ -169,52 +556,4 @@ void globale(void) } retour = login(); } -} - -void miseAJourPlaces(VilleIUT *tiut[], int tLog) -{ - int trouve, pos, places; - char ville[31], dept[31], choix; - ListeDept l; - printf("Dans quelle ville se situe le département concerné ?\nSaisie : "); - scanf("%s%*c", ville); - printf("\n"); - pos = rechercheIUT(tiut, tLog, ville, &trouve); - while(trouve == 0) - { - printf("Cette ville n'existe pas, veuillez re-saisir : "); - scanf("%s%*c", ville); - printf("\n"); - pos = rechercheIUT(tiut, tLog, ville, &trouve); - } - l = tiut[pos]->lDept; - printf("Quel département souhaitez-vous mettre à jour ?\nSaisie : "); - scanf("%s%*c", dept); - printf("\n"); - l = rechercherDept(l, dept, &trouve); - while(trouve == 0) - { - printf("Ce département n'existe pas, veuillez-resaisir : "); - scanf("%s%*c", dept); - printf("\n"); - l = rechercherDept(l, dept, &trouve); - } - printf("Vous avez sélectionné le département %s dans la ville de %s.\nSouhaitez-vous continuez ? (O/N)\nSaisie : ", dept, ville); - scanf("%c%*c", &choix); - printf("\n"); - if(choix == 'N') - { - return; - } - printf("Il y a actuellement %d places.\nQuel est le nouveau nombre de places ?\nSaisie : ", l->d.nbP); - scanf("%d%*c", &places); - printf("\nVous avez saisie %d places, veuillez confirmez (O/N)\nSaisie : ", places); - scanf("%c%*c", &choix); - printf("\n"); - if(choix == 'O') - { - l->d.nbP = places; - printf("La mise à jour a bien été effectuée.\n"); - } - return; } \ No newline at end of file diff --git a/Jsae.h b/Jsae.h index f4f80d8..53b54f4 100644 --- a/Jsae.h +++ b/Jsae.h @@ -42,7 +42,7 @@ ListeDept listeDeptNouv(void); ListeDept insererEntete(ListeDept lDept,Departement d); ListeDept insererDept(ListeDept lDept, Departement d); ListeDept supprimerEntete(ListeDept lDept); -ListeDept supprimerDept(ListeDept lDept, Departement d); +ListeDept supprimerDept(ListeDept lDept, char *dep); bool vide(ListeDept lDept); int longueur(ListeDept lDept);