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
| #include<stdio.h>
#include<string.h>
#define N 50
typedef struct Etudiant { char nom[15];
char pren[15];
char sexe[15];
}Etd;
Etd T[N];
int i=0,n;
int inscrit(Etd T[N])
{ printf("***********************Inscription des eleves ***************************\n");
printf("<<<<<<<<<<<<<<<<<<<<Entrez le Nombre des eleves>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("<<<<<<<<<Etudiant %d>>>>>>>>>>>>>\n",i+1);
printf("Entrez son nom :");
scanf("%s",T[i].nom);
printf("Entrez son Prenom :");
scanf("%s",T[i].pren);
printf("Entrez son sexe mas ou fem :");
scanf("%s",T[i].sexe);
}
return n;}
void affiche(Etd T[N])
{
for(i=0;i<n;i++)
{
printf("<<<<<<<<<Eleve %d >>>>>>>>>\n",i+1);
printf("***************************\n");
printf("Son Nom est : %s",T[i].nom);
printf("\n");
printf("Son Prenom est : %s",T[i].pren);
printf("\n");
printf("Son Sexe est : %s",T[i].sexe);
printf("\n");
printf("***************************\n");
}
}
void trie(Etd T[N])
{
int desordre = 1;
char x[15];
while ( desordre !=0 )
{
desordre = 0;
for (i=0;i<n-1;i++)
{
if ( strcmp(T[i].nom, T[i+1].nom)==1 )
{
strcpy (x,T[i+1].nom) ;
strcpy (T[i+1].nom,T[i].nom);
strcpy (T[i].nom, x);
desordre = 1;
}
}
}
}
void cherche(Etd T[N],int n)
{
int INF,SUP,MIL;
char NOMR[15];
printf("**********Recherche d'un Eleve************\n");
printf("Entrez Le nom a chercher : \n");
scanf("%s",NOMR);
INF=0;
SUP=n-1;
while (INF<=SUP)
{
MIL=(SUP+INF)/2;
if (strcmp(NOMR,T[MIL].nom)==-1)
SUP=MIL-1;
else
INF=MIL+1;
}
if (strcmp(NOMR,T[MIL].nom)==0)
printf("L'Etudiant<<<%s>>> est Inscrit \n",NOMR);
else
printf("L'Etudiant <<<%s>>> n' est pas Inscrit \n",NOMR);
}
int Nombrefille(Etd T[N])
{
int F=0;
for(i=0;i<n;i++)
{
if(strcmp(T[i].sexe,"fem")==0)
F++;
}
printf("Le Nombre des filles est %d \n",F);
return F;
}
int main()
{
int choix,n;
n=inscrit(T);
do
{
printf("********************************Menu***************************************\n");
printf("* Tapez 1 si vous voulez Afficher les eleves incrits *\n");
printf("* Tapez 2 si vous voulez Trier les eleves par ordre alphabetique *\n");
printf("* Tapez 3 si vous voulez Recherche si un eleve est inscrit *\n");
printf("* Tapez 4 si vous voulez Savoir combien de filles existent dans la classe *\n");
printf("* Tapez 5 si vous voulez Quitter *\n");
printf("***************************************************************************\n");
scanf("%d",&choix);
switch(choix)
{
case 1:affiche(T);break;
case 2:trie(T);break;
case 3:cherche(T,n);break;
case 4:Nombrefille(T);affiche(T);break;
case 5: default:break;
}
}
while (choix!=5);
return 0;
} |
Partager