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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NB_ELEVES 2
typedef struct
{
char nom[50];
char prenom[50];
float notes[3];
float moy;
} etudiant;
// PROCEDURES ET FONCTIONS UTILISEES
void init();
void insertion(etudiant classe[NB_ELEVES]);
void affichage(etudiant classe[NB_ELEVES]);
void recherche(etudiant classe[NB_ELEVES], char *lenom);
// Programme pricipal
int main()
{
// VARIABLES GLOBALES
etudiant classe_etu[NB_ELEVES];
int choixMenu;
char nometu[50]; // Nom etudiant à chercher
init(classe_etu); // appel de la procedure init
choixMenu=99;
while( choixMenu != 0 )
{
system( "cls" );
printf("------------------------------\n");
printf("-- Gestion des etudiants\n");
printf("------------------------------\n\n");
printf("\n\n------- Menu Principal -------\n\n");
printf("1 - Insertion des etudiants\n");
printf("2 - Affichage des etudiants\n");
printf("3 - Rechercher un etudiant\n");
printf("0 - Quitter");
printf("\n\n------------------------------\n\n");
// Choix du menu
printf("Votre choix : ");
scanf("%d", &choixMenu );
// Gestion du choix
switch( choixMenu )
{
case 1 : insertion(classe_etu); break;
case 2 : affichage(classe_etu); break;
case 3 : { printf( "Taper le Nom a chercher : " );
scanf( "%s", &nometu );
recherche(classe_etu, nometu);
} ; break;
case 0 : printf("\n\nProgramme termine. Merci"); break;
default : printf( "Mauvais choix...Recommencez\n" );
}
}
return 0;
}
// Fin Programme Principal
// INITIALISATION de la moyenne à -1
void init(etudiant classe[NB_ELEVES])
{
int i;
// On met -1 dans le champ moyenne
for( i = 0 ; i < NB_ELEVES ; i++ )
{
classe[i].moy = -1;
}
}
// INSERTION
void insertion(etudiant classe[NB_ELEVES])
{
int i, nbNotes;
float note, total;
for( i = 0 ; i < NB_ELEVES ; i++ )
{
system( "cls" );
printf( "\n---- Etudiant %d ----\n", i + 1 );
// Nom
printf( "Nom : " );
scanf( "%s", &classe[i].nom );
// Prenom
printf( "Prenom : " );
scanf( "%s", &classe[i].prenom );
classe[i].prenom[0] = toupper( classe[i].prenom[0] );
// Notes
nbNotes = 1;
total = 0;
while( nbNotes <= 3 )
{
// On verifie la saisie de la note
do
{
printf( "Note %d : ", nbNotes );
scanf( "%f", ¬e );
if( note < 0 || note > 20 )
printf( "Une note doit etre comprise entre 0 et 20\n" );
}
while( note < 0 || note > 20 );
// On affecte la note a l eleve
classe[i].notes[nbNotes - 1] = note;
total = total + note;
nbNotes++;
}
// Calcul de la moyenne
classe[i].moy = total / 3;
}
}
// AFFICHAGE
void affichage(etudiant classe[NB_ELEVES])
{
int i, j;
system( "cls" );
// On vérifie si le tableau est remplie
if( classe[0].moy != -1 )
{
for( i = 0 ; i < NB_ELEVES ; i++ )
{
printf( "\n---- Etudiant %d ----\n", i + 1 );
printf( "Nom : %s\n", toupper( classe[i].nom ));
printf( "Prenom : %s\n", classe[i].prenom );
printf( "Notes : " );
for( j = 0 ; j < 3 ; j++ )
{
printf( "%.2f ", classe[i].notes[j] );
}
printf( "\nMoyenne : %.2f\n", classe[i].moy );
printf( "---------------------\n" );
}
}
else
printf( "\nAucun etudiant n a ete insere.\n" );
printf( "\nAppuyez sur touche pour continuer..." );
getch();
}
// Recherche sur le nom d'un étudiant
void recherche(etudiant classe[NB_ELEVES], char *lenom)
{
int i;
int resultat;
i=0;
resultat = strcmp(classe[i].nom, lenom);
while ((resultat !=0) && (i < NB_ELEVES) ) {
i++;
resultat = strcmp(classe[i].nom, lenom);
}
if (strcmp(classe[i].nom, lenom) == 0)
printf( "Le nom cherche : %s a ete trouve au rang %d \n", lenom, i+1);
printf( "Sa moyenne est de %.2f /20 \n",classe[i].moy);
printf( "Taper sur une touche pour continuer .... " );
getch();
} |
Partager