fonction de chargement des candidat + choix fait avec affichage

master
Benjamin BACHELARD 2 years ago
parent 805c03aeea
commit 6a23f041ff

@ -1,4 +1,8 @@
226645 Blondeau Nicolas 4 5.5 4 3
Clermont Biologie 0 0
Grenoble Bio-Info 0 0
Aurillac Informatique 0 0
226584 bachelard benjamin 20 17.5 19 3
Clermont Informatique 0 0
Grenoble Informatique 0 0
Aurillac Informatique 0 0
Aurillac Informatique 0 0

188
iut.c

@ -3,7 +3,7 @@
#include <string.h>
#include "iut.h"
//Fonction d'initialisation de VilleIUT --> Renvoie une liste vide
//Fonction qui teste si la liste est vide ou non, et renvoie 'Vrai si la liste est vide', sinon 'Faux'
@ -13,7 +13,7 @@ Booleen testVide(VilleIUT V){
return faux;
}
//chargement Ville+iut
int chargement(VilleIUT *tiut[],int tmax){
int i = 0, j=0;
int nbDep = 0;
@ -45,59 +45,141 @@ int chargement(VilleIUT *tiut[],int tmax){
fclose(fe);
return i;
}
VilleIUT lireVille(FILE *fe, int *nbDep){
VilleIUT V;
V.ldept = NULL;
fscanf(fe,"%s %d", V.ville, nbDep);
return V;
}
VilleIUT lireVille(FILE *fe, int *nbDep){
VilleIUT V;
V.ldept = NULL;
fscanf(fe,"%s %d", V.ville, nbDep);
return V;
}
MaillonDept lireDep(FILE *fe){
MaillonDept m;
fscanf(fe,"%s %d %s %c", m.departement, &m.nbP, m.resp, &m.AouD);
return m;
}
ListeD InsertionTete(ListeD ld, char *departement, int nbP,char *resp, char AouD){
MaillonDept *m;
m = (MaillonDept*)malloc(sizeof(MaillonDept));
if(m==NULL){
printf("Problème malloc m");
exit(1);}
strcpy(m->departement, departement);
m->nbP = nbP;
strcpy(m->resp, resp);
m->AouD = AouD;
m->suivant = ld;
return m;
}
ListeD Insertion(ListeD ld, char *departement, int nbP,char *resp, char AouD){
if(ld==NULL)
return InsertionTete(ld, departement, nbP, resp, AouD);
if(strcmp(ld->departement, departement)<0)
return InsertionTete(ld, departement, nbP, resp, AouD);
ld->suivant = Insertion(ld->suivant, departement, nbP, resp, AouD);
return ld;
}
MaillonDept lireDep(FILE *fe){
MaillonDept m;
fscanf(fe,"%s %d %s %c", m.departement, &m.nbP, m.resp, &m.AouD);
return m;
}
ListeD InsertionTete(ListeD ld, char *departement, int nbP,char *resp, char AouD){
MaillonDept *m;
m = (MaillonDept*)malloc(sizeof(MaillonDept));
if(m==NULL){
printf("Problème malloc m");
exit(1);}
strcpy(m->departement, departement);
m->nbP = nbP;
strcpy(m->resp, resp);
m->AouD = AouD;
m->suivant = ld;
return m;
}
void affichage (VilleIUT *tiut[],int n){
int i;
for(i=0;i<n;i++){
printf("\n%s\n", tiut[i]->ville);
affichageListe(tiut[i]->ldept);
ListeD Insertion(ListeD ld, char *departement, int nbP,char *resp, char AouD){
if(ld==NULL)
return InsertionTete(ld, departement, nbP, resp, AouD);
if(strcmp(ld->departement, departement)<0)
return InsertionTete(ld, departement, nbP, resp, AouD);
ld->suivant = Insertion(ld->suivant, departement, nbP, resp, AouD);
return ld;
}
//affichage Ville+departement..
void affichage (VilleIUT *tiut[],int n){
int i;
for(i=0;i<n;i++){
printf("\n%s\n", tiut[i]->ville);
affichageListe(tiut[i]->ldept);
}
}
void affichageListe(ListeD ld){
while(ld!=NULL){
printf("%s\t",ld->departement);
printf("%d\t",ld->nbP);
printf("%s\t",ld->resp);
printf("%c\n",ld->AouD);
ld = ld->suivant;}
}
//chargement candidat
int chargementcandidat(Candidat *tcandidat[],int tmax){
int i = 0, j=0;
int nbChoix = 0;
Candidat C;
Choix ch;
FILE *fe1;
fe1=fopen("Candidat.don","r");
if(fe1==NULL){
printf("Problème d'ouverture du fichier Candidat");
return-1;
}
C = lireCandidat(fe1, &nbChoix);
while(!feof(fe1)){
tcandidat[i] = (Candidat*)malloc(sizeof(Candidat));
if(tcandidat[i]==NULL){
printf("Problème de malloc");
return -3;
}
*tcandidat[i] = C;
for(j = 0; j < nbChoix; j++){
ch = lireChoix(fe1);
tcandidat[i]->lchoix = InsertionCandidat(tcandidat[i]->lchoix, ch.ville, ch.departement, ch.decision, ch.validation);
}
C = lireCandidat(fe1, &nbChoix);
i++;
}
fclose(fe1);
return i;
}
void affichageListe(ListeD ld){
while(ld!=NULL){
printf("%s\t",ld->departement);
printf("%d\t",ld->nbP);
printf("%s\t",ld->resp);
printf("%c\n",ld->AouD);
ld = ld->suivant;}
}
Candidat lireCandidat(FILE *fe1, int *nbChoix){
Candidat C;
C.lchoix = NULL;
fscanf(fe1,"%d %s %s %f %f %f %d", &C.numero, C.nom, C.prenom, &C.note.Francais, &C.note.Maths, &C.note.Anglais, &C.nb_choix);
*nbChoix=C.nb_choix;
return C;
}
Choix lireChoix(FILE *fe1){
Choix ch;
fscanf(fe1,"%s %s %d %d", ch.ville, ch.departement, &ch.decision, &ch.validation);
return ch;
}
ListeC InsertionTeteCandidat(ListeC ld, char *ville, char *departement, int decision, int validation){
Choix *ch;
ch = (Choix*)malloc(sizeof(Choix));
if(ch==NULL){
printf("Problème malloc m");
exit(1);}
strcpy(ch->ville, ville);
strcpy(ch->departement, departement);
ch->decision = decision;
ch->validation = validation;
ch->suivant = ld;
return ch;
}
ListeC InsertionCandidat(ListeC ld, char *ville, char *departement, int decision, int validation){
if(ld==NULL)
return InsertionTeteCandidat(ld, ville, departement, decision, validation);
if(strcmp(ld->ville, ville)<0)
return InsertionTeteCandidat(ld, ville, departement, decision, validation);
ld->suivant = InsertionCandidat(ld->suivant, ville, departement, decision, validation);
return ld;
}
//affichage Candidat+choix
void affichageCandidatchoix(Candidat *tcandidat[],int n){
int i;
for(i=0;i<n;i++){
printf("\n%d\t", tcandidat[i]->numero);
printf("%s ", tcandidat[i]->nom);
printf("%s\t", tcandidat[i]->prenom);
printf("%.2f\t", tcandidat[i]->note.Francais);
printf("%.2f\t", tcandidat[i]->note.Maths);
printf("%.2f\t", tcandidat[i]->note.Anglais);
printf("%d\n", tcandidat[i]->nb_choix);
affichageListeCandidatchoix(tcandidat[i]->lchoix);
}
}
void affichageListeCandidatchoix(ListeC ld){
while(ld!=NULL){
printf("%s\t",ld->ville);
printf("%s\t",ld->departement);
printf("%d\t",ld->decision);
printf("%d\n",ld->validation);
ld = ld->suivant;}
}

27
iut.h

@ -4,27 +4,27 @@
// Structure pour stocker les informations sur un choix d'un candidat
typedef struct{
float Français;
float Francais;
float Maths;
float Anglais;
}note;
typedef struct liste{
typedef struct liste2 {
char ville[50];
char departement[50];
int decision;
int validation;
struct liste *suivant;
struct liste2 *suivant;
} Choix, *ListeC;
typedef struct liste{
typedef struct liste1{
int numero;
char nom[50];
char prenom[50];
note note;
int nb_choix;
ListeC lchoix;
struct liste *suivant;
struct liste1 *suivant;
} Candidat;
@ -66,15 +66,26 @@ typedef enum {faux,vrai}Booleen;
//Liste:
VilleIUT Initialisation(void);
Booleen testVide(VilleIUT V);
void afficher (VilleIUT V);
VilleIUT defiler(VilleIUT V);
VilleIUT lireVille(FILE *fe, int *nbDep);
MaillonDept lireDep(FILE *fe);
//chargement Ville+departement
int chargement(VilleIUT *tiut[],int tmax);
MaillonDept lireDep(FILE *fe);
VilleIUT lireVille(FILE *fe, int *nbDep);
ListeD Insertion(ListeD ld, char *departement, int nbP,char *resp, char AouD);
ListeD InsertionTete(ListeD ld, char *departement, int nbP,char *resp, char AouD);
void affichage (VilleIUT *tiut[],int n);
void affichageListe(ListeD ld);
ListeD Insertion(ListeD ld, char *departement, int nbP,char *resp, char AouD);
ListeD InsertionTete(ListeD ld, char *departement, int nbP,char *resp, char AouD);
//Candidat+choix
int chargementcandidat(Candidat *tcandidat[],int tmax);
Candidat lireCandidat(FILE *fe1, int *nbChoix);
Choix lireChoix(FILE *fe1);
ListeC InsertionTeteCandidat(ListeC ld, char *ville, char *departement, int decision, int validation);
ListeC InsertionCandidat(ListeC ld, char *ville, char *departement, int decision, int validation);
void affichageCandidatchoix(Candidat *tcandidat[],int n);
void affichageListeCandidatchoix(ListeC ld);

@ -3,13 +3,18 @@
int main(){
VilleIUT V;
int n;
int n,nc;
VilleIUT *tiut[200];
Candidat *tcandidat[200];
//afficher(V);
n=chargement(tiut ,200);
printf("Nombre de villes : %d\n",n);
affichage(tiut,n);
nc=chargementcandidat(tcandidat ,200);
printf("\nNombre de candidat : %d\n",nc);
affichageCandidatchoix(tcandidat,nc);
int choix;
printf("\n\nUtilisateur - 1\tAdministrateur - 2\n\n");
scanf("%d",&choix);

Loading…
Cancel
Save