#include #include #include #include "sae1-02.h" // général // f enregistrement // Partie 1 /* void affichageVilleIUT() { printf("%s\t%s\t%d\t%s") } int rechercheVille() { } VilleIUT lire(FILE * fe) { VilleIUT v; fscanf(fe, "%s", V.ville); fscanf(fe, "%s", v.Idept->departement); fscanf(fe, "%d", v.Idept->nbplace); fgets(v.Idept->responsable, 31, fe); v.Idept->responsable[strlen(v.Idept->responsable)-1] = '\0'; return v; } */ // Partie 2 //chargement ====================================================================================================================================================================== Listchoixdept listvide(void){return NULL;} Listchoixdept lireCarte(FILE *fe, int nbchoix){ if(nbchoix==0){return NULL;} Maillonchoix* cc; cc = (Maillonchoix*)malloc(sizeof(Maillonchoix)); fscanf(fe, "%s %s %d %d", cc->Ville, cc->dep, &cc->decision, &cc->validation); cc->suivant = lireCarte(fe, nbchoix-1); return cc; } listetuinfo lireEtu(FILE *fe){ listetuinfo b; int i; fscanf(fe, "%d %s %s %d %d %d %d %d", &b.numeroetu, b.nometu, b.prenometu, &b.notes[0], &b.notes[1], &b.notes[2], &b.notes[3], &b.nbchoix); return b; } int chargeretudiant(char nomFich[], listetuinfo *tetu[], int tmax){ int i=0, nbetu; listetuinfo a; Listchoixdept b; FILE *fe; fe = fopen( nomFich, "r"); if(fe==NULL){printf("\n");return-1;} fscanf(fe, "%d", &nbetu); b = listvide(); for(i=0; i");fclose(fe);return-1;} tetu[i] = (listetuinfo*)malloc(sizeof(listetuinfo)); if(tetu[i]==NULL){printf("\n");fclose(fe);return-1;} a = lireEtu(fe); b = lireCarte(fe, a.nbchoix); a.carte = b; *tetu[i] = a; } fclose(fe); return nbetu; } //enregistrement ======================================================================================================================================================== void enregistrementcarte(FILE *fe, Maillonchoix* carte, int nb){ if(carte==NULL){return;} fprintf(fe, "%s\n%s\n%d\n%d\n", carte->Ville, carte->dep, carte->decision, carte->validation); enregistrementcarte(fe, carte->suivant, nb-1); free(carte); } void enregistrementinfo(FILE *fe, listetuinfo etu){ Listchoixdept b; int i=0; b = etu.carte; fprintf(fe, "%d\n%s\n%s\n%d %d %d %d\n%d\n", etu.numeroetu, etu.nometu, etu.prenometu, etu.notes, etu.nbchoix); enregistrementcarte(fe, b, etu.nbchoix); } int enregistrementetudiants(char nomFich[], listetuinfo *tetu[], int nb){ int i=0; FILE *fe; listetuinfo etu; fe = fopen( nomFich, "w"); if(fe==NULL){printf("\n");return-1;} fprintf(fe, "%d\n", nb); for(i=0; idepartement); affichagedep(carte->suivant); } void affichagecarte(Maillonchoix* carte){ if(carte==NULL){return;} printf("%s - %s\n", carte->Ville, carte->dep); afficherchoix(carte->suivant); } void affichageville(Maillon *tville[], int nbville){ int i; Listdept b; for(i=0; ildept; printf("%s :\n", tville[i]->Ville); affichagedep(b); printf("\n"); } } void affichervillechoix(Maillon villechoix){ int i; Listdept ldep; ldep = villechoix.ldept; printf("%s :\n", villechoix.Ville); affichagedep(ldep); printf("\n"); } int cherchelistcorrespond(MaillonDept* dep, char choixdep[]){ if(dep==NULL){return -1;} if(strcmp(dep->departement,choixdep)==0){return 1;} return cherchelistcorrespond(dep->suivant, choixdep); } int correspondville(char choixville[], char choixdep[], Maillon *tville[], int nbville){ int i, ok; Listdept b; for(i=0; iVille,choixville)==0){ b = tville[i].ldept; ok = cherchelistcorrespond(b, choixdep); if(ok==1){return 1;} } } return -1; } int correspondcarte(char choixville[], char choixdep[], Maillonchoix* carte){ if(carte==NULL){return 0;} if(strcmp(choixville,carte->Ville)==0){ if(strcmp(choixdep,carte->dep)==0){ return 1; } } correspondcarte(choixville, choixdep, carte->suivant); } //ajouter ============================================================================================================================================= void choix(Maillon *tville[], int nbville, char choixville[], char choixdep[]){ int i, ok; printf("ville : \n"); fgets(choixville, 31, stdin); choixville[strlen(choixville)-1]='\0'; printf("departement : \n"); fgets(choixdep, 31, stdin); choixdep[strlen(choixdep)-1]='\0'; ok = correspondville(choixville, choixdep, tville, nbville); while(ok!=1){ printf("ville : \n"); fgets(choixville, 31, stdin); choixville[strlen(choixville)-1]='\0'; printf("departement : \n"); fgets(choixdep, 31, stdin); choixdep[strlen(choixdep)-1]='\0'; ok = correspondville(choixville, choixdep, tville, nbville); } } Listchoixdept ajoutercarte(Maillonchoix* a, char choixville[], char choixdep[]){ Maillonchoix* carte; carte = (Maillonchoix*)malloc(sizeof(Maillonchoix)); if(carte==NULL){printf("\n");exit(1);} strcpy(carte->Ville,choixville); strcpy(carte->dep,choixdep); carte->decision=0; carte->validation=0; carte->suivant=a; return carte; } int allajoutprocess(Maillon *tville[], listetuinfo etu, int nbville){ int i, ok; Listchoixdept b; b = etu.carte; char choixville[31], choixdep[31]; affichageville(tville, nbville); choix(tville, nbville, choixville, choixdep); ok = correspondcarte(choixville, choixdep, b); if(ok==0){b = ajoutercarte(b, choixville, choixdep);} else{printf("\t< choix deja existant >\n");} } //modifier ============================================================================================================================================================== void choix2(Listchoixdept lcarte, char choixville[], char choixdep[]){ int ok; printf("ville : \n"); fgets(choixville, 31, stdin); choixville[strlen(choixville)-1]='\0'; printf("departement : \n"); fgets(choixdep, 31, stdin); choixdep[strlen(choixdep)-1]='\0'; ok = correspondcarte(choixville, choixdep, lcarte); while(ok!=1){ printf("ville : \n"); fgets(choixville, 31, stdin); choixville[strlen(choixville)-1]='\0'; printf("departement : \n"); fgets(choixdep, 31, stdin); choixdep[strlen(choixdep)-1]='\0'; ok = correspondcarte(choixville, choixdep, lcarte); } } void fchoixdep(char choixville[], char choixdep[], Maillon *tville[], int nbville){ int ok; printf("\n< quel departement voulez vous choisir ? >\n==>"); fgets(choixdep, 31, stdin); choixdep[strlen(choixdep)-1]='\0'; ok = correspondville(choixville, choixdep, tville[i], nbville); while(ok!=1){ printf("\n< quel departement voulez vous choisir ? >\n==>"); fgets(choixdep, 31, stdin); choixdep[strlen(choixdep)-1]='\0'; ok = correspondville(choixville, choixdep, tville[i], nbville); } } Maillonchoix choixmodifcarte(Maillonchoix dep, char choixville[], char choixdep[]){ Maillonchoix dep; if(dep==NULL){exit(1);} if(strcmp(dep->Ville,choixville)==0){ if(strcmp(dep->dep,choixdep)==0){ fchoixdep(choixville, choixdep, tville, nbville); dep->dep=choixville; return dep; } } dep->suivant = choixmodifcarte(dep.suivant, choixville, choixdep); } int correspondvilleonly(char choixville[], Maillon ville){ Listdept b; if(strcmp(ville.Ville,choixville)==0){ affichervillechoix(ville); return 1; } } void modificationcarte(listetuinfo etu, Maillon *tville[], int nbville){ int i, ok; char choixville[31], choixdep[31]; Listchoixdept lcarte; lcarte=etu.carte; affichagecarte(lcarte); choix2(lcarte, choixville, choixdep); for(i=0; i\n");} } } //supprimer ========================================================================================================================================== Maillonchoix suppressioncartechoix(char choixville[], char choixdep[], Maillonchoix* carte){ Maillonchoix* premier, tmp; if(carte==NULL){exit(1);} if(strcmp(carte.Ville,choixville)==0){ if(strcmp(choixdep,carte.dep)==0){ tmp=carte.suivant; free(carte); return tmp; } } carte = suppressioncartechoix(choixville, choixdep, carte.suivant); } void suppcarte(listetuinfo etu){ int i, ok; char choixville[31], choixdep[31]; Listchoixdept lcarte; lcarte=etu.carte; affichagecarte(lcarte); choix2(lcarte, choixville, choixdep); lcarte = suppressioncartechoix(choixville, choixdep, lcarte); } //affichage ======================================================================================================================================================= void affichagecarteall(Maillonchoix* carte){ if(carte==NULL){return;} printf("%s - %s\n décision : %d\nvalidation : %d\n", carte->Ville, carte->dep, carte->decision, carte->validation); afficherchoix(carte->suivant); } void affichageetu(listetuinfo etu){ Listchoixdept lcarte; lcarte=etu.carte; printf(" %d\n %s %s\n", a.numeroetu, a.nometu, a.prenometu); printf(" mathématique : %d\n", a.notes[0]); printf(" français : %d\n", a.notes[1]); printf(" anglais : %d\n", a.notes[2]); printf(" matière spé : %d\n", a.notes[3]); affichagecarteall(lcarte); } void affichage(Listchoixdept c){ if(c==NULL){printf("\n");return;} printf("%s %s %d %d", c->Ville, c->dep, c->decision, c->validation); if(c->suivant==NULL){affichage(c->suivant);} else{ printf("\n - "); affichage(c->suivant); } } //affiche que la personne void affichageetu(listetuinfo a){ printf(" %d\n %s %s\n", a.numeroetu, a.nometu, a.prenometu); printf(" mathématique : %d -", a.notes[0]); printf(" français : %d -", a.notes[1]); printf(" anglais : %d -", a.notes[2]); printf(" matière spé : %d\n", a.notes[3]); } //affichage general void affichealletu(listetuinfo *tetu[], int nb){ int j=0; Listchoixdept b; b = listvide(); for(j=0; jcarte; affichage(b); printf("\n\n"); } } //========================================================================================================================================================= // zone de test ========================================================================================= void test1(void){ listetuinfo *tetu[5000]; int nb; char nomFich[20]; strcpy( nomFich, "candidature.txt"); nb = chargeretudiant(nomFich, tetu, 5000); affichealletu(tetu, nb); } //========================================================================================================== // Partie 3 // Partie 4 /* V affichage coté candidat de ces infos admis ou pas - valdier ça candidature refuse les autres - valider met a jour le dossier candidature - chaque departement peut consulter ça liste d'attente - metre a jour la liste - - - - - */ // coté etu========================================================================================================= // affichage void affichagedepresultat(Maillonchoix* carte){ if(carte==NULL){return;} if(carte->decision==1){ printf("%s %s - admis \n", carte.Ville, carte.dep); } if(carte->decision==1){ printf("%s %s - refusé \n", carte.Ville, carte.dep); } if(carte->decision==1){ printf("%s %s - lsite d'attente \n", carte.Ville, carte.dep); } affichagedepresultat(carte.suivant); } // validation void validation(char choixville[], char choixdep[], Maillonchoix* carte, int *ok, Maillonatt lplace, int nbplace, listetuinfo etu){ if(carte==NULL){return;} if(strcmp(carte.Ville,choixville)==0){ if(strcmp(carte.dep,choixdep)==0){ if(carte.decision==1){ carte.validation=1; *ok=1; }else{printf("vous netes pas admis dans cette iut\n");*ok=-1;return;} } } validation(choixville, choixdep, carte.suivant, ok); if(ok==1){ if(carte.decision==1){ carte.validation=-1; miseajourindep( lplace, nbplace, etu); } } } void enregistrementvalidation(char choixville[], char choixdep[], Maillonchoix* carte, int *ok, char nomFich[], listetuinfo *tetu[], int nb){ int ok; validation( choixville, choixdep, carte, &ok); enregistrementetudiants( nomFich, tetu, nb); } // -> mise a jour Maillonatt miseajourfile(Maillonatt place, int nbplace, listetuinfo etu){ if(place==NULL){exit(1);} if(place.munc==etu.numeroetu){ Maillonatt temp; temp=place.suivant; free(place); return temp; } miseajourfile(place.suivant, nbplace-1); } int miseajouratt(Maillonatt place, int nbplace){ if(place==NULL){return;} if(nbplace==0){return;} if(place.decision==2){ place.decision==1; } miseajouratt(place.suivant, nbplace-1); } void miseajourindep(Maillonatt lplace, int nbplace, listetuinfo etu){ lpace = miseajourfile(lplace, nbplace, etu); miseajouratt(lplace, nbplace); } // coté dep============================================================================================================= // affichage dep void affichageonlyadmis(Maillonatt etuatt){ if(etuatt==NULL){return;} if(etuatt.decision==1){ printf("%d %s %s\n" etuatt.numc, etuatt.nom, etuatt.prenom); } affichageonlyadmis(etuatt.suivant); } void affichageonlyatt(Maillonatt etuatt){ if(etuatt==NULL){return;} if(etuatt.decision==1){ printf("%d %s %s\n" etuatt.numc, etuatt.nom, etuatt.prenom); } affichageonlyatt(etuatt.suivant); } //chercher present en admission ======================================================================================== void chercheretuadmisindep(char choixnom[], char nomprenom[], Maillonatt etuatt){ if(etuatt==NULL){printf("erreur de recherche\n");return;} if(strcmp(etuatt.nom,choixnom)==0){ if(strcmp(etuatt.prenom,choixprenom)==0){ if(etuatt.decision==1){printf("%s %s est admis\n", etuatt.nom, etuatt.prenom);return;} if(etuatt.decision==2){printf("%s %s est en attente\n", etuatt.nom, etuatt.prenom);return;} if(etuatt.decision==-1){printf("%s %s est refusé\n", etuatt.nom, etuatt.prenom);return;} } } chercheretuadmisindep(choixnom, choixprenom, etuatt.suivant); } // Général (menu et ce qui en ai relié) /* questionadmin(){ printf("\nQuel numéro détudiant ?\n==>"); scanf("%d%*c", &choix); printf("\n"); } int menu(void){ //charger int i=0, choix; while(i!=1){ printf("\n\tmenu\n\n"); printf("1\tutilisateur\n"); printf("2\tadmin\n"); printf("3\tresponsable d'admission\n"); printf("\nQuel est votre choix ?\n==>"); scanf("%d%*c", &choix); printf("\n"); if(choix==1){ } if(choix==2){ } if(choix==3){ } if(choix<1 || choix>6){ printf("mauvaise saisie\n"); } } //enregister return 1; } */