Demande de correction de programme

gemini010 Messages postés 12 Date d'inscription dimanche 27 octobre 2002 Statut Membre Dernière intervention 13 mars 2005 - 2 avril 2003 à 13:39
gemini010 Messages postés 12 Date d'inscription dimanche 27 octobre 2002 Statut Membre Dernière intervention 13 mars 2005 - 3 avril 2003 à 11:31
slt a tous, je dois créer un programme avec differente fonctions et structures permettant de gerer des etudiants ( on doit pouvoir ajouter des enregistrements, lister les enregistement,les modifier, faire une recherche sur un etudiant et aussi pouvoir faire des suppressions.

ca serait sympa si qqun pouvait corriger ce code et l'améliorer si possible :)

g notament qque probleme
pour le listage:
s'il n'y a qu'un seul enregistement ----) il y a pas de prob mais s'il y en a plus, seul le dernier s'affiche :(

pour la modification d'un enregistrement:
si une cote est > 10 et que je souhaite mettre une cote<10 il y a un probleme a l'affichage .

merci pour votre aide

voici le code

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

/*Déclarations des types ------------------------------------*/
struct Resultat

{
int Total;
float Pourcentage;
char Grade[20];
};

struct Eleve
{
char Nom[25];
char Prenom[25];
char Sexe;
char Formation [20];
int Cotes[4];
struct Resultat Res;
};

/* déclaration des fonctions --------------------------------*/
char execmenu();
void affgrille(int);
void encodeleve(struct Eleve *t,int);
void calculeleve(struct Eleve *);
void affeleve(struct Eleve ,int);
void afftoteleve(struct Eleve ,int);
void AjoutFich(struct Eleve[], int*);
int verif(char []);
int verifcote(char Cotes[]);
void ListFich(struct Eleve[], int);

void ChercheFich(struct Eleve[], int);
void ModificationFich(struct Eleve[], int);
void SuppressionFich(struct Eleve[], int*);
void modifeleve(struct Eleve *,int);
void modifich(struct Eleve [],int);
int chercheleve(struct Eleve [],char [],char []);

/* fonction principale --------------------------------------*/
void main ()

{
struct Eleve tab[10];
char choi;
int nbre=0;

do
{
choi=execmenu();
switch(choi)
{
case 'A':AjoutFich(tab,&nbre);break;
case 'L':ListFich(tab,nbre);break;
case 'M':modifich(tab,nbre);break;
case 'R':ChercheFich(tab,5);break;
case 'S':SuppressionFich(tab,&nbre);break;
}

}
while (choi!='Q');
}
/* fonction execmenu ----------------------------------------*/

char execmenu()

{
char choix;
clrscr();
printf("\n\n\n\n\n\n\n\n");
printf(" **********************************\n");
printf(" * jouter un enregistrement *\n");
printf(" * <L>ister un fichier *\n");
printf(" * <M>odifier un enregistrement *\n");
printf(" * <R>echercher un enregistrement *\n");
printf(" * <S>upprimer un enregistrement *\n");
printf(" * <Q>uitter *\n");
printf(" * Votre choix : *\n");
printf(" **********************************");
do
{
choix=toupper(getch());
}
while(!strchr("A,L,M,R,S,Q",choix));

return choix;
}

/*fonction d'affichage du masque de saise -------------------*/

void affgrille(int position)
{
clrscr();
gotoxy(0,position);printf("Nom :.........................");
gotoxy(36,position);printf("Prénom :.........................");
gotoxy(0,position+1);printf("Sexe :.");
gotoxy(36,position+1);printf("Formation :.........................");
gotoxy(0,position+2);printf("Cotes :.., .., .., ..");
}
/*fonction d'encodage de l'élève ----------------------------*/

void encodeleve(struct Eleve *t,int position)
{
int flag=0,longueur;
char temp[25],tempo[2];
do
{
gotoxy(8,position);gets(t->Nom);strupr(t->Nom);
strcpy(temp,t->Nom);
flag=verif(temp);
longueur = strlen(t->Nom);
}
while (!flag &&( longueur>0 || longueur<26 ));
flag=0;
do
{
gotoxy(47,position);gets(t->Prenom);strupr(t->Prenom);
strcpy(temp,t->Prenom);
flag=verif(temp);
longueur = strlen(t->Prenom);
}
while (!flag && (longueur>0 || longueur<26));
do
{
gotoxy(8,position+1);t->Sexe=toupper(getchar());fflush(stdin);
}
while (t->Sexe != 'M' && t->Sexe != 'F');

do
{
gotoxy(47,position+1);gets(t->Formation);strupr(t->Formation);
strcpy(temp,t->Formation);
flag=verif(temp);
longueur = strlen(t->Formation);
}
while (!flag && (longueur>0 || longueur<26));
do
{
gotoxy(8,position+2);gets(tempo);
flag=verifcote(tempo);
}
while (!flag);
t->Cotes[0]=atoi(tempo);
do
{
gotoxy(12,position+2);gets(tempo);
flag=verifcote(tempo);
}
while (!flag);
t->Cotes[1]=atoi(tempo);
do
{
gotoxy(16,position+2);gets(tempo);
flag=verifcote(tempo);
}
while (!flag);
t->Cotes[2]=atoi(tempo);
do
{
gotoxy(20,position+2);gets(tempo);
flag=verifcote(tempo);
}
while (!flag);
t->Cotes[3]=atoi(tempo);

}
/*fonction calcul point eleve -------------------------------*/

void calculeleve(struct Eleve *t)
{
t->Res.Total=t->Cotes[0]+t->Cotes[1]+t->Cotes[2]+t->Cotes[3];
t->Res.Pourcentage=float(t->Res.Total)/8*10;
if (t->Res.Pourcentage>=90)
strcpy(t->Res.Grade,"Plus grande distinction");
else
if (t->Res.Pourcentage>=80)
strcpy(t->Res.Grade,"Grande distinction");
else
if (t->Res.Pourcentage>=70)
strcpy(t->Res.Grade,"Distinction");
else
if (t->Res.Pourcentage>=60)
strcpy(t->Res.Grade,"Satisfaction");
else
if (t->Res.Pourcentage>=50)
strcpy(t->Res.Grade,"Balance");
else
strcpy(t->Res.Grade,"Ajourné");
}
/*fonction d'affichage élève --------------------------------*/
void affeleve(struct Eleve t,int position)
{
gotoxy(8,position);puts(t.Nom);
gotoxy(47,position);puts(t.Prenom);
gotoxy(8,position+1);printf("%c",t.Sexe);
gotoxy(47,position+1);puts(t.Formation);
gotoxy(8,position+2);printf("%d, %d, %d, %d",t.Cotes[0],t.Cotes[1],t.Cotes[2],t.Cotes[3]);
}

/*fonction d'affichage du total de élève --------------------*/

void afftoteleve(struct Eleve t,int position)
{
gotoxy(0,position);printf("Total : %d",t.Res.Total);
gotoxy(15,position);printf("Pourcentage : %.2f",t.Res.Pourcentage);
gotoxy(40,position);printf("Grades : %s",t.Res.Grade);
}

/*fonction d'ajout de fiche ---------------------------------*/

void AjoutFich(struct Eleve t[],int *nbrele)
{
clrscr();
if (*nbrele<10)
{
affgrille(5);
encodeleve(&t[*nbrele],5);
calculeleve(&t[*nbrele]);
affeleve(t[*nbrele],5);
afftoteleve(t[*nbrele],10);
getch();
(*nbrele)++;
}
else
{
clrscr();
gotoxy(30,10);printf("Pas de place pour ajouter un nouvel enregistrement");getch();
}
}
/*fonction de verification de l'encodage --------------------*/
int verif(char t[])
{

char *flag,a;
int longueur,i;
flag=NULL;
if (t[0]=='\0')
return 0;
for (i=1;i<32;i++)
{
flag=strchr(t,i);
if (flag!=NULL)
{i=32;return 0;}
}
for (i=33;i<44;i++)
{
flag=strchr(t,i);
if (flag!=NULL)
{i=44;return 0;}
}
for (i=46;i<65;i++)
{
flag=strchr(t,i);
if (flag!=NULL)
{i=65;return 0;}
}
for (i=91;i<=255;i++)
{
flag=strchr(t,i);
if (flag!=NULL)
{i=256;return 0;}
}
longueur = strlen(t);
if (t[0]==' ' || t[0]=='-' || t[longueur-1]==' ' || t[longueur-1]=='-')
flag=&a;
if (flag==NULL)
return 1;
else
return 0;

}
/*fonction de verification des cotes ------------------------*/
int verifcote(char cote[])
{
int i;
i=atoi(cote);
if (i>=0 && i <=20)
return 1;
else
return 0;
}
/*fonction de listage de fiche ------------------------------*/
void ListFich(struct Eleve t[],int nbrele)
{
int i=0,cpt=0;
while (i<nbrele)
{
clrscr();
while (cpt<=3 && i<nbrele)
{
affgrille(cpt*6+1);
affeleve (t[i],cpt*6+1);
afftoteleve(t[i],cpt*6+5);
cpt++;i++;
}
getch();cpt=0;
}
}
/*fonction de recherche de fiche ----------------------------*/
void ChercheFich(struct Eleve t[],int posi)
{
char nom[25],prenom[25];
int flag=-1;
clrscr();
gotoxy(20,13);printf("Nom:");gets(nom);
gotoxy(20,14);printf("Prénom:");gets(prenom);strupr(nom);strupr(prenom);
flag=chercheleve(t,nom,prenom);
if (flag>-1 && nom[0]!='\0' && prenom[0]!='\0')
{
clrscr();
affgrille(5);
affeleve(t[flag],5);
afftoteleve(t[flag],10);
}
else
{
gotoxy(20,15);printf("L'élève n'existe pas");
}
getch();
}

/*fonction de modification des fiches -----------------------*/

void modifich(struct Eleve t[],int nbrele)
{

char nom[25],prenom[25];
int flag=-1;
clrscr();
gotoxy(20,13);printf("Nom:");gets(nom);
gotoxy(20,14);printf("Prénom:");gets(prenom);strupr(nom);strupr(prenom);
flag=chercheleve(t,nom,prenom);
if (flag>-1 && nom[0]!='\0' && prenom[0]!='\0')
{
clrscr();
affgrille(5);
affeleve(t[flag],5);
modifeleve(&t[flag],5);
calculeleve(&t[flag]);
afftoteleve(t[flag],10);
}
else
{
gotoxy(20,15);printf("L\'élève n'existe pas");
}
getch();
}
/*fonction de suppression de fiche --------------------------*/
void SuppressionFich(struct Eleve t[],int *nbrele)
{
char nom[25],prenom[25],rep;
int flag=-1,cpt=0;
clrscr();
gotoxy(20,13);printf("Nom à supprimer:");gets(nom);
gotoxy(20,14);printf("Prénom à supprimer:");gets(prenom);strupr(nom);strupr(prenom);
flag=chercheleve(t,nom,prenom);
if (flag>-1 && nom[0]!='\0' && prenom[0]!='\0')
{
clrscr();
affgrille(5);
affeleve(t[flag],5);
afftoteleve(t[flag],10);
gotoxy(20,20);printf("Voullez-vous supprimer cet enregistrement<O/N>?");
rep=toupper(getch());

if (rep=='O' || rep=='N')
cpt=flag;
while (cpt<*nbrele)
{
t[flag]=t[flag+1];
cpt++;
}
(*nbrele)--;
}
else
{
gotoxy(20,15);printf("L\'élève n'existe pas");getch();
}
}

/*fonction de modification de l'élève -----------------------*/
void modifeleve(struct Eleve *t,int position)
{
char rep[25],reponse,tempo[2],temp[25];
int r,flag=0,longueur;
do
{
gotoxy(8,position);gets(rep);strupr(rep);
flag=verif(rep);
longueur = strlen(rep);
}
while (!flag && longueur>1 && longueur<25 );
flag=0;
if (rep[0]!='\0')
strcpy(t->Nom,rep);
do
{
gotoxy(47,position);gets(rep);strupr(rep);
flag=verif(rep);
longueur = strlen(rep);
}
while (!flag && longueur>1 && longueur<25 );
flag=0;
if (rep[0]!='\0')
strcpy(t->Prenom,rep);
do
{
gotoxy(8,position+1);reponse=toupper(getchar());fflush(stdin);
}
while (reponse != 'F' && reponse != 'M' && reponse!='\n');
if (reponse!='\n')
t->Sexe=reponse;
do
{
gotoxy(47,position+1);gets(rep);strupr(rep);
flag=verif(rep);
longueur = strlen(rep);
}
while (!flag && longueur>1 && longueur<25 );
flag=0;
if (rep[0]!='\0')
strcpy(t->
Formation,rep);
do
{
gotoxy(8,position+2);gets(tempo);
flag=verifcote(tempo);
}
while (!flag);

if (tempo[0]!='\0')
t->Cotes[0]=atoi(tempo);
do
{
gotoxy(12,position+2);gets(tempo);
flag=verifcote(tempo);
}
while (!flag);
if (tempo[0]!='\0')
t->Cotes[1]=atoi(tempo);
do
{
gotoxy(16,position+2);gets(tempo);
flag=verifcote(tempo);
}
while (!flag);
if (tempo[0]!='\0')
t->Cotes[2]=atoi(tempo);
do
{
gotoxy(20,position+2);gets(tempo);
flag=verifcote(tempo);
}
while (!flag);
if (tempo[0]!='\0')
t->Cotes[3]=atoi(tempo);
}

/*fonction de recherche d'élève -----------------------------*/

int chercheleve(struct Eleve t[],char nom[],char prenom[])
{
int i,retour=0;
for (i=0;i<10;i++)
if (!strcmp(t[i].Nom,nom) && !strcmp(t[i].Prenom,prenom))
return i;
else
retour=-1;
return retour;
}

Gemini

1 réponse

gemini010 Messages postés 12 Date d'inscription dimanche 27 octobre 2002 Statut Membre Dernière intervention 13 mars 2005
3 avril 2003 à 11:31
personne pour m'aider? :(
0
Rejoignez-nous