Ajout de fonctions et améliorations

master
Kyllian Chabanon 2 years ago
parent e90dca3022
commit 214d15ee10

@ -0,0 +1,103 @@
#include "partie1.h"
void modificationNbPDept(VilleIUT *tiut[], int nb)
{
char iutModif[30], deptModif[30];
int posIUT, posDept, nbPlaces;
bool trouve;
printf("Dans quel IUT se situe le département que vous voulez modifier ?\n> ");
scanf("%s", iutModif);
posIUT = rechercheVille(tiut, nb, iutModif, &trouve);
if (trouve == false)
{
printf("Cet IUT n'existe pas. Veuillez réessayer.\n");
return;
}
printf("Quel est le département dont vous voulez modifier le nombre de places ?\n> ");
scanf("%s", deptModif);
posDept = rechercheDept(tiut[posIUT]->ldept, deptModif, &trouve);
if (trouve == false)
{
printf("Cet département n'existe pas dans cet IUT. Veuillez réessayer.\n");
return;
}
printf("Il y a actuellement %d places dans ce département. Entrez le nouveau nombre de places :\n> ", getNbP(tiut[posIUT]->ldept, posDept));
scanf("%d", &nbPlaces);
setNbP(tiut[posIUT]->ldept, posDept, nbPlaces);
printf("Le nombre de places est bien passé à %d.\n", getNbP(tiut[posIUT]->ldept, posDept));
}
void creationDept(VilleIUT *tiut[], int nb)
{
char iut[30], nomDept[30], nomResp[30];
int posIUT, nbP;
bool trouve;
printf("Dans quel IUT voulez-vous créer un département ?\n> ");
scanf("%s", iut);
posIUT = rechercheVille(tiut, nb, iut, &trouve);
if (trouve == false)
{
printf("Cet IUT n'existe pas. Veuillez réessayer.\n");
return;
}
printf("Entrez le nom du département que vous voulez créer :\n> ");
scanf("%s", nomDept);
rechercheDept(tiut[posIUT]->ldept, nomDept, &trouve);
if (trouve == true)
{
printf("Ce département existe déjà.\n");
return;
}
printf("Entrez le nombre de places dans le département :\n> ");
scanf("%s%*c", &nbP);
printf("Entrez le nom du responsable :\n> ");
fgets(nomResp, 30, stdin);
tiut[posIUT]->ldept = inserer(tiut[posIUT]->ldept, nomDept, nbP, nomResp);
printf("Vous avez créé le département \"%s\", avec %d places. Son représentant est %s.\n", nomDept, nbP, nomResp);
}
int suppressionDept(VilleIUT *tiut[], int nb)
{
char nomDept[30], iut[30], choix;
int posIUT, posDept;
bool trouve;
printf("Dans quel IUT voulez-vous supprimer un département ?\n> ");
scanf("%s", iut);
posIUT = rechercheVille(tiut, nb, iut, &trouve);
if (trouve == false)
{
printf("Cet IUT n'existe pas. Veuillez réessayer.\n");
return nb;
}
printf("Quel département voulez-vous supprimer ?\n> ");
scanf("%s", nomDept);
posDept = rechercheDept(tiut[posIUT]->ldept, nomDept, &trouve);
if (trouve == false)
{
printf("Cet département n'existe pas dans cet IUT. Veuillez réessayer.\n");
return nb;
}
printf("Voulez-vous vraiment supprimer le département %s de l'IUT %s ? (o/N)\n> ", nomDept, iut);
scanf(" %c%*c", &choix);
if (choix == 'o' || choix == 'O')
{
tiut[posIUT]->ldept = supprimer(tiut[posIUT]->ldept, nomDept);
printf("Vous avez bien supprimé le département %s de l'IUT %s.\n", nomDept, iut);
if (vide(tiut[posIUT]->ldept))
{
for (int i = posIUT; i < nb; i++)
{
tiut[i] = tiut[i + 1];
}
free(tiut[nb]);
printf("L'IUT %s a été supprimé car il n'avait plus de départements.\n", iut);
return nb - 1;
}
}
else
{
printf("Vous avez annulé la suppression du département.\n");
}
return nb;
}

@ -11,7 +11,7 @@ void choixMenu(void)
printf("\t1 - Menu utilisateur\n");
printf("\t2 - Menu administrateur\n");
printf("\t9 - Quitter\n");
printf("\nChoix : ");
printf("\nEntrez votre choix :\n> ");
scanf("%d", &choix);
switch (choix)
{
@ -46,7 +46,7 @@ void menuUtilisateur(void)
printf("\t3 - Voir le nombre de places en première année\n");
printf("\t4 - Voir les IUT possédant un département particulier\n");
printf("\t9 - Quitter\n");
printf("\nChoix : ");
printf("\nEntrez votre choix :\n> ");
scanf("%d", &choix);
switch (choix)
{
@ -91,21 +91,21 @@ void menuAdministrateur(void)
printf("\t5 - Stopper la phase de candidature\n");
printf("\t6 - Modifier le responsable d'un département\n");
printf("\t9 - Quitter\n");
printf("\nChoix : ");
printf("\nEntrez votre choix :\n> ");
scanf("%d", &choix);
switch (choix)
{
case 1:
c = true;
//
// modificationNbPDept(tiut, nb);
break;
case 2:
c = true;
//
// creationDept(tiut[], nb);
break;
case 3:
c = true;
//
// suppressionDept(tiut[], nb);
break;
case 4:
c = true;

@ -15,7 +15,8 @@ int chargementVillesIUT(VilleIUT *tiut[])
{
FILE *file = fopen("informationsIUT.txt", "r");
char ville[30], dept[30], resp[30];
int nbP, i = 0, trouve, insertPos;
int nbP, i = 0, insertPos;
bool trouve;
if (file == NULL)
{
printf("Fonction chargementVillesIUT : Problème lors de l'ouverture du fichier informationsIUT.txt");
@ -26,7 +27,7 @@ int chargementVillesIUT(VilleIUT *tiut[])
{
fscanf(file, "%s%s%d", ville, dept, &nbP);
fgets(resp, 30, file);
insertPos = recherche(tiut, i, ville, &trouve);
insertPos = rechercheVille(tiut, i, ville, &trouve);
if (trouve == 0)
{
@ -52,36 +53,17 @@ int chargementVillesIUT(VilleIUT *tiut[])
return i;
}
int recherche(VilleIUT *tiut[], int nb, char val[], int *trouve)
int rechercheVille(VilleIUT *tiut[], int nb, char val[], bool *trouve)
{
int i;
for (i = 0; i < nb; i++)
{
if (strcmp(tiut[i]->ville, val) == 0)
{
*trouve = 1;
*trouve = true;
return i;
}
}
*trouve = 0;
*trouve = false;
return i;
}
void affichageVillesIUT(VilleIUT *tiut[], int nb)
{
printf("Voici les villes qui ont un IUT :\n");
for (int i = 0; i < nb; i++)
{
printf("\t%s\n", tiut[i]->ville);
}
}
void affichageDeptIUT(VilleIUT *tiut[], int nb)
{
printf("Voici les départements présents dans chaque IUT :\n");
for (int i = 0; i < nb; i++)
{
printf("\t%s :\n", tiut[i]->ville);
afficherDept(tiut[i]->ldept);
}
}

@ -6,8 +6,13 @@
/* Fichier */
int chargementVillesIUT(VilleIUT *tiut[]);
int recherche(VilleIUT *tiut[], int nb, char val[], int *trouve);
int rechercheVille(VilleIUT *tiut[], int nb, char val[], bool *trouve);
/* Utilisateur */
void affichageVillesIUT(VilleIUT *tiut[], int nb);
void affichageDeptIUT(VilleIUT *tiut[], int nb);
void affichageDeptIUT(VilleIUT *tiut[], int nb);
/* Administrateur */
void modificationNbPDept(VilleIUT *tiut[], int nb);
void creationDept(VilleIUT *tiut[], int nb);
int suppressionDept(VilleIUT *tiut[], int nb);

@ -66,4 +66,74 @@ void afficherDept(ListeDept l)
bool vide(ListeDept l)
{
return l == NULL;
}
int rechercheDept(ListeDept l, char departement[], bool *trouve)
{
if (vide(l))
{
*trouve = false;
return 0;
}
if (strcmp(departement, l->departement) != 0)
{
*trouve = false;
return 1 + rechercheDept(l->suiv, departement, trouve);
}
if (strcmp(departement, l->departement) == 0)
{
*trouve = true;
return 0;
}
return rechercheDept(l->suiv, departement, trouve);
}
int getNbP(ListeDept l, int pos)
{
for (int i = 0; i < pos; i++)
{
l = l->suiv;
}
return l->nbP;
}
void setNbP(ListeDept l, int pos, int valeur)
{
for (int i = 0; i < pos; i++)
{
l = l->suiv;
}
l->nbP = valeur;
}
ListeDept supprimerEnTete(ListeDept l)
{
MaillonDept *aux;
if (l == NULL)
{
printf("Opération interdite.");
exit(1);
}
aux = l;
l = l->suiv;
free(aux);
return l;
}
ListeDept supprimer(ListeDept l, char departement[])
{
if (l == NULL)
{
return l;
}
if (strcmp(departement, l->departement) < 0)
{
return l;
}
if (strcmp(departement, l->departement) == 0)
{
return supprimerEnTete(l);
}
l->suiv = supprimer(l->suiv, departement);
return l;
}

@ -21,4 +21,10 @@ ListeDept insererEnTete(ListeDept l, char departement[], int nbP, char resp[]);
ListeDept inserer(ListeDept l, char departement[], int nbP, char resp[]);
void afficher(ListeDept l);
bool vide(ListeDept l);
void afficherDept(ListeDept l);
void afficherDept(ListeDept l);
int rechercheDept(ListeDept l, char departement[], bool *trouve);
ListeDept supprimerEnTete(ListeDept l);
ListeDept supprimer(ListeDept l, char departement[]);
int getNbP(ListeDept l, int pos);
void setNbP(ListeDept l, int pos, int valeur);

@ -5,8 +5,11 @@ int main(void)
int nbVilles;
VilleIUT *tiut[100];
nbVilles = chargementVillesIUT(tiut);
//affichageVillesIUT(tiut, nbVilles);
// affichageVillesIUT(tiut, nbVilles);
affichageDeptIUT(tiut, nbVilles);
// modificationNbPDept(tiut, nbVilles);
// creationDept(tiut, nbVilles);
nbVilles = suppressionDept(tiut, nbVilles);
affichageDeptIUT(tiut, nbVilles);
return 0;
}

@ -0,0 +1,20 @@
#include "partie1.h"
void affichageVillesIUT(VilleIUT *tiut[], int nb)
{
printf("Voici les villes qui ont un IUT :\n");
for (int i = 0; i < nb; i++)
{
printf("\t%s\n", tiut[i]->ville);
}
}
void affichageDeptIUT(VilleIUT *tiut[], int nb)
{
printf("Voici les départements présents dans chaque IUT :\n");
for (int i = 0; i < nb; i++)
{
printf("\t%s :\n", tiut[i]->ville);
afficherDept(tiut[i]->ldept);
}
}
Loading…
Cancel
Save