From 0bc63869eeb5b3708dba91dd660541ee8cddedab Mon Sep 17 00:00:00 2001 From: Kyllian Chabanon Date: Sun, 1 Jan 2023 17:10:39 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20fonction=20de=20modification?= =?UTF-8?q?=20du=20responsable=20d'un=20d=C3=A9partement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Partie_1/administrateur.c | 38 ++++++++++++++++++++++++++++++++---- Partie_1/informationsIUT.txt | 8 ++++---- Partie_1/menus.c | 8 ++++---- Partie_1/partie1.c | 1 + Partie_1/partie1.h | 3 ++- Partie_1/structures.c | 18 +++++++++++++++++ Partie_1/structures.h | 4 +++- Partie_1/test.c | 3 ++- 8 files changed, 68 insertions(+), 15 deletions(-) diff --git a/Partie_1/administrateur.c b/Partie_1/administrateur.c index 3c243d2..aebf3eb 100644 --- a/Partie_1/administrateur.c +++ b/Partie_1/administrateur.c @@ -18,7 +18,7 @@ void modificationNbPDept(VilleIUT *tiut[], int nb) posDept = rechercheDept(tiut[posIUT]->ldept, deptModif, &trouve); if (trouve == false) { - printf("Cet département n'existe pas dans cet IUT. Veuillez réessayer.\n"); + printf("Ce département n'existe pas dans cet IUT. Veuillez réessayer.\n"); return; } printf("Il y a actuellement %d places dans ce département. Entrez le nouveau nombre de places :\n> ", getNbP(tiut[posIUT]->ldept, posDept)); @@ -49,11 +49,12 @@ void creationDept(VilleIUT *tiut[], int nb) return; } printf("Entrez le nombre de places dans le département :\n> "); - scanf("%s%*c", &nbP); + scanf("%d%*c", &nbP); printf("Entrez le nom du responsable :\n> "); fgets(nomResp, 30, stdin); + nomResp[strlen(nomResp) - 1] = '\0'; tiut[posIUT]->ldept = inserer(tiut[posIUT]->ldept, nomDept, nbP, nomResp); - printf("Vous avez créé le département \"%s\", avec %d places. Son représentant est %s.\n", nomDept, nbP, nomResp); + printf("Vous avez créé le département \"%s\", avec %d places. Son responsable est %s.\n", nomDept, nbP, nomResp); } int suppressionDept(VilleIUT *tiut[], int nb) @@ -74,7 +75,7 @@ int suppressionDept(VilleIUT *tiut[], int nb) posDept = rechercheDept(tiut[posIUT]->ldept, nomDept, &trouve); if (trouve == false) { - printf("Cet département n'existe pas dans cet IUT. Veuillez réessayer.\n"); + printf("Ce département n'existe pas dans cet IUT. Veuillez réessayer.\n"); return nb; } printf("Voulez-vous vraiment supprimer le département %s de l'IUT %s ? (o/N)\n> ", nomDept, iut); @@ -100,4 +101,33 @@ int suppressionDept(VilleIUT *tiut[], int nb) printf("Vous avez annulé la suppression du département.\n"); } return nb; +} + +void modificationRespDept(VilleIUT *tiut[], int nb) +{ + char iutModif[30], deptModif[30], nouvResp[30]; + int posIUT, posDept; + bool trouve; + printf("Dans quel IUT se situe le département que vous voulez modifier ?\n> "); + scanf("%s", iutModif); + posIUT = rechercheVille(tiut, nb, iutModif, &trouve); + if (trouve == false) + { + printf("Cet IUT n'existe pas. Veuillez réessayer.\n"); + return; + } + printf("Quel est le département dont vous voulez modifier le responsable ?\n> "); + scanf("%s%*c", deptModif); + posDept = rechercheDept(tiut[posIUT]->ldept, deptModif, &trouve); + if (trouve == false) + { + printf("Ce département n'existe pas dans cet IUT. Veuillez réessayer.\n"); + return; + } + + printf("Le responsable de ce département est actuellement %s. Entrez le nouveau responsable :\n> ", getResp(tiut[posIUT]->ldept, posDept)); + fgets(nouvResp, 30, stdin); + nouvResp[strlen(nouvResp) - 1] = '\0'; + setResp(tiut[posIUT]->ldept, posDept, nouvResp); + printf("Le nouveau responsable est %s.\n", getResp(tiut[posIUT]->ldept, posDept)); } \ No newline at end of file diff --git a/Partie_1/informationsIUT.txt b/Partie_1/informationsIUT.txt index 40f5a09..8b61438 100755 --- a/Partie_1/informationsIUT.txt +++ b/Partie_1/informationsIUT.txt @@ -1,4 +1,4 @@ -Grenoble Informatique 112 Dupont Jean -Clermont-Ferrand Informatique 136 Simon Carine -Aurillac Bio-Informatique 56 Ayoub Milaki -Clermont-Ferrand Biologie 120 Coralie Elebone \ No newline at end of file +Grenoble Informatique 112 Dupont Jean +Clermont-Ferrand Informatique 136 Simon Carine +Aurillac Bio-Informatique 56 Ayoub Milaki +Clermont-Ferrand Biologie 120 Coralie Elebone \ No newline at end of file diff --git a/Partie_1/menus.c b/Partie_1/menus.c index 933956a..62c4391 100644 --- a/Partie_1/menus.c +++ b/Partie_1/menus.c @@ -87,9 +87,9 @@ void menuAdministrateur(void) printf("\t1 - Modifier le nombre de places dans un département\n"); printf("\t2 - Créer un département dans un IUT\n"); printf("\t3 - Supprimer un département d'un IUT\n"); - printf("\t4 - Lancer la phase de candidature\n"); - printf("\t5 - Stopper la phase de candidature\n"); - printf("\t6 - Modifier le responsable d'un département\n"); + printf("\t4 - Modifier le responsable d'un département\n"); + printf("\t5 - Lancer la phase de candidature\n"); + printf("\t6 - Stopper la phase de candidature\n"); printf("\t9 - Quitter\n"); printf("\nEntrez votre choix :\n> "); scanf("%d", &choix); @@ -109,7 +109,7 @@ void menuAdministrateur(void) break; case 4: c = true; - // + // modificationRespDept(tiut, nb); break; case 5: c = true; diff --git a/Partie_1/partie1.c b/Partie_1/partie1.c index 3f742aa..f3123cc 100755 --- a/Partie_1/partie1.c +++ b/Partie_1/partie1.c @@ -27,6 +27,7 @@ int chargementVillesIUT(VilleIUT *tiut[]) { fscanf(file, "%s%s%d", ville, dept, &nbP); fgets(resp, 30, file); + resp[strlen(resp) -1] = '\0'; insertPos = rechercheVille(tiut, i, ville, &trouve); if (trouve == 0) diff --git a/Partie_1/partie1.h b/Partie_1/partie1.h index 8b815c3..994856d 100755 --- a/Partie_1/partie1.h +++ b/Partie_1/partie1.h @@ -15,4 +15,5 @@ void affichageDeptIUT(VilleIUT *tiut[], int nb); /* Administrateur */ void modificationNbPDept(VilleIUT *tiut[], int nb); void creationDept(VilleIUT *tiut[], int nb); -int suppressionDept(VilleIUT *tiut[], int nb); \ No newline at end of file +int suppressionDept(VilleIUT *tiut[], int nb); +void modificationRespDept(VilleIUT *tiut[], int nb); \ No newline at end of file diff --git a/Partie_1/structures.c b/Partie_1/structures.c index a36bfda..369c872 100644 --- a/Partie_1/structures.c +++ b/Partie_1/structures.c @@ -136,4 +136,22 @@ ListeDept supprimer(ListeDept l, char departement[]) } l->suiv = supprimer(l->suiv, departement); return l; +} + +char* getResp(ListeDept l, int pos) +{ + for (int i = 0; i < pos; i++) + { + l = l->suiv; + } + return l->resp; +} + +void setResp(ListeDept l, int pos, char valeur[]) +{ + for (int i = 0; i < pos; i++) + { + l = l->suiv; + } + strcpy(l->resp, valeur); } \ No newline at end of file diff --git a/Partie_1/structures.h b/Partie_1/structures.h index a669509..6eb1223 100644 --- a/Partie_1/structures.h +++ b/Partie_1/structures.h @@ -27,4 +27,6 @@ ListeDept supprimerEnTete(ListeDept l); ListeDept supprimer(ListeDept l, char departement[]); int getNbP(ListeDept l, int pos); -void setNbP(ListeDept l, int pos, int valeur); \ No newline at end of file +void setNbP(ListeDept l, int pos, int valeur); +char* getResp(ListeDept l, int pos); +void setResp(ListeDept l, int pos, char valeur[]); \ No newline at end of file diff --git a/Partie_1/test.c b/Partie_1/test.c index e3d25b6..01c0033 100755 --- a/Partie_1/test.c +++ b/Partie_1/test.c @@ -9,7 +9,8 @@ int main(void) affichageDeptIUT(tiut, nbVilles); // modificationNbPDept(tiut, nbVilles); // creationDept(tiut, nbVilles); - nbVilles = suppressionDept(tiut, nbVilles); + // nbVilles = suppressionDept(tiut, nbVilles); + modificationRespDept(tiut, nbVilles); affichageDeptIUT(tiut, nbVilles); return 0; }