ajout fonction de mises a jour commencées

master
Maël DAIM 3 years ago
parent 9eb0d6fe52
commit 60d372470b

201
Msae.c

@ -56,52 +56,47 @@ int login(void)
//################# fonctions affichage ########################### //################# fonctions affichage ###########################
void afficherPlace(MaillonDept m) void afficherPlace(Departement d)
{ {
printf("\nPour ce département il y a %d places en 1ère année \n\n",m.nbP); printf("\nPour ce département il y a %d places en 1ère année \n\n",d.nbP);
} }
/* void afficherVilleDep(VilleIUT v)
//################## fonctions insertion #########################
int insererDept(VilleIUT v, MaillonDept m)
{ {
int trouve; ListeDept l;
MaillonDept *pos; printf("_________________________________________________________________________________________________________________\n");
pos=rechercheDept(v.lDept,&trouve,m.dept); printf("| Ville | Département |\n");
if(trouve==0) printf("|----------------------------------|----------------------------------------------------------------------------|\n");
l = v.lDept;
while(l != NULL)
{ {
printf("\nDépartement déjà présent dans cet IUT\n") printf("| %-32s | %-32s | %3d | %-32s |\n", v.nom, l->d.dept, l->d.nbP, l->d.respAd);
return -1; printf("|----------------------------------|----------------------------------------------------------------------------|\n");
l = l->suiv;
} }
m->suiv=pos;
pos=&m;
return 1;
} }
void afficherDep(Departement d)
//################# fonctions recherche #########################
MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[])
{
while(lDept->suiv!=NULL)
{
if(strcmp(nom,lDept->dept)==0)
{ {
*trouve=1; printf("_____________________________________________________________________________\n");
return lDept; printf("| Département |\n");
printf("|----------------------------------------------------------------------------|\n");
printf("| %-32s | %3d | %-32s |\n", d.dept, d.nbP, d.respAd);
printf("|----------------------------------------------------------------------------|\n");
} }
if(strcmp(nom,lDept->dept)<0)
//################ fonction liste ######################################
bool vide(ListeDept lDept)
{ {
*trouve=0; if(lDept == NULL)
return lDept; return true;
} return false;
lDept=lDept->suiv;
}
*trouve=0;
return lDept;
} }
*/
//################# fonctions recherche #########################
int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve) int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve)
{ {
@ -124,3 +119,141 @@ int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve)
return inf; return inf;
} }
ListeDept rechercherDept(ListeDept lDept, char dept[], int *trouve)
{
if(vide(lDept))
{
*trouve = 0;
return lDept;
}
if(strcmp(dept, lDept->d.dept) < 0)
{
trouve = 0;
return lDept;
}
if(strcmp(dept,lDept->d.dept) == 0)
{
*trouve = 1;
return lDept;
}
return rechercherDept(lDept->suiv, dept, trouve);
}
//#################### fonction mise à jour ############################
/*void miseAJourPlaces(VilleIUT *tiut[], int tLog)
{
int places;
char ville[31], dept[31], choix;
ListeDept l;
printf("Dans quelle ville se situe le département concerné ?\nSaisie : ");
scanf("%s%*c", ville);
printf("\n");
pos = rechercheIUT(tiut, tLog, ville, &trouve);
while(trouve == 0)
{
printf("Cette ville n'existe pas, veuillez re-saisir : ");
scanf("%s%*c", ville);
printf("\n");
pos = rechercheIUT(tiut, tLog, ville, &trouve);
}
l = tiut[pos]->lDept;
printf("Quel département souhaitez-vous mettre à jour ?\nSaisie : ");
scanf("%s%*c", dept);
printf("\n");
l = rechercherDept(l, dept, &trouve);
while(trouve == 0)
{
printf("Ce département n'existe pas, veuillez-resaisir : ");
scanf("%s%*c", dept);
printf("\n");
l = rechercherDept(l, dept, &trouve);
}
printf("Vous avez sélectionné le département %s dans la ville de %s.\nSouhaitez-vous continuez ? (O/N)\nSaisie : ", dept, ville);
scanf("%c%*c", &choix);
printf("\n");
if(choix == 'N')
{
return;
}
printf("Il y a actuellement %d places.\nQuel est le nouveau nombre de places ?\nSaisie : ", l->d.nbP);
scanf("%d%*c", &places);
printf("\nVous avez saisie %d places, veuillez confirmez (O/N)\nSaisie : ", places);
scanf("%c%*c", &choix);
printf("\n");
if(choix == 'O')
{
l->d.nbP = places;
printf("La mise à jour a bien été effectuée.\n");
}
return;
}*/
void miseAJourNomDept(Departement d,ListeDept l)
{
int trouve;
char nomDept[31],choix='n';
system("clear");
afficherDep(d);
while(choix!='o')
{
printf("\n\nQuel est le nouveau nom du département?\n");
fgets(nomDept,31,stdin);
nomDept[strlen(nomDept)-1]='\0';
rechercherDept(l,nomDept,&trouve);
if(trouve==1)
}
}
void miseAJourGlobale(VilleIUT *tiut[], int tLog)
{
int trouve,pos,choix=0;
char ville[31],dept[31];
MaillonDept *m;
Departement d;
printf("Dans quelle ville voulez-vous faire des mises à jour?\t");
scanf("%s",ville);
pos=rechercheIUT(tiut,tLog,ville,&trouve);
if(trouve!=1)
{
printf("\n\nCette ville n'existe pas\n");
clearpage();
return;
}
afficherVilleDep(*tiut[pos]);
printf("Quel département de %s voulez-vous modifier?\t",ville);
scanf("%s",dept);
m=rechercherDept(tiut[pos]->lDept,dept,&trouve);
d=m->d;
if(trouve!=1)
{
printf("\n\nCe département n'existe pas dans cette ville\n");
clearpage();
return;
}
afficherDep(d);
printf("\n\n");
while(choix!=9)
{
printf("################### Menu des mises à jour ###################\n");
printf("\n\t1.Mise à jour du nom du département\n\t2.Mise à jour des places du département\n\t3.Mise à jour du responsable du département\n\t9.Quitter\n\n");
printf("\tSaisie:\t");
scanf("%d",&choix);
if(choix==1)
{
miseAJourNomDept(d,tiut[pos]->lDept);
}
if(choix==2)
{
miseAJourPlaces(d);
}
if(choix==3)
{
miseAJourResp(d);
}
}
clearpage();
afficherDep(d);
}

@ -5,21 +5,24 @@
//######### Définition des types ############# //######### Définition des types #############
typedef struct maillonDept typedef struct
{ {
char dept[31]; char dept[31];
int nbP; int nbP;
char respAd[31]; char respAd[31];
struct mailllonDept *suiv; }Departement;
}MaillonDept,*ListeDept; typedef struct maillonDept
{
Departement d;
struct maillonDept *suiv;
}MaillonDept,*ListeDept;
typedef struct typedef struct
{ {
char nom[31]; char nom[31];
ListeDept lDept; ListeDept lDept;
}VilleIUT; }VilleIUT;
//########## fonction commune ############### //########## fonction commune ###############
@ -29,14 +32,28 @@ void clearpage(void);
//########## fonction affichage ############## //########## fonction affichage ##############
void afficherPlace(MaillonDept m); void afficherPlace(Departement d);
void afficherDep(Departement d);
void afficherVilleDep(VilleIUT v);
//########## fonction admin ################# //########## fonction de mise à jour ###########
int insererDept(VilleIUT v, MaillonDept m); void miseAJourGlobale(VilleIUT *tiut[], int tLog);
void miseAJourNomDept(Departement d,ListeDept l);
void miseAJourResp(Departement d);
void miseAJourPlaces(Departement d);
//######### fonction recherche ############## //########## fonction de recherche ##############
MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[ ] ); ListeDept rechercherDept(ListeDept lDept, char dept[], int *trouve);
int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve); int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve);
//########## fonction liste ##############
ListeDept listenouv(void);
ListeDept InsererEntete(ListeDept l,int nb);
ListeDept Inserer(ListeDept l, int x);
ListeDept supprimerEntete(ListeDept l);
ListeDept supprimer(ListeDept l, int x);
int longueur(ListeDept l);
bool vide(ListeDept l);
ListeDept ajouterEnqueue(ListeDept l, int x);
int tete(ListeDept l);

@ -2,22 +2,6 @@
int main(void) int main(void)
{ {
VilleIUT* tiut[20];
VilleIUT a,b,c,d;
char test[20];
int trouve, pos;
strcpy(a.nom,"Clermont");
strcpy(b.nom,"Lyon");
strcpy(c.nom,"Paris");
a.lDept = NULL;
b.lDept = NULL;
c.lDept = NULL;
tiut[0] = &a;
tiut[1] = &b;
tiut[2] = &c;
printf("Quel IUT cherchez-vous?\t");
scanf("%s",test);
pos = rechercheIUT(tiut,4,test,&trouve);
printf("%d %d\n",pos,trouve);
return 0; return 0;
} }

Loading…
Cancel
Save