1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| #include<iostream.h>
#include<string.h>
#include<malloc.h>
#include<stdio.h>
struct elevnot
{
char eleve[20];
int note;
};
struct liste
{
elevnot * releve;
int nbmax;
int nb;
};
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 : \n");
scanf("%s",&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 %s\n",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 supprime(char mot[])
{
int i;
for (i=0;i<bulletin.nb;i++)
{
if (strcmp(bulletin.releve[i].eleve,mot)==0)
{
bulletin.releve[i]=bulletin.releve[bulletin.nb-1];
bulletin.nb--;
}
}
}
void viretout()
{
free(bulletin.releve);
initliste();
}
void showmethenotes()
{
int i;
for (i=0;i<bulletin.nb;i++)
{
printf("NOM : %s NOTE : %d/20\n",bulletin.releve[i].eleve,bulletin.releve[i].note);
}
}
void whatsthemoyenne()
{
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 : %d\n",moyenne);
}
//void main()
int main(void)
{
int choix,i;
char nom[20];
do
{
printf(" ---------------\n");
printf(" | Menu |\n");
printf(" ---------------\n\n\n");
printf("1. Ajouter une note\n");
printf("2. Supprimer une note au nom de\n");
printf("3. Afficher les notes\n");
printf("4. Afficher la moyenne\n");
printf("5. Supprimer toutes les notes\n");
printf("6. Quitter\n");
printf("Votre choix : \n");
scanf("%d",&choix);
switch(choix)
{
case 1: ajoute();
break;
case 2: printf("Quel nom ? \n");scanf("%s",&nom[i]);
supprime(nom);
break;
case 3: showmethenotes();
break;
case 4: whatsthemoyenne();
break;
case 5: viretout();
break;
case 6: viretout();
break;
};
} while (choix!=6);
} |
Partager