Guillaume 2 years ago
commit a499c3ac16

@ -138,10 +138,6 @@ lChoix creerCandidature(lChoix choixCandid, char ville[50], char departement[50]
ListeDeptV2 configurationDeptV2( ListeDept ldept ); ListeDeptV2 configurationDeptV2( ListeDept ldept );
void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept );
ListeCandidats trierListeCandidats( ListeCandidats l );
ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l );
ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l );
// listeDeparements.c // listeDeparements.c
ListeDept ajouterEnTete(ListeDept ldept, char nomDept[], char resp[], int nbP); ListeDept ajouterEnTete(ListeDept ldept, char nomDept[], char resp[], int nbP);
@ -177,3 +173,16 @@ VilleIut * lireIut (FILE * fichier);
VilleIut ** chargeIutDon(char nomFichier[], int * nbIut, int * nbMax); VilleIut ** chargeIutDon(char nomFichier[], int * nbIut, int * nbMax);
VilleIut ** initialiseTabIut(void); VilleIut ** initialiseTabIut(void);
void tailleSupTabIut(VilleIut ** tIut, int *nbMax); void tailleSupTabIut(VilleIut ** tIut, int *nbMax);
void fusionIut(VilleIut ** tIut, int * nbIut);
int existe(char * nom, VilleIut ** tIut, int nbIut, int iDepart, int * indice);
void fusion(VilleIut ** tIut, int nbIut, int i, int j);
void supprimerIut(VilleIut ** tIut, int nbIut, int j);
// candidat.c
Candidat *modifierCandidat(Candidat *c);
void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept );
ListeCandidats trierListeCandidats( ListeCandidats l );
ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l );
ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l );

@ -0,0 +1,32 @@
#include "../header/sae.h"
/**
@brief Modifie les informations d'un candidat
@param c Pointeur vers le candidat à modifier
@return Pointeur vers le candidat modifié
*/
Candidat *modifierCandidat(Candidat *c)
{
int choix;
printf("Que voulez vous modifier\n1-Le nom\n2-Le Prenom\n3-Les notes\n");
scanf("%d", &choix);
switch (choix)
{
case 1:
printf("Nom actuel : %s\nVeuillez saisir le nouveau nom\n", c->nom);
fgets(c->nom, 50, stdin);
c->nom[strlen(c->nom) - 1] = '\0';
break;
case 2:
printf("Prenom actuel : %s\nVeuillez saisir le nouveau prenom\n", c->prenom);
fgets(c->nom, 50, stdin);
c->prenom[strlen(c->prenom) - 1] = '\0';
break;
case 3:
printf("Voici les notes actuels : %.2f %.2f %.2f %.2f\nVeuillez saisir les nouvelles notes(note1/note2/note3/note4)", c->notes[0], c->notes[1], c->notes[2], c->notes[3]);
scanf("%f/%f/%f/%f", &c->notes[0], &c->notes[1], &c->notes[2], &c->notes[3]);
break;
}
return c;
}

@ -27,6 +27,8 @@ VilleIut ** chargeIutDon(char nomFichier[], int * nbIut, int * nbMax)
*nbMax = 5; *nbMax = 5;
i = 0; i = 0;
while (!feof(fichier)) while (!feof(fichier))
{ {
@ -42,6 +44,10 @@ VilleIut ** chargeIutDon(char nomFichier[], int * nbIut, int * nbMax)
} }
*nbIut = i-1; *nbIut = i-1;
fclose(fichier);
fusionIut(tIut, nbIut);
return tIut; return tIut;
} }
@ -169,6 +175,7 @@ void lectureDep(ListeDept ldept, FILE * fichier)
fscanf(fichier, "%s %d ", ldept->nomDept, &ldept->nbP); fscanf(fichier, "%s %d ", ldept->nomDept, &ldept->nbP);
fgets(ldept->resp, 30, fichier); fgets(ldept->resp, 30, fichier);
ldept->resp[strlen(ldept->resp)-1] = '\0'; ldept->resp[strlen(ldept->resp)-1] = '\0';
ldept->suiv = NULL;
} }
/** /**
@ -178,117 +185,89 @@ void testCharge(void)
{ {
int nbIut, nbMax; int nbIut, nbMax;
VilleIut ** tIut = chargeIutDon("../donnees/iut.don", &nbIut, &nbMax); VilleIut ** tIut = chargeIutDon("../donnees/iut.don", &nbIut, &nbMax);
fusionIut(tIut, &nbIut);
for (int i = 0; i < nbIut; i++) for (int i = 0; i < nbIut; i++)
{ {
printf("[ %s | %s | %d | %s ]\n", tIut[i]->nom, tIut[i]->lDept->nomDept, tIut[i]->lDept->nbP, tIut[i]->lDept->resp); printf("\nVille : %s\n", tIut[i]->nom);
afficherListe(tIut[i]->lDept);
} }
} }
/**
* @brief Fusionne la liste de département de toutes les villes du même nom de tIut
/*int chargIutDon(VilleIut *tVilleIut[], int nbMax, char nomFich[]) *
* @param tIut Tableau de pointeur de VilleIut
* @param nbIut [Taille Logique]
*/
void fusionIut(VilleIut ** tIut, int *nbIut)
{ {
FILE *flot; int indice;
int i=0, nbP, trouve, indice;
char nom[30], nomDept[30], resp[30];
flot = fopen(nomFich, "r"); for (int i = 0; i < *nbIut; i++)
if(flot==NULL)
{
printf("Probleme d'ouverture du fichier\n");
exit(1);
}
fscanf(flot, "%s", nom);
lireDep(flot, nomDept, &nbP, resp);
while(!feof(flot))
{ {
if(i==nbMax) if(existe(tIut[i]->nom, tIut, *nbIut, i, &indice))
{ {
printf("Tableau plein\n"); fusion(tIut, *nbIut, i, indice);
return -1; (*nbIut)--;
i--;
} }
indice = appartientIut(tVilleIut, i, nom, &trouve);
if(trouve==0)
{
tVilleIut[i] = (VilleIut*)malloc(sizeof(VilleIut));
if(tVilleIut[i]==NULL)
{
printf("Probleme malloc\n");
fclose(flot);
exit(1);
} }
strcpy(tVilleIut[i]->nom, nom);
tVilleIut[i]->lDept = listenouv();
ajouterDept(tVilleIut[i]->lDept, nomDept, resp, nbP);
i = i + 1;
}
if(trouve==1)
tVilleIut[indice]->lDept = ajouterDept(tVilleIut[indice]->lDept, nomDept, resp, nbP);
fscanf(flot, "%s", nom);
lireDep(flot, nomDept, &nbP, resp);
}
return i;
} }
void lireDep(FILE *flot, char nomDept[], int *nbP, char resp[]) /**
{ * @brief Verifie l'existance d'une VilleIut dans le tableau de pointeur de VilleIut
fscanf(flot,"%s%d\t", nomDept, nbP); *
fgets(resp, 30, flot); * @param nom [CHAINE DE CARACTERES]
* @param tIut Tableau de pointeur de VilleIut
#ifdef _WIN32 * @param nbIut [Taille Logique]
resp[strlen(resp) - 1] = '\0'; * @param iDepart Indice à partir du quel rechercher
#endif * @param indice Indice de la valeur si trouvée
* @return int 1 -> Trouvé | 0 -> Inexistante
#ifdef __linux__ */
resp[strlen(resp) - 2] = '\0'; int existe(char * nom, VilleIut ** tIut, int nbIut, int iDepart, int * indice)
#endif
}
int appartientIut(VilleIut *tVilleIut[], int nb, char nom[], int *trouve)
{ {
int i = 0; for (int i = iDepart+1; i < nbIut; i++)
while(i < nb)
{ {
if(strcmp(tVilleIut[i]->nom, nom) == 0) if (strcmp(nom, tIut[i]->nom) == 0)
{ {
*trouve = 1; *indice = i;
return i; return 1;
} }
i = i + 1;
} }
*trouve = 0;
return i; return 0;
} }
void sauvegarderFichierIutDon(VilleIut *tVilleIut[], int nbVille, char nomFich[]) /**
* @brief Fusionne la liste de département de deux VilleIut du même nom
*
* @param tIut Tableau de pointeur de VilleIut
* @param nbIut [Taille Logique]
* @param i Indice liste d'accueil
* @param j Indice ville à supprimer
*/
void fusion(VilleIut ** tIut, int nbIut, int i, int j)
{ {
FILE *flot; ListeDept aux;
int i=0; aux = tIut[i]->lDept;
tIut[i]->lDept = tIut[j]->lDept;
tIut[i]->lDept->suiv = aux;
flot = fopen(nomFich, "w"); supprimerIut(tIut, nbIut, j);
if(flot==NULL) }
{
printf("Probleme lors de l'ouverture du fichier\n"); /**
exit(1); * @brief Supprime une ville du tableau de pointeur de VilleIut
} *
while(i<nbVille) * @param tIut Tableau de pointeur de VilleIut
{ * @param nbIut [Taille Logique]
printf("%d\n", i); * @param j Indice ville à supprimer
while(tVilleIut[i]->lDept != NULL) */
void supprimerIut(VilleIut ** tIut, int nbIut, int j)
{
for (int i = j ; i < nbIut-1 ; i++)
{ {
printf("%s %s %d %s", tVilleIut[i]->nom, tVilleIut[i]->lDept->nomDept, tVilleIut[i]->lDept->nbP, tVilleIut[i]->lDept->resp); tIut[i] = tIut[i+1];
fprintf(flot, "%s %s %d %s", tVilleIut[i]->nom, tVilleIut[i]->lDept->nomDept, tVilleIut[i]->lDept->nbP, tVilleIut[i]->lDept->resp);
tVilleIut[i]->lDept = tVilleIut[i]->lDept->suiv;
}
i = i + 1;
} }
fclose(flot);
} }
*/
/*
*/

@ -10,7 +10,7 @@ int main(void)
// #endif // #endif
//guillaume(); //guillaume();
//testCharge(); //testCharge();
//Globale(); Globale();
//testJean(); //testJean();
return 0; return 0;

@ -14,21 +14,25 @@
*/ */
void Globale(void) void Globale(void)
{ {
printf(" \n ---> lancement de la fonction globale.... \n\n"); //printf(" \n ---> lancement de la fonction globale.... \n\n");
Log * tLog; Log * tLog;
VilleIut *tIut[50] ; VilleIut ** tIut;
int nbVilles; int nbVilles;
int nbLog; int nbLog;
int nbIut, nbIutMax;
//Chargement des fichiers //Chargement des fichiers
tLog = chargementLog("../donnees/log.don", &nbLog); tLog = chargementLog("../donnees/log.don", &nbLog);
tIut = chargeIutDon("../donnees/iut.don", &nbIut, &nbIutMax);
//nbVilles = chargIutDon(tIut, 50, "../donnees/iut.don"); //nbVilles = chargIutDon(tIut, 50, "../donnees/iut.don");
//Appel du menu visiteur //Appel du menu visiteur
menuVisiteur(tLog, nbLog, tIut, nbVilles); menuVisiteur(tLog, nbLog, tIut, nbIut);
//Sauvegarde dans les fichiers //Sauvegarde dans les fichiers
} }
/** /**
@ -77,10 +81,8 @@ Log * chargementLog(char * nomFichier, int * nbLog)
} }
fscanf(fichier, "%s %s %s", tLog[i].utilisateur, tLog[i].mdp, tLog[i].status); fscanf(fichier, "%s %s %s", tLog[i].utilisateur, tLog[i].mdp, tLog[i].status);
printf("%s\n", tLog[i].status);
i++; i++;
} }
*nbLog = i; *nbLog = i;
return tLog; return tLog;
} }
@ -99,7 +101,7 @@ void test(VilleIut * tIut[], int nbVilles)
* choixMenuVisiteur. Selon le choix de l'utilisateur, la fonction appelle la fonction correspondante * choixMenuVisiteur. Selon le choix de l'utilisateur, la fonction appelle la fonction correspondante
* ou met fin à l'exécution de la fonction. * ou met fin à l'exécution de la fonction.
*/ */
void menuVisiteur(Log * tLog, int nbLog, VilleIut *tIut[], int nbVilles) void menuVisiteur(Log * tLog, int nbLog, VilleIut *tIut[], int nbIut)
//void menuVisiteur(VilleIut *villeIut, int nbVilles) //void menuVisiteur(VilleIut *villeIut, int nbVilles)
{ {
int choix; int choix;
@ -114,15 +116,14 @@ void menuVisiteur(Log * tLog, int nbLog, VilleIut *tIut[], int nbVilles)
switch(choix) switch(choix)
{ {
case 1: case 1:
//test(tIut, nbVilles); afficheVillesIUT(tIut, nbIut);
afficheVillesIUT(tIut, nbVilles);
//printf("Affiche les Villes contenant des IUT (En attente d'une fonction de chargement fonctionnelle)\n");
break; break;
case 2: case 2:
printf("Affiche le nombre de place dans un departement (En attente de Guillaume)\n"); printf("Affiche le nombre de place dans un departement (En attente de Guillaume)\n");
break; break;
case 3 : case 3 :
afficherDeptIutDonne(tIut, nbVilles); printf("Afficher departement d'un Iut\n");
//afficherDeptIutDonne(tIut, nbIut);
break; break;
case 4 : case 4 :
printf("Affiche les IUT possedant un departement donne (En attente de Jean)\n"); printf("Affiche les IUT possedant un departement donne (En attente de Jean)\n");
@ -582,7 +583,11 @@ void afficheVillesIUT(VilleIut *tiut[], int nbVilles)
// Affichage du nom de la ville // Affichage du nom de la ville
printf(" -> %s\n", tiut[i]-> nom); printf(" -> %s\n", tiut[i]-> nom);
} }
printf(" \n\n\n");
printf("\nAppuyez sur entree pour continuer...\n");
scanf("%*c");
clean
} }
/** /**
@ -786,6 +791,44 @@ int creerCandidat(Candidat *tCand[], int nbCandidats)
return nbCandidats + 1; return nbCandidats + 1;
} }
/**
* @brief Supprime un choix de la liste de choix d'un candidat
*
* @param lchoix la liste de choix à modifier
* @param nbchoix le nombre de choix dans la liste de choix
*
* @return la liste avec le choix en moins
*/
lChoix supprimerCandidature( lChoix l, int * nbchoix)
{
if ( l == NULL )
{
printf(" \n --> Le candidat ne possede aucun choix...\n\n");
return l;
}
printf("\n Voici les choix du candidat : \n");
printf( " -----------------------------\n\n");
int rep = 0, c = 0;
for( int i = 0; i < *nbchoix; i ++ )
{
printf(" %d.) Ville : %10s ; Departement : %10s \n",i + 1, l -> ville, l -> departement);
}
printf(" \n\n --> Quel choix supprimer ? : ");
scanf("%d%*c", &rep);
while ( c != rep - 1 )
{
l = l -> suiv;
c = c + 1;
}
l = supprimerEnTeteC( l );
*nbchoix = *nbchoix - 1;
return l;
}
/** /**
* @brief Permet de créer une candidature à un candidat * @brief Permet de créer une candidature à un candidat
@ -870,107 +913,3 @@ ListeDeptV2 configurationDeptV2( ListeDept ldept )
return lDeptV2; return lDeptV2;
} }
/*
================================================
Partie 4
================================================
*/
/**
* @brief Affiche une liste de candidats après l'avoir triée par ordre alphabétique
*
* @param lcand liste de candidats à trier et afficher
* @param type type de liste à afficher ( en attente ou admis )
* @param nomDept nom du departement dont est issu la liste
*/
void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept )
{
lcand = trierListeCandidats( lcand );
printf( " Liste des candidats %s du departement %10s \n -------------------------------------------------------\n\n", type, nomDept);
while ( lcand != NULL)
{
printf(" | Nom : %10s | Prenom : %10s | Numero : %8s |\n",
lcand -> candidat.nom, lcand -> candidat.prenom, lcand -> candidat.numero);
lcand = lcand -> suiv;
}
}
/**
* @brief Trie par ordre alphabétique les candidats d'une liste
*
* @param l liste de candidats à trier.
*
* @return La liste triée
*/
ListeCandidats trierListeCandidats( ListeCandidats l )
{
ListeCandidats nvL;
while ( l != NULL )
{
nvL = insertionCroissanteCand( nvL, l );
l = l -> suiv;
}
return nvL;
}
/**
* @brief Permet d'insérer un nouveau Maillon de candidats dans la liste par ordre alphabétique
* @param l la liste dont est issu le maillon à insérer
* @param nvL la nouvelle liste où est inséré le maillon
*
* @return La nouvelle liste avec le maillon au bon endroit
*/
ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l )
{
if ( l == NULL)
{
nvL = insertionTeteCand( nvL, l );
return nvL;
}
if ( strcmp( l -> candidat.nom, nvL -> candidat.nom ) < 0 )
{
nvL = insertionTeteCand( nvL, l );
return nvL;
}
if ( strcmp( l -> candidat.nom, nvL -> candidat.nom ) == 0 )
{
if ( strcmp( l -> candidat.prenom, nvL -> candidat.prenom ) < 0 )
{
nvL = insertionTeteCand( nvL, l );
return nvL;
}
}
nvL -> suiv = insertionCroissanteCand( nvL -> suiv, l );
return nvL;
}
/**
* @brief Insère en tête de la nouvelle liste un nouveau maillon
* @param l liste d'où est issu le nouveau maillon à intégrer
* @param nvL Liste où est insérer le nouveau Maillon
* @return La nouvelle liste avec le maillon au bon endroit
*/
ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l )
{
MaillonCandidat * m = ( MaillonCandidat * ) malloc ( sizeof( MaillonCandidat ));
if ( m == NULL )
{
printf("\n -> Erreur allocation memoire...\n");
exit(1);
}
m -> candidat = l -> candidat;
m -> suiv = nvL;
nvL = m;
free( l );
return nvL;
}
Loading…
Cancel
Save