From 832d2c8fb9dcb44ae43957f88009ccf2f2abd324 Mon Sep 17 00:00:00 2001 From: allaurent13 Date: Thu, 12 Jan 2023 22:32:03 +0000 Subject: [PATCH] =?UTF-8?q?Toutes=20les=20fonction=20de=20la=20Partie=202?= =?UTF-8?q?=20sont=20faite=20->=20probl=C3=A8me=20:=20Sauvegarde=20|=20fon?= =?UTF-8?q?ction=20de=20modif=20(fonction=20interne)|?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Candidres.txt | 0 SAE.c | 386 ++++++++++++++++++++++++++++++++++++++++++-------- SAE.h | 48 ++++++- 3 files changed, 375 insertions(+), 59 deletions(-) create mode 100644 Candidres.txt diff --git a/Candidres.txt b/Candidres.txt new file mode 100644 index 0000000..e69de29 diff --git a/SAE.c b/SAE.c index 062adb3..aae4da2 100644 --- a/SAE.c +++ b/SAE.c @@ -1,5 +1,4 @@ #include "SAE.h" -//#include "SAEl.h" bool motdepasseVerif(void) { @@ -47,7 +46,7 @@ bool verifSelection(void) while(1) { printf("Voulez-vous continué la sélection (oui|non) : "); - scanf("%s",choix); + scanf("%s%*c",choix); if (strcmp(choix,"oui")==0) return true; if (strcmp(choix,"non")==0) @@ -84,7 +83,8 @@ int menuUtilisateurAffiche(void) printf("4 - Consultation du nombre de places pour un Département dans un IUT\n"); printf("5 - Consultation des départements dans un IUT\n"); printf("6 - Consultation de tout les IUT ayant un département choisi\n"); - printf("7 - Consultation de toute les informations des Département par IUT"); + printf("7 - Consultation de toute les informations des Département par IUT\n"); + printf("8 - Mode Candidat\n"); printf("\n\n9 - Connexion mode Administrateur\n"); printf("\n\n10 - Quitter\n"); printf("####################################################\n"); @@ -112,7 +112,7 @@ int menuAdminAffiche(void) return choix; } -void gestionMenu(VilleIUT **tiut, int nbEle) +void gestionMenu(VilleIUT **tiut, int nbEle, Candidat **tcandid, int *nbCandid, int *taillePCandid) { int choix; while(1) @@ -148,13 +148,25 @@ void gestionMenu(VilleIUT **tiut, int nbEle) AffichageGlobalIUT(tiut, nbEle); clearpage(); break; + case 8: + gestionCandid(tiut, nbEle, tcandid, nbCandid, taillePCandid); + break; case 9: choix = gestionMenuAdmin(tiut, nbEle); if (choix == -1) - if (verifQuit()) return; + if (verifQuit()) + { + SauvegarderIUT(tiut, nbEle); + SauvegardeCandid(tcandid, *nbCandid); + return; + } break; case 10: - if (verifQuit()) return; + if (verifQuit()) + { + SauvegarderIUT(tiut, nbEle); + return; + } break; } @@ -201,26 +213,17 @@ int gestionMenuAdmin(VilleIUT **tiut, int nbEle) void global(void) { - /*int tailleL, i; + int tailleL, i, tphys, nb; VilleIUT** tab; + Candidat **tabC; char nomFich[20]; strcpy(nomFich,"iut.txt"); printf("charg\n"); tab = chargementVille(nomFich,30,&tailleL); - printf("\n"); - gestionMenu(tab, tailleL); - SauvegardeIUT(tab, tailleL) - */ - int tphys, nb; - Candidat **tab; - tab = chargmentCandid("candidature.txt", &tphys, &nb); + tabC = chargmentCandid("candidature.txt", &tphys, &nb); system("clear"); - afficherCandid(tab, nb); - supprimerCandid(tab, &nb); - afficherCandid(tab, nb); - creationCandid(tab, &nb, &tphys); - afficherCandid(tab, nb); - + printf("\n"); + gestionMenu(tab, tailleL, tabC, &nb, &tphys); } void AffichageVille(VilleIUT **tiut, int nbEle) @@ -575,7 +578,7 @@ void clearpage(void) { char entre; printf("\nappuyé sur la touche [ENTREE] pour continuer"); - scanf("%*c%c", &entre); + scanf("%*c%c%*c", &entre); system("clear"); } @@ -665,6 +668,8 @@ void videTabDept(ChoixDept **tDept, int tailleP) { ChoixDept *aux; int i; + if (tailleP == 0) + free(tDept); for (i=tailleP - 1; i >= 0; i--) { aux = tDept[i]; @@ -706,6 +711,7 @@ void afficherCandid(Candidat **tab, int nbEle) { printf("%d %s %s |%.1f %.1f %.1f %.1f|\n", tab[i]->id, tab[i]->nom, tab[i]->prenom, tab[i]->note[0], tab[i]->note[1], tab[i]->note[2], tab[i]->note[3]); afficherCandidIUT(tab[i]->idCandIUT); + printf("\n"); } printf("\n"); } @@ -955,16 +961,16 @@ Candidat **reallocTCandid(Candidat **tab, int *tailleP) return aux; } -void creationCandid(Candidat **tab, int *nbEle, int *tailleP) +void creationCandid(VilleIUT **tiut, int nbIUT, Candidat **tcandid, int *nbCandid, int *taillePCandid) { char nom[30], prenom[30], choix[4]; - int idAdd, i; + int idAdd, i, iCandid; Candidat c; - if (*nbEle == *tailleP) - tab = reallocTCandid(tab, tailleP); + if (*nbCandid == *taillePCandid) + tcandid = reallocTCandid(tcandid, taillePCandid); while(1) { - idAdd = tab[*nbEle - 1]->id + 1; + idAdd = tcandid[*nbCandid - 1]->id + 1; printf("Votre prénom : "); scanf("%s%*c", prenom); printf("Votre nom : "); @@ -984,24 +990,23 @@ void creationCandid(Candidat **tab, int *nbEle, int *tailleP) strcpy(c.nom, nom); strcpy(c.prenom, prenom); c.idCandIUT = ListeCandidvide(); - *(tab[*nbEle]) = c; - *nbEle = *nbEle + 1; + *nbCandid = *nbCandid + 1; + *(tcandid[*nbCandid - 1]) = c; printf("création terminer \n"); break; } if (strcmp(choix, "non")==0) - break; + return; } while(1) { printf("voulez vous faire votre choix maintenant (oui|non) : "); scanf("%s", choix); if (strcmp(choix, "oui")==0) - { - printf("en construction\n"); - } + modifCandid(tcandid, *nbCandid, tiut, 0, c.id); if (strcmp(choix, "non")==0) break; + return; } if(!verifSelection()) break; @@ -1028,42 +1033,62 @@ int menuCandid(void) return choix; } +void afficher1Candid(Candidat **tab, int nbCandid) +{ + int i, trouve, id; + printf("identifiant : "); + scanf("%d", &id); + i = rechCandid(tab, nbCandid, id, &trouve); + if(trouve == 0) + { + printf("Identifiant absent de la base de donnée\n"); + return; + } + printf("%d %s %s |%.1f %.1f %.1f %.1f|\n", tab[i]->id, tab[i]->nom, tab[i]->prenom, tab[i]->note[0], tab[i]->note[1], tab[i]->note[2], tab[i]->note[3]); + afficherCandidIUT(tab[i]->idCandIUT); + printf("\n"); +} + void gestionCandid(VilleIUT **tiut, int nbIUT, Candidat **tcandid, int *nbCandid, int *taillePCandid) { - int choix; + int choix, id, pos, trouve; while(1) { choix = menuCandid(); system("clear"); switch(choix) { case 1: - creationCandid(tcandid, nbCandid, taillePCandid); + creationCandid(tiut, nbIUT ,tcandid, nbCandid, taillePCandid); system("clear"); break; case 2: - suppressionCandid(tab, nbCandid); + supprimerCandid(tcandid, nbCandid); system("clear"); break; case 3: - modifCandid(tiut, nbEle); + printf("Votre identifiant : "); + scanf("%d", &id); + pos = rechCandid(tcandid, *nbCandid, id, &trouve); + if (trouve == 0) + printf("identifiant pas présent dans la base de donnée !\n"); + else + modifCandid(tcandid, *nbCandid, tiut, nbIUT, id); system("clear"); break; case 4: - AffichageNbplaceDeptVille(tiut, nbEle); + afficher1Candid(tcandid, *nbCandid); clearpage(); break; case 5: - //modif candid; + afficherCandid(tcandid, *nbCandid); clearpage(); break; case 9: - choix = gestionMenuAdmin(tiut, nbEle); + choix = gestionMenuAdmin(tiut, nbIUT); if (choix == -1) - if (verifQuit()) return; - break; + return; case 10: - if (verifQuit()) return; - break; + return; } } @@ -1145,14 +1170,14 @@ void ajouterDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i { printf("Dans quel Département voulez-vous candidater : "); scanf("%s%*c", departement); - pos = recherchecandidDept(tiut[pos]->idDept, departement) - if (trouve == 0) + if (rechercheDept(tiut[pos]->idDept, departement) == NULL) printf("Erreur ! Département non référencé\n"); - if (trouve == 1) + if (rechercheDept(tiut[pos]->idDept, departement) != NULL) { - aux = recherchecandidIUT(tcandid[iCandid]->idCandIUT, ville) == NULL) + aux = recherchecandidIUT(tcandid[iCandid]->idCandIUT, ville); + if (aux == NULL) { - tDept = (ChoixDept **)malloc(sizeof(ChoixDept *)*(nbDept + 5)); + tDept = (ChoixDept **)malloc(sizeof(ChoixDept *)*10); if(tDept == NULL) { printf("Pb malloc candidIUt\n"); @@ -1163,23 +1188,23 @@ void ajouterDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i } else { - irech = recherchecandidDept(tcandid[iCandid]->idCandIUT->tabDept, tcandid[iCandid]->nbChoix, departement, &trouve); + irech = recherchecandidDept(aux->tabDept, aux->nbChoix, departement, &trouve); if (trouve == 0) { - *(tcandid[iCandid]->idCandIUT->tabDept[tcandid[iCandid]->idCandIUT->nbChoix]) = RempTabCandid(departement, 0, 0); - tcandid[iCandid]->idCandIUT->nbChoix = tcandid[iCandid]->idCandIUT->nbChoix + 1; + *(aux->tabDept[aux->nbChoix]) = RempTabCandid(departement, 0, 0); + aux->nbChoix = aux->nbChoix + 1; printf("Candidature validée !\n"); } else printf("vous avez déjà postuler au département %s de cette %s", departement, ville); } } - printf("saisie Département\n") + printf("saisie Département\n"); if(verifSelection()) - break + break; } } - printf("Saisie IUT\n") + printf("Saisie IUT\n"); if(!verifSelection()) break; } @@ -1200,17 +1225,30 @@ void supprimerCandidDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int else while(1) { - printf("Dans quel Département voulez-vous supprimer votre candidature\n"); + printf("Dans quel Département voulez-vous supprimer votre candidature : "); scanf("%s%*c", departement); pos = recherchecandidDept(aux->tabDept, aux->nbChoix, departement, &trouve); + if (trouve == 0) + printf("Aucun voeux formuler dans ce département de l'IUT\n"); + else + if(!confirmationSup()) + printf("Annulation confirmé !\n"); + else + free(aux->tabDept[pos]); + aux->nbChoix = aux->nbChoix - 1; + if (aux->nbChoix == 0) + suppressionCandid(tcandid[iCandid]->idCandIUT, ville, aux->tabDept, aux->nbChoix); + printf("voeux supprimmé !\n"); + break; } + break; } } void modifCandid(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, int iCandid) { - int choix, iCandid; + int choix; while(1) { choix = menuGestionCandid(); @@ -1224,4 +1262,240 @@ void modifCandid(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i return; } } +} + +ListeDept creerListeDept(void) +{ + return NULL; +} + +VilleIUT **chargementVille(char *nomFich, int tphys, int *tailleL) +{ + int i = 0, nbDept; + FILE *flot; + VilleIUT **tabV; + tabV = (VilleIUT **)malloc(sizeof(VilleIUT *) * tphys); + if (tabV == NULL) + { + printf("Erreur malloc tab!\n"); + exit(1); + } + flot = fopen(nomFich, "r"); + if (flot == NULL) + { + printf("Problème ouverture du fichier !\n"); + exit(1); + } + *tailleL = 0; + tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT)); + if (tabV[*tailleL] == NULL) + { + printf("Erreur malloc ville!\n"); + fclose(flot); + exit(1); + } + *(tabV[*tailleL]) = lireVille(flot); + while (!feof(flot)) + { + fscanf(flot, "%d", &nbDept); + printf("Nombre de dep : %d\n", nbDept); + tabV[*tailleL]->idDept = creerListeDept(); + while (i < nbDept) + { + tabV[*tailleL]->idDept = traiterDept(tabV[*tailleL]->idDept, flot); + i += 1; + } + i = 0; + *tailleL += 1; + tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT)); + if (tabV[*tailleL] == NULL) + { + printf("Erreur malloc ville!\n"); + fclose(flot); + exit(1); + } + *(tabV[*tailleL]) = lireVille(flot); + } + if (tailleL == 0) + printf("Fichier vide !\n"); + fclose(flot); + return tabV; +} + +VilleIUT lireVille(FILE *flot) +{ + VilleIUT v; + fgets(v.ville, 30, flot); + v.ville[strlen(v.ville) - 1] = '\0'; + return v; +} + +ListeDept traiterDept(ListeDept l, FILE *flot) +{ + char nom[30], dept[30]; + int nbPlaces; + fscanf(flot, "%s %d", dept, &nbPlaces); + fgets(nom, 30, flot); + nom[strlen(nom) - 1] = '\0'; + printf("Nom du départ : %s\n", dept); + l = insererDept(l, dept, nom, nbPlaces); + return l; +} + +ListeDept ajouterEnTeteDept(ListeDept l, char *dept, char *nom, int nbP) +{ + MaillonDept *nouv; + nouv = (MaillonDept *)malloc(sizeof(MaillonDept)); + if (nouv == NULL) + { + printf("Erreur malloc !\n"); + exit(1); + } + strcpy(nouv->departement, dept); + nouv->nbPers = nbP; + strcpy(nouv->responsable, nom); + nouv->suiv = l; + return nouv; +} + +void affichageListeDept(ListeDept l) // itératif +{ + while (l != NULL) + { + printf("- %s :\t|%d places\t\t%s|\n", l->departement, l->nbPers, l->responsable); + l = l->suiv; + } +} + +ListeDept insererDept(ListeDept l, char *dept, char *nom, int nbP) +{ // récursif + if (l == NULL) + return ajouterEnTeteDept(l, dept, nom, nbP); + if ((strcmp(dept, l->departement)) < 0) + return ajouterEnTeteDept(l, dept, nom, nbP); + if ((strcmp(dept, l->departement)) == 0) + return l; + l->suiv = insererDept(l->suiv, dept, nom, nbP); + return l; +} + +ListeDept supprimerEnTêteDept(ListeDept l) +{ + MaillonDept *aux; + if (l == NULL) + { + printf("suppression interdite\n"); + exit(1); + } + if (l->suiv == NULL) + return NULL; + aux = l; + l = l->suiv; + free(aux); + return l; +} + +ListeDept supprimerDept(ListeDept l, char *code) +{ + if (l == NULL) + return l; + if ((strcmp(code, l->departement)) < 0) + return l; + if ((strcmp(code, l->departement)) == 0) + return supprimerEnTêteDept(l); + l->suiv = supprimerDept(l->suiv, code); + return l; +} + +ListeDept rechercheDept(ListeDept l, char code[]) +{ + if (l == NULL) + return NULL; + if ((strcmp(code, l->departement)) < 0) + return NULL; + if (strcmp(code, l->departement) == 0) + return l; + return rechercheDept(l->suiv, code); +} + +void SauvegarderIUT(VilleIUT **tabV, int tailleL) +{ + int i, nbDept; + FILE *flot; + flot = fopen("res.txt", "w"); + for (i = 0; i < tailleL; i++) + { + fprintf(flot, "%s\n", tabV[i]->ville); + nbDept = longueurListe(tabV[i]->idDept); + fprintf(flot, "%d\n", nbDept); + SauvegarderListe(tabV[i]->idDept, flot); + free(tabV[i]); + } + fclose(flot); +} + +void SauvegarderListe(ListeDept l, FILE *flot) +{ + MaillonDept *tmp; + while (l->suiv != NULL) + { + tmp = l; + fprintf(flot, "%s %d %s\n", l->departement, l->nbPers, l->responsable); + l = l->suiv; + free(tmp); + } + fprintf(flot, "%s %d %s\n", l->departement, l->nbPers, l->responsable); + free(l); +} + +int longueurListe(ListeDept l) +{ + int cpt = 0; + while (l != NULL) + { + cpt += 1; + l = l->suiv; + } + return cpt; +} + + +void SauvegardeCandid(Candidat **tabC, int nbCandid) +{ + int i,j, nbIUT; + FILE *flot; + flot = fopen("Candidres.txt", "w"); + fprintf(flot,"%d\n", nbCandid); + for (i = 0; i > nbCandid; i++) + { + fprintf(flot, "%s %s\n", tabC[i]->prenom, tabC[i]->nom); + fprintf(flot, "%.1f %.1f %.1f %.1f\n", tabC[i]->note[0], tabC[i]->note[1], tabC[i]->note[2], tabC[i]->note[3]); + nbIUT = longueur(tabC[i]->idCandIUT); + fprintf(flot,"%d\n",nbIUT); + SauvegarderCandidIUT(tabC[i]->idCandIUT, flot); + free(tabC[i]); + } + fclose(flot); +} + +void SauvegarderCandidIUT(ListeCandid l, FILE *flot) +{ + MaillonCandid *tmp; + while(l != NULL) + { + tmp = l; + fprintf(flot, "%s\n%s", l->iutCandid, l->nbChoix); + SauvegardeCandidDept(l->tabDept, l->nbChoix, flot); + l = l->suiv; + free(tmp); + } + free(l); +} + +void SauvegardeCandidDept(ChoixDept **tDept, int nbDept, FILE *flot) +{ + int i; + for(i = 0; i < nbDept; i++) + fprintf(flot, "%s\n%d\n%d", tDept[i]->departement, tDept[i]->decisionDept, tDept[i]->decisionCandid); + } \ No newline at end of file diff --git a/SAE.h b/SAE.h index e2800d4..0520e40 100644 --- a/SAE.h +++ b/SAE.h @@ -60,7 +60,7 @@ int menuUtilisateurAffiche(void); int menuAdminAffiche(void); -void gestionMenu(VilleIUT **tiut, int nbEle); +void gestionMenu(VilleIUT **tiut, int nbEle, Candidat **tcandid, int *nbCandid, int *taillePCandid); int gestionMenuAdmin(VilleIUT **tiut, int nbEle); @@ -180,10 +180,52 @@ void supprimerCandid(Candidat **tab, int *nbEle); Candidat **reallocTCandid(Candidat **tab, int *tailleP); -void creationCandid(Candidat **tab, int *nbEle, int *tailleP); +void creationCandid(VilleIUT **tiut, int nbIUT, Candidat **tcandid, int *nbCandid, int *taillePCandid); int menuCandid(void); +void afficher1Candid(Candidat **tab, int nbCandid); + void gestionCandid(VilleIUT **tiut, int nbIUT, Candidat **tcandid, int *nbCandid, int *taillePCandid); -int menuGestionCandid(void); \ No newline at end of file +int menuGestionCandid(void); + +ListeCandid recherchecandidIUT(ListeCandid l, char code[]); + +int recherchecandidDept(ChoixDept **tab,int nbEle, char code[],int *trouve); + +ChoixDept RempTabCandid(char dept[],int deciCandid ,int deciDept); + +void ajouterDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, int iCandid); + +void supprimerCandidDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, int iCandid); + +void modifCandid(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, int iCandid); + +ListeDept creerListeDept(void); + +ListeDept ajouterEnTeteDept(ListeDept l, char* dept, char* nom, int nbP); + +ListeDept insererDept(ListeDept l, char *dept, char *nom, int nbP); + +void affichageListeDept(ListeDept l); + +VilleIUT lireVille(FILE *flot); + +ListeDept traiterDept(ListeDept l, FILE *flot); + +VilleIUT** chargementVille(char* nomFich, int tphys, int* tailleL); + +ListeDept supprimerDept(ListeDept l, char *code); + +int longueurListe(ListeDept l); + +void SauvegarderIUT(VilleIUT** tabV, int tailleL); + +void SauvegarderListe(ListeDept l, FILE* flot); + +void SauvegardeCandid(Candidat **tabC, int nbCandid); + +void SauvegarderCandidIUT(ListeCandid l, FILE *flot); + +void SauvegardeCandidDept(ChoixDept **tDept, int nbDept, FILE *flot); \ No newline at end of file