Académique Documents
Professionnel Documents
Culture Documents
h>
#include<string.h>
#include<malloc.h>
#include<conio.h>
typedef struct elevnot
{
char eleve[20];
int note;
};
liste bulletin;
void initliste()
{
bulletin.releve=NULL;
bulletin.nbmax=0;
bulletin.nb=0;
}
void ajoute()
{
int r=0,i;
elevnot * inter;
elevnot ajout;
bool sortir;
do
{
printf("Veuillez entrer le nom de l'\202l\212ve : ");
scanf ("%d",&ajout.eleve);
sortir=true;
for (i=0;i<bulletin.nb;i++)
{
if(strcmp(bulletin.releve[i].eleve,ajout.eleve)==0)
{sortir=false;}
}
}while (sortir==false);
do
{
printf("Veuillez entrer la note de : ",ajout.eleve );
scanf("%d",&ajout.note);
}while ((ajout.note<0)||(ajout.note>20));
if(bulletin.nb<bulletin.nbmax)
{bulletin.releve[bulletin.nb]=ajout;
bulletin.nb++;}
else
{
inter=(elevnot *)malloc((bulletin.nbmax+5)*sizeof(elevnot));
if(inter==NULL) r=-1;
else
{
for(i=0;i<bulletin.nb;i++)inter[i]=bulletin.releve[i];
bulletin.nbmax=bulletin.nbmax+5;
free(bulletin.releve);
bulletin.releve=inter;
bulletin.releve[bulletin.nb]=ajout;
bulletin.nb++;
}
}
}
void viretout()
{
free(bulletin.releve);
initliste();
}
void donnenotes()
{
int i;
for (i=0;i<bulletin.nb;i++)
{
printf("NOM : , NOTE : /20",bulletin.releve[i].eleve);
}
}
void quelleestlamoyenne()
{
int i;
double moyenne=0;
for (i=0;i<bulletin.nb;i++) moyenne+=bulletin.releve[i].note;
moyenne=moyenne/bulletin.nb;
if (bulletin.nb!=0) printf("MOYENNE : ",moyenne);
}
main()
{
int choix;
char nom[20];
do
{
printf("pour Ajouter une note taper 1");
printf("pour Supprimer une note taper 2 ");
printf("pour Afficher les notes taper 3");
printf("pour Afficher la moyenne taper4");
printf("pour Supprimer toutes les notes taper5");
printf("pour Quitter taper6");
printf("Votre choix : "),choix;
switch(choix)
{
case 1: ajoute();
break;
case 2: printf("Quel nom ? ",nom);
supprime(nom);
break;
case 3: donnenotes();
break;
case 4: quelleestlamoyenne();
break;
case 5: viretout();
break;
case 6: viretout();
break;
};
} while (choix!=6);
getch ();
return 0;
}