13/01 Partie 3 debug

master
Louis LABORIE 2 years ago
parent 832d2c8fb9
commit 1384a8fe84

322
SAEl.c

@ -1,158 +1,20 @@
#include "SAEl.h" #include "SAEl.h"
#include "SAE.h"
ListeDept creerListeDept(void) int verifChefDepart(VilleIUT **tiut, int nbEle, char *dept, char *ville, char *nom)
{ {
return NULL; int i, verif = 0;
} ListeDept l;
for (i = 0; i < nbEle; i++)
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); if (strcmp(tiut[i]->ville, ville) == 0)
i += 1;
}
i = 0;
*tailleL += 1;
tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT));
if (tabV[*tailleL] == NULL)
{ {
printf("Erreur malloc ville!\n"); l = tiut[i]->idDept;
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->nbPlaces = nbP;
strcpy(nouv->nom, nom);
nouv->suiv = l;
return nouv;
}
void affichageListeDept(ListeDept l) // itératif
{
while (l != NULL) while (l != NULL)
{ {
printf("- %s :\t|%d places\t\t%s|\n", l->departement, l->nbPlaces, l->nom); if (strcmp(l->departement, dept) == 0)
l = l->suiv; {
} if (strcmp(l->responsable, nom) == 0)
}
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;
}
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; verif = 1;
} }
} }
@ -163,7 +25,8 @@ int verifChefDepart(VilleIUT** tiut, int nbEle, char* dept, char* ville, char* n
return verif; return verif;
} }
int menuResponsableAffiche(void) { int menuResponsableAffiche(void)
{
int choix; int choix;
printf("####################################################\n"); printf("####################################################\n");
printf("\t\t|Menu Responsable|\n\n"); printf("\t\t|Menu Responsable|\n\n");
@ -173,34 +36,38 @@ int menuResponsableAffiche(void) {
printf("\n\n10 - Quitter\n"); printf("\n\n10 - Quitter\n");
printf("####################################################\n"); printf("####################################################\n");
printf("\nSelection : "); printf("\nSelection : ");
scanf("%d",&choix); scanf("%d", &choix);
return choix; return choix;
} }
int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int tailleL) { int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat **tcandid, int tailleL)
int choix, codeRet; {
int choix, codeRet, nb;
char dept[30]; char dept[30];
char ville[30]; char ville[30];
char nom[30]; char nom[30];
Candidat** tabCandidV;
printf("Nom du département concernée : "); printf("Nom du département concernée : ");
scanf("%s",dept); scanf("%s", dept);
printf("\nNom de la ville concernée : "); printf("\nNom de la ville concernée : ");
fgets(ville,30,stdin); fgets(ville, 30, stdin);
ville[strlen(ville) - 1] = '\0'; ville[strlen(ville) - 1] = '\0';
printf("\nNom du responsable du département : "); printf("\nNom du responsable du département : ");
fgets(nom,30,stdin); fgets(nom, 30, stdin);
nom[strlen(nom) - 1] = '\0'; nom[strlen(nom) - 1] = '\0';
printf("\n"); printf("\n");
codeRet = verifChefDepart(tiut,nbEle,dept,ville,nom); codeRet = verifChefDepart(tiut, nbEle, dept, ville, nom);
if (codeRet == 0) return 0; if (codeRet == 0)
while(1) return 0;
while (1)
{ {
choix = menuResponsableAffiche(); choix = menuResponsableAffiche();
system("clear"); system("clear");
switch(choix) { switch (choix)
{
case 1: case 1:
candidDept(tcandid,dept,ville,tailleL); tabCandidV = candidDept(tcandid, dept, ville, tailleL,&nb);
examinerCandid(tcandid,tailleL); examinerCandid(tabCandidV, nb, dept, ville);
system("clear"); system("clear");
break; break;
case 9: case 9:
@ -208,40 +75,9 @@ int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int taill
case 10: case 10:
return -1; return -1;
} }
} }
}
/*
void affichageListeDeptR(ListeDept l)
{
if (l->suiv == NULL)
printf("%d\n", l->v);
printf("%d =>", l->v);
affichageListeDeptR(l->suiv);
} }
int tete(ListeDept l)
{
if (l == NULL)
{
printf("opération interdite\n");
exit(1);
}
return l->v;
}
*/
bool vide(ListeDept l)
{
if (l == NULL)
return true; // 1
return false; // 0
}
/* /*
int longueur(ListeDept l) int longueur(ListeDept l)
{ {
@ -255,56 +91,56 @@ int longueur(ListeDept l)
} }
*/ */
ListeDept rechercheDept(ListeDept l, char code[]) // 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; // MaillonDept *tmp;
while (l->suiv != NULL) // 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)
{ // {
int cpt = 0; // int cpt = 0;
while (l != NULL) // while (l != NULL)
{ // {
cpt += 1; // cpt += 1;
l = l->suiv; // l = l->suiv;
} // }
return cpt; // return cpt;
} // }
int traiterCandidIUTDept(Candidat *candid, char *dept, char *ville) int traiterCandidIUTDept(Candidat *candid, char *dept, char *ville)
{ {
@ -330,10 +166,11 @@ int traiterCandidIUTDept(Candidat *candid, char *dept, char *ville)
return 0; return 0;
} }
Candidat **candidDept(Candidat **tabCandidat, char *dept, char *ville, int tailleL, int *nb) Candidat** candidDept(Candidat** tabCandidat, char* dept, char* ville, int tailleL, int* nb)
{ {
int tphys = 50, i, codeRetour; int tphys = 50, i, codeRetour;
Candidat **tabCandDept = (Candidat **)malloc(sizeof(Candidat *) * tphys); Candidat **tabCandDept;
tabCandDept = (Candidat **)malloc(sizeof(Candidat *) * tphys);
if (tabCandDept == NULL) if (tabCandDept == NULL)
{ {
printf("Pb malloc tab candid\n"); printf("Pb malloc tab candid\n");
@ -345,7 +182,7 @@ Candidat **candidDept(Candidat **tabCandidat, char *dept, char *ville, int taill
codeRetour = traiterCandidIUTDept(tabCandidat[i], dept, ville); codeRetour = traiterCandidIUTDept(tabCandidat[i], dept, ville);
if (codeRetour == 1) if (codeRetour == 1)
{ {
tabCandDept[i] = tabCandidat[i]; tabCandDept[*nb] = tabCandidat[i];
*nb += 1; *nb += 1;
} }
} }
@ -356,6 +193,7 @@ void SauvegardeCandidAdmis(Candidat **tab, int nb, int admis)
{ {
FILE *flot; FILE *flot;
int i; int i;
float moy;
if (admis == 1) if (admis == 1)
flot = fopen("candidAdmis.txt", "w"); flot = fopen("candidAdmis.txt", "w");
else else
@ -373,7 +211,7 @@ void SauvegardeCandidAdmis(Candidat **tab, int nb, int admis)
fclose(flot); fclose(flot);
} }
void examinerCandid(Candidat **tabCandid, int nb) void examinerCandid(Candidat **tabCandid, int nb, char* dept, char* ville)
{ {
int nbAdmis, i, comptAdmis = 0, j, comptAttente = 0; int nbAdmis, i, comptAdmis = 0, j, comptAttente = 0;
float mini, moy; float mini, moy;

@ -2,50 +2,22 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include "SAE.h"
typedef struct maillondept {
char departement[30];
int nbPlaces;
char nom[30];
struct maillondept* suiv;
}MaillonDept;
typedef MaillonDept* ListeDept; // PARTIE 3
typedef struct {
char ville[30];
ListeDept idDept;
}VilleIUT;
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); int traiterCandidIUTDept(Candidat* candid,char* dept, char* ville);
void SauvegarderListe(ListeDept l, FILE* flot); Candidat** candidDept(Candidat** tabCandidat, char* dept, char* ville, int tailleL, int* nb);
bool verifSelection(void); void SauvegardeCandidAdmis(Candidat** tab, int nb, int admis);
void creationDept(VilleIUT **tiut, int nbEle); void examinerCandid(Candidat **tabCandid, int nb, char* dept, char* ville);
int rechVille(VilleIUT **tiut, int nbEle, char code[], int *trouve); int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int tailleL);
int verifChefDepart(VilleIUT** tiut, int nbEle, char* dept, char* ville, char* nom); int verifChefDepart(VilleIUT** tiut, int nbEle, char* dept, char* ville, char* nom);
@ -53,42 +25,3 @@ int menuResponsableAffiche(void);
int gestionResponsable(VilleIUT **tiut, int nbEle, Candidat** tcandid, int tailleL); 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);

@ -0,0 +1,2 @@
Paul Bocluse 12.0
Don Qui Roté 10.0

@ -0,0 +1,2 @@
Michel Cool 13.2
Matteo Skater 13.0

@ -1,4 +1,4 @@
4 6
1 1
Paul Bocluse Paul Bocluse
14 9 7 18 14 9 7 18
@ -51,3 +51,27 @@ Informatique
Réseaux Réseaux
0 0
0 0
5
Michel Cool
14 9 12 18
1
Clermont-Ferrand
2
Informatique
0
0
Réseaux
0
0
6
Matteo Skater
10 14 15 13
1
Clermont-Ferrand
2
Informatique
0
0
Réseaux
0
0

Loading…
Cancel
Save