12/01 Partie 3 fonctions finies pas testées

master
Louis LABORIE 2 years ago
parent 9d37257504
commit bf68bed1f0

241
SAEl.c

@ -1,4 +1,5 @@
#include "SAEl.h" #include "SAEl.h"
#include "SAE.h"
ListeDept creerListeDept(void) ListeDept creerListeDept(void)
{ {
@ -10,7 +11,7 @@ VilleIUT **chargementVille(char *nomFich, int tphys, int *tailleL)
int i = 0, nbDept; int i = 0, nbDept;
FILE *flot; FILE *flot;
VilleIUT **tabV; VilleIUT **tabV;
tabV = (VilleIUT **)malloc(sizeof(VilleIUT*) * tphys); tabV = (VilleIUT **)malloc(sizeof(VilleIUT *) * tphys);
if (tabV == NULL) if (tabV == NULL)
{ {
printf("Erreur malloc tab!\n"); printf("Erreur malloc tab!\n");
@ -34,7 +35,7 @@ VilleIUT **chargementVille(char *nomFich, int tphys, int *tailleL)
while (!feof(flot)) while (!feof(flot))
{ {
fscanf(flot, "%d", &nbDept); fscanf(flot, "%d", &nbDept);
printf("Nombre de dep : %d\n",nbDept); printf("Nombre de dep : %d\n", nbDept);
tabV[*tailleL]->idDept = creerListeDept(); tabV[*tailleL]->idDept = creerListeDept();
while (i < nbDept) while (i < nbDept)
{ {
@ -70,10 +71,10 @@ ListeDept traiterDept(ListeDept l, FILE *flot)
{ {
char nom[30], dept[30]; char nom[30], dept[30];
int nbPlaces; int nbPlaces;
fscanf(flot,"%s %d",dept,&nbPlaces); fscanf(flot, "%s %d", dept, &nbPlaces);
fgets(nom, 30, flot); fgets(nom, 30, flot);
nom[strlen(nom) - 1] = '\0'; nom[strlen(nom) - 1] = '\0';
printf("Nom du départ : %s\n",dept); printf("Nom du départ : %s\n", dept);
l = insererDept(l, dept, nom, nbPlaces); l = insererDept(l, dept, nom, nbPlaces);
return l; return l;
} }
@ -87,9 +88,9 @@ ListeDept ajouterEnTeteDept(ListeDept l, char *dept, char *nom, int nbP)
printf("Erreur malloc !\n"); printf("Erreur malloc !\n");
exit(1); exit(1);
} }
strcpy(nouv->departement,dept); strcpy(nouv->departement, dept);
nouv->nbPlaces = nbP; nouv->nbPlaces = nbP;
strcpy(nouv->nom,nom); strcpy(nouv->nom, nom);
nouv->suiv = l; nouv->suiv = l;
return nouv; return nouv;
} }
@ -107,9 +108,9 @@ ListeDept insererDept(ListeDept l, char *dept, char *nom, int nbP)
{ // récursif { // récursif
if (l == NULL) if (l == NULL)
return ajouterEnTeteDept(l, dept, nom, nbP); return ajouterEnTeteDept(l, dept, nom, nbP);
if ((strcmp(dept,l->departement)) < 0) if ((strcmp(dept, l->departement)) < 0)
return ajouterEnTeteDept(l, dept, nom, nbP); return ajouterEnTeteDept(l, dept, nom, nbP);
if ((strcmp(dept,l->departement)) == 0) if ((strcmp(dept, l->departement)) == 0)
return l; return l;
l->suiv = insererDept(l->suiv, dept, nom, nbP); l->suiv = insererDept(l->suiv, dept, nom, nbP);
return l; return l;
@ -135,14 +136,85 @@ ListeDept supprimerDept(ListeDept l, char *code)
{ {
if (l == NULL) if (l == NULL)
return l; return l;
if ((strcmp(code,l->departement)) < 0) if ((strcmp(code, l->departement)) < 0)
return l; return l;
if ((strcmp(code,l->departement)) == 0) if ((strcmp(code, l->departement)) == 0)
return supprimerEnTêteDept(l); return supprimerEnTêteDept(l);
l->suiv = supprimerDept(l->suiv, code); l->suiv = supprimerDept(l->suiv, code);
return l; return l;
} }
int verifChefDepart(VilleIUT** tiut, int nbEle, char* dept, char* ville, char* nom) {
int i, verif = 0;
ListeDept l;
for (i = 0 ; i < nbEle ; i++) {
if (strcmp(tiut[i]->ville,ville) == 0) {
l = tiut[i]->idDept;
while (l != NULL) {
if (strcmp(l->departement,dept) == 0) {
if (strcmp(l->responsable,nom) == 0) {
verif = 1;
}
}
l = l->suiv;
}
}
}
return verif;
}
int menuResponsableAffiche(void) {
int choix;
printf("####################################################\n");
printf("\t\tMenu Responsable\n\n");
printf("1 - Traiter les candidatures (output dans des fichiers)\n");
printf("\n\n9 - Repasser en mode Utilisateur");
printf("\n\n10 - Quitter\n");
printf("####################################################\n");
printf("\nSelection : ");
scanf("%d",&choix);
return choix;
}
int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int tailleL) {
int choix, codeRet;
char dept[30];
char ville[30];
char nom[30];
printf("Nom du département concernée : ");
scanf("%s",dept);
printf("\nNom de la ville concernée : ");
fgets(ville,30,stdin);
ville[strlen(ville) - 1] = '\0';
printf("\nNom du responsable du département : ");
fgets(nom,30,stdin);
nom[strlen(nom) - 1] = '\0';
printf("\n");
codeRet = verifChefDepart(tiut,nbEle,dept,ville,nom);
if (codeRet == 0) return 0;
while(1)
{
choix = menuResponsableAffiche();
system("clear");
switch(choix) {
case 1:
candidDept(tcandid,dept,ville,tailleL);
examinerCandid(tcandid,tailleL);
system("clear");
break;
case 9:
return 0;
case 10:
return -1;
}
}
}
/* /*
void affichageListeDeptR(ListeDept l) void affichageListeDeptR(ListeDept l)
{ {
@ -186,37 +258,40 @@ ListeDept rechercheDept(ListeDept l, char code[])
{ {
if (l == NULL) if (l == NULL)
return NULL; return NULL;
if ((strcmp(code,l->departement)) < 0) if ((strcmp(code, l->departement)) < 0)
return NULL; return NULL;
if (strcmp(code,l->departement)==0) if (strcmp(code, l->departement) == 0)
return l; return l;
return rechercheDept(l->suiv, code); return rechercheDept(l->suiv, code);
} }
void SauvegarderIUT(VilleIUT** tabV, int tailleL) { void SauvegarderIUT(VilleIUT **tabV, int tailleL)
{
int i, nbDept; int i, nbDept;
FILE* flot; FILE *flot;
flot = fopen("res.txt","w"); flot = fopen("res.txt", "w");
for (i = 0 ; i < tailleL ; i++) { for (i = 0; i < tailleL; i++)
fprintf(flot,"%s\n",tabV[i]->ville); {
fprintf(flot, "%s\n", tabV[i]->ville);
nbDept = longueurListe(tabV[i]->idDept); nbDept = longueurListe(tabV[i]->idDept);
fprintf(flot,"%d\n",nbDept); fprintf(flot, "%d\n", nbDept);
SauvegarderListe(tabV[i]->idDept,flot); SauvegarderListe(tabV[i]->idDept, flot);
free(tabV[i]); free(tabV[i]);
} }
} }
void SauvegarderListe(ListeDept l, FILE* flot) { void SauvegarderListe(ListeDept l, FILE *flot)
MaillonDept* tmp; {
while (l->suiv != NULL) { MaillonDept *tmp;
while (l->suiv != NULL)
{
tmp = l; tmp = l;
fprintf(flot,"%s %d %s\n",l->departement,l->nbPlaces,l->nom); fprintf(flot, "%s %d %s\n", l->departement, l->nbPlaces, l->nom);
l = l->suiv; l = l->suiv;
free(tmp); free(tmp);
} }
fprintf(flot,"%s %d %s\n",l->departement,l->nbPlaces,l->nom); fprintf(flot, "%s %d %s\n", l->departement, l->nbPlaces, l->nom);
free(l); free(l);
} }
int longueurListe(ListeDept l) int longueurListe(ListeDept l)
@ -230,6 +305,122 @@ int longueurListe(ListeDept l)
return cpt; return cpt;
} }
int traiterCandidIUTDept(Candidat *candid, char *dept, char *ville)
{
int i, verif = 0, nb = 0;
ListeCandid l = candid->idCandIUT;
while (l != NULL)
{
if (strcmp(l->iutCandid, ville) == 0)
{
verif = 1;
break;
}
l = l->suiv;
}
if (verif == 1)
{
for (i = 0; i < l->nbChoix; i++)
{
if (strcmp(l->tabDept[i]->departement, dept) == 0)
return 1;
}
}
return 0;
}
Candidat **candidDept(Candidat **tabCandidat, char *dept, char *ville, int tailleL, int *nb)
{
int tphys = 50, i, codeRetour;
Candidat **tabCandDept = (Candidat **)malloc(sizeof(Candidat *) * tphys);
if (tabCandDept == NULL)
{
printf("Pb malloc tab candid\n");
exit(1);
}
*nb = 0;
for (i = 0; i < tailleL; i++)
{
codeRetour = traiterCandidIUTDept(tabCandidat[i], dept, ville);
if (codeRetour == 1)
{
tabCandDept[i] = tabCandidat[i];
*nb += 1;
}
}
return tabCandDept;
}
void SauvegardeCandidAdmis(Candidat **tab, int nb, int admis)
{
FILE *flot;
int i;
if (admis == 1)
flot = fopen("candidAdmis.txt", "w");
else
flot = fopen("candidMEA.txt", "w");
if (flot == NULL)
{
printf("Problème ouverture fichier candidat admis\n");
exit(1);
}
for (i = 0; i < nb; i++)
{
moy = (tab[i]->note[0] + tab[i]->note[1] + tab[i]->note[2] + tab[i]->note[3]) / 4;
fprintf(flot, "%s %s %.1f\n", tab[i]->nom, tab[i]->prenom, moy);
}
fclose(flot);
}
void examinerCandid(Candidat **tabCandid, int nb)
{
int nbAdmis, i, comptAdmis = 0, j, comptAttente = 0;
float mini, moy;
Candidat *tabAdmis[50];
Candidat *tabEnAttente[50];
ListeCandid l;
printf("Nombre d'admis ?\n");
scanf("%d", &nbAdmis);
printf("Note minimum ?\n");
scanf("%f", &mini);
for (i = 0; i < nb; i++)
{
moy = (tabCandid[i]->note[0] + tabCandid[i]->note[1] + tabCandid[i]->note[2] + tabCandid[i]->note[3]) / 4;
l = tabCandid[i]->idCandIUT;
while (l != NULL)
{
if (strcmp(l->iutCandid, ville) == 0)
break;
l = l->suiv;
}
for (j = 0; j < l->nbChoix; j++)
{
if (strcmp(l->tabDept[j]->departement, dept) == 0)
{
if (moy >= mini)
{
if (comptAdmis < nbAdmis)
{
l->tabDept[j]->decisionDept = 1;
tabAdmis[comptAdmis] = tabCandid[i];
comptAdmis += 1;
}
else
{
l->tabDept[j]->decisionDept = 2;
tabEnAttente[comptAttente] = tabCandid[i];
comptAttente += 1;
}
}
else
l->tabDept[j]->decisionDept = -1;
}
}
}
SauvegardeCandidAdmis(tabAdmis, comptAdmis, 1);
SauvegardeCandidAdmis(tabEnAttente, comptAttente, 0);
}
/* /*
ListeDept ajouterEnQueue(ListeDept l, int x) ListeDept ajouterEnQueue(ListeDept l, int x)
{ {

@ -46,3 +46,49 @@ bool verifSelection(void);
void creationDept(VilleIUT **tiut, int nbEle); void creationDept(VilleIUT **tiut, int nbEle);
int rechVille(VilleIUT **tiut, int nbEle, char code[], int *trouve); int rechVille(VilleIUT **tiut, int nbEle, char code[], int *trouve);
int verifChefDepart(VilleIUT** tiut, int nbEle, char* dept, char* ville, char* nom);
int menuResponsableAffiche(void);
int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int tailleL);
// PARTIE 3
typedef struct
{
char departement[30];
int decisionDept;
int decisionCandid;
}ChoixDept;
typedef struct maillonEtu
{
char iutCandid[30];
int nbChoix;
ChoixDept **tabDept;
struct maillonEtu *suiv;
}MaillonCandid, *ListeCandid;
typedef struct
{
int id;
char nom[30];
char prenom[30];
float note[4];
MaillonCandid *idCandIUT;
}Candidat;
int traiterCandidIUTDept(Candidat* candid,char* dept, char* ville);
Candidat** candidDept(Candidat** tabCandidat, char* dept, char* ville, int tailleL);
void SauvegardeCandidAdmis(Candidat** tab, int nb, int admis);
void examinerCandid(Candidat **tabCandid, int nb);
int gestionResponsable(VilleIUT **tiut, int nbEle);

Loading…
Cancel
Save