From 6fb3fb2b92fb6295223148936cb49fab638c3268 Mon Sep 17 00:00:00 2001 From: johnny Date: Tue, 10 Jan 2023 11:28:58 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20fonctions=20de=20r=C3=A9allocatio?= =?UTF-8?q?n=20dans=20la=20partie=202,=20ajout=20de=20la=20sauvegarde=20pa?= =?UTF-8?q?rtie=202=20et=20aussi=20des=20affichages,=20tout=20fonctionne?= =?UTF-8?q?=20mais=20les=20r=C3=A9allocations=20ne=20sont=20pas=20encore?= =?UTF-8?q?=20test=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- J2sae.c | 87 +++++++++++++++++++++++++++++++------- J2sae.h | 3 ++ J2test.h | 0 Jsae.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- Jsae.h | 8 ++-- 5 files changed, 202 insertions(+), 22 deletions(-) delete mode 100755 J2test.h diff --git a/J2sae.c b/J2sae.c index c50301e..4d13d76 100755 --- a/J2sae.c +++ b/J2sae.c @@ -22,20 +22,17 @@ Candidat ** chargementCandidats(int *tMax) fclose(flot); exit(1); } - printf("Début du chargement\n"); for(i = 0; i < *tMax; i++) { c = lireCandidat(flot); tCand[i] = c; } - printf("Fin du chargement\n"); fclose(flot); return tCand; } Candidat * lireCandidat(FILE *flot) { - printf("Lecture d'un candidat\n"); Candidat *c; Choix choix; int i = 0; @@ -53,8 +50,6 @@ Candidat * lireCandidat(FILE *flot) fscanf(flot, "%f%f%f%f%*c", &c->notes[0], &c->notes[1], &c->notes[2], &c->notes[3]); fscanf(flot, "%d%*c", &c->nombreChoix); c->tchoix = (Choix **)malloc(sizeof(Choix *) * c->nombreChoix); - afficherCandidat(c); - printf("Nombre de choix : %d\n", c->nombreChoix); while(i < c->nombreChoix) { c->tchoix[i] = lireChoix(flot); @@ -65,7 +60,6 @@ Candidat * lireCandidat(FILE *flot) Choix * lireChoix(FILE *flot) { - printf("Lecture d'un choix\n"); Choix *c; c = (Choix *)malloc(sizeof(Choix)); if(c == NULL) @@ -78,32 +72,93 @@ Choix * lireChoix(FILE *flot) fgets(c->dep, 31, flot); c->dep[strlen(c->dep) - 1] = '\0'; fscanf(flot, "%d%d%*c", &c->decisionResp, &c->decisionCand); - afficherChoix(c); return c; } + +void sauvegarder(Candidat *tCand[], int tMax) +{ + FILE *flot; + int i, j; + flot = fopen("CandidatsSauv.don", "w"); + if(flot == NULL) + { + printf("Erreur de l'ouverture du fichier lors de l'enregistrement\n"); + fclose(flot); + exit(1); + } + fprintf(flot, "%d\n", tMax); + for(i = 0; i < tMax; i++) + { + fprintf(flot, "%d\n%s\n%s\n%d\n", tCand[i]->numeroC, tCand[i]->nom, tCand[i]->prenom, tCand[i]->nombreChoix); + for(j = 0; j < tCand[i]->nombreChoix; j++) + { + fprintf(flot, "%s\n%s\n%d\n%d\n", tCand[i]->tchoix[j]->ville, tCand[i]->tchoix[j]->dep, tCand[i]->tchoix[j]->decisionResp, tCand[i]->tchoix[j]->decisionCand); + } + } + fclose(flot); + return; +} + void globale(void) { + int tMax; Candidat **tCandidats, c; - int tMax, i, j; tCandidats = chargementCandidats(&tMax); + sauvegarder(tCandidats, tMax); + afficherCandChoix(tCandidats, tMax); +} + +void afficherChoix(Choix *c) +{ + printf("|_____________________________________________________________________________|\n"); + printf("| %-32s | %-32s | %1d | %1d |\n", c->ville, c->dep, c->decisionResp, c->decisionCand); + printf("|-----------------------------------------------------------------------------|\n"); +} + +void afficherCandidat(Candidat *c) +{ + printf("|------------------------------------------------------------------------------------------------------------|\n"); + printf("| %-4d | %-32s | %-32s | %2.2f | %2.2f | %2.2f | %2.2f |\n", c->numeroC, c->nom, c->prenom, c->notes[0], c->notes[1], c->notes[2], c->notes[3]); + printf("|------------------------------------------------------------------------------------------------------------|\n"); +} + +void afficherCandChoix(Candidat *tCand[],int tMax) +{ + int i, j; for(i = 0; i < tMax; i++) { - afficherCandidat(tCandidats[i]); - for(j = 0; j < tCandidats[i]->nombreChoix; j++) + printf("______________________________________________________________________________________________________________\n"); + printf("| Candidat |\n"); + afficherCandidat(tCand[i]); + printf("\n"); + printf("_______________________________________________________________________________\n"); + printf("| Choix |\n"); + for(j = 0; j < tCand[i]->nombreChoix; j++) { - afficherChoix(tCandidats[i]->tchoix[j]); + afficherChoix(tCand[i]->tchoix[j]); } } } -void afficherChoix(Choix *c) +Candidat ** reallocation(Candidat *tCand[], int tMax) { - printf("%s\t%s\t%d\t%d\n", c->ville, c->dep, c->decisionResp, c->decisionCand); + Candidat **aux; + aux = (Candidat **)realloc(tCand, sizeof(Candidat *) * tMax + 1); + if(aux == NULL) + { + printf("Erreur lors de la réallocation du tableau\n") + } + return aux; } -void afficherCandidat(Candidat *c) +Choix ** reallocation(Choix *tChoix[], int nbChoix) { - printf("Afficher candidat\n"); - printf("%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n", c->numeroC, c->nom, c->prenom, c->notes[0], c->notes[1], c->notes[2], c->notes[3]); + Choix **aux; + aux = (Choix **)realloc(tChoix, sizeof(Choix *) * nbChoix + 1); + if(aux == NULL) + { + printf("Erreur lors de la réallocation du tableau\n") + } + return aux; } \ No newline at end of file diff --git a/J2sae.h b/J2sae.h index 2df3f5f..962d14c 100755 --- a/J2sae.h +++ b/J2sae.h @@ -47,4 +47,7 @@ Candidat * lireCandidat(FILE *flot); Choix * lireChoix(FILE *flot); void afficherCandidat(Candidat *c); void afficherChoix(Choix *c); +void afficherCandChoix(Candidat *tCand[],int tMax); +Candidat ** reallocation(Candidat *tCand[], int tMax); +Choix ** reallocation(Choix *tChoix[], int nbChoix); void globale(void); \ No newline at end of file diff --git a/J2test.h b/J2test.h deleted file mode 100755 index e69de29..0000000 diff --git a/Jsae.c b/Jsae.c index 83c243c..6183bf8 100644 --- a/Jsae.c +++ b/Jsae.c @@ -390,6 +390,126 @@ void retirerDept(VilleIUT *tiut[], int tLog) /* Permet de gérer la suppression +//############################################################### fonction mise à jour ############################################################### +//#################################################################################################################################################### +//#################################################################################################################################################### + +void miseAJourNomDept(Departement *d,ListeDept l) +{ + int trouve; + char nomDept[31],choix; + system("clear"); + afficherDep(*d); + while(choix!='o' && choix!='O') //Boucle pour de la saisie controlée + { + printf("\nQuel est le nouveau nom du département?\n"); //Demande le nouveau nom du département + fgets(nomDept,31,stdin); //Affecte la saisie au tableau "dept" + nomDept[strlen(nomDept)-1]='\0'; + rechercherDept(l,nomDept,&trouve); //Recherche si le nouveau nom de département saisie n'est pas déjà présent dans la liste des département de la ville + if(trouve==1) //Message informatif si le nouveau nom est déjà présent + { + printf("Important : Nom de département déjà présent dans l'IUT.\n"); + } + printf("Êtes-vous sûr de remplacer le nom du département par %s?(o/n)\t",nomDept); //Demande confirmation + scanf("%c%*c",&choix); //affecte la saisie à la variable "choix" + } + strcpy(d->dept,nomDept); //Applique la modification + afficherDep(*d); //Affiche la modification + clearpage(); +} + +void miseAJourResp(Departement *d) +{ + char resp[31],choix='n'; + system("clear"); + afficherDep(*d); + while(choix!='o' && choix!='O') //Boucle pour de la saisie controlée + { + printf("\nQuel est le nouveau nom du responsable ?\t");//Demande le nouveau nom du responsable + fgets(resp,31,stdin); + resp[strlen(resp)-1]='\0'; + printf("Êtes-vous sûr de remplacer le nom du responsable par %s?(o/n)\t",resp);//Demande confirmation + scanf("%c%*c",&choix); + } + strcpy(d->respAd,resp);//Applique la modification + afficherDep(*d);//Affiche la modification + clearpage(); +} + +void miseAJourPlaces(Departement *d) +{ + int places; + char choix='n'; + system("clear"); + afficherDep(*d); + while(choix!='o' && choix!='O')//Boucle pour de la saisie controlée + { + printf("Quel est le nouveau nombre de place ?\t");//Demande le nouveau nombre de place + scanf("%d%*c",&places); + printf("Êtes-vous sûr de passer les places en première année de %d à %d ?(o/n)\t",d->nbP,places);//Demande confirmation + scanf("%c",&choix); + } + d->nbP=places;//Applique la modification + afficherDep(*d);//Affiche la modification + clearpage(); +} + +void miseAJourGlobale(VilleIUT *tiut[], int tLog) +{ + int trouve,pos,choix=0; //Déclaration de variables | initialisation de "choix" pour rentrer dans la boucle + char ville[31],dept[31]; + MaillonDept *m; + Departement *d; + system("clear"); + afficherTIUT(tiut,tLog); //affichage des différentes villes + printf("Dans quelle ville voulez-vous faire des mises à jour?\t"); //demande sur quelle ville faire une mise à jour + scanf("%s",ville); //affecte la saisie au tableau "ville" + pos=rechercheIUT(tiut,tLog,ville,&trouve); //recherche de la saisie dans le tableau des villes et associe la position dans le tableau à la variable "pos" + if(trouve!=1) //message d'erreur si la ville n'est pas trouvée + { + printf("\n\nCette ville n'existe pas\n"); + clearpage(); + return; + } + system("clear"); + afficherVilleDep(*tiut[pos]); //Affiche les différents départements de la ville saisie + printf("Quel département de %s voulez-vous modifier?\t",ville); //demande sur quel département faire une mise à jour + scanf("%s%*c",dept); //affecte la saisie au tableau "dept" + m=rechercherDept(tiut[pos]->lDept,dept,&trouve); //recherche du département saisie et affecte l'adresse du maillon correspondant au pointeur "m" + if(trouve!=1) // message d'erreur si le département n'apparait pas dans la liste + { + printf("\n\nCe département n'existe pas dans cette ville\n"); + clearpage(); + return; + } + d=&(m->d); //affecte au pointeur de département "d" l'adresse de la structure "Departement" du maillon qui nous intéresse + while(choix!=9) // boucle pour le menu des mises à jour + { + system("clear"); + afficherDep(m->d); // affichage du département et de ses caractéristiques + printf("\n\n"); + printf("###################################### Menu des mises à jour ######################################\n"); + printf("\n\t1.Mise à jour du nom du département\n\t2.Mise à jour des places du département\n\t3.Mise à jour du responsable du département\n\t9.Quitter\n\n"); // affiche les modifications qu'on peut faire sur le département + printf("\tSaisie:\t"); + scanf("%d%*c",&choix); // associe la saisie à la variable choix + if(choix==1) // comparaisons de la saisie pour savoir ce que l'utilisateur veut faire et appels des fonctions correspondantes + { + miseAJourNomDept(&(m->d),tiut[pos]->lDept); + } + if(choix==2) + { + miseAJourPlaces(&(m->d)); + } + if(choix==3) + { + miseAJourResp(&(m->d)); + } + } + afficherDep(m->d); //affichages du département après les potentielles modifications + clearpage(); +} + + /*********************************************** Fonctions de login, menus, globale et clearpage **********************************************/ /**********************************************************************************************************************************************/ /**********************************************************************************************************************************************/ @@ -450,7 +570,7 @@ int login(void) /* Affiche un menu de connexion pour ensuite adapter l'affichage 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 */ { - int select = 0, pos; + int select, pos; int trouve; char ville[31], choix; ListeDept l; @@ -499,10 +619,10 @@ void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax) /* Affiche un menu de choi { retirerDept(tiut, *tLog); } - /*if(select == 5) + if(select == 5) { miseAJourGlobale(tiut, tLog); - }*/ + } if(select == 6) { printf("Quel est le nom de la ville à insérer ?\nSaisie : "); /* Demande le nom de la ville à insérer */ diff --git a/Jsae.h b/Jsae.h index 99c33fe..db27d37 100644 --- a/Jsae.h +++ b/Jsae.h @@ -36,6 +36,7 @@ void afficherDep(Departement d); void afficherVille(VilleIUT v); void afficherTIUT(VilleIUT *tiut[], int tLog); void afficherVilleDep(VilleIUT v); +void afficheDeptDesIUT(VilleIUT *tiut[], int tLog); /* Fonctions de Listes */ @@ -64,9 +65,10 @@ int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve); /* Fonctions de mise à jour */ -void miseAJourNomDept(VilleIUT *tiut[], int tLog); -void miseAJourResp(VilleIUT *tiut[], int tLog); -void miseAJourPlaces(VilleIUT *tiut[], int tLog); +void miseAJourGlobale(VilleIUT *tiut[], int tLog); +void miseAJourNomDept(Departement *d,ListeDept l); +void miseAJourResp(Departement *d); +void miseAJourPlaces(Departement *d); /* Fonctions de gestion d'affichage, menus et globale */