Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

SONDAGE ELECTIONS PRESIDENTIELLES LANGAGEC


Information sur la source

Catégorie :.Net Niveau : Débutant Date de création : 20/06/2002 Date de mise à jour : 20/06/2002 19:03:14 Vu : 1 993

Note :
Aucune note

Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

Description

Utilisation de structures de fichiers: ecriture et lecture, des fonctions.
Ce programme comporte un menu de presentation, des saisies de chaines de caracteres et des lecture de chaines de caracteres. Une fonction qui evite les doublons(=redondance des personnes saisies). Une fonction statistique qui serait à améliorer.  Note: 16/20.
 

Source

  • #include <stdio.h>
  • #include <conio.h>
  • #include <string.h>
  • #define LGNOM 20
  • #define LGPRENOM 15
  • #define LGTEL 11
  • #define LGMOIS 25
  • #define LGJOUR 3
  • #define LGANNEE 5
  • #define LGNOMCHER 20
  • #define LGVERIFNOM 20
  • #define LGVERIFPRENOM 15
  • #define LGNOM1 20
  • #define LGPRENOM1 15
  • #define LGCANDIDAT 3
  • int i;
  • float somme=0;
  • FILE *sortie;
  • struct { char nom[LGNOM+1];
  • char prenom[LGPRENOM+1];
  • char jour[LGJOUR+1];
  • char mois[LGMOIS+1];
  • char annee[LGANNEE+1];
  • char tel[LGTEL+1];
  • char candidat[LGCANDIDAT+1];
  • }fait;
  • FILE *entree;
  • char * tampon;
  • char * nomfic="c:\meaux2.dat";
  • void main (void)
  • {
  • void introduction (void);
  • void menu (void);
  • void saisie (void);
  • void lecture (void);
  • void liste (void);
  • void verif (void);
  • void statistique (void);
  • clrscr();
  • introduction();
  • getch();
  • clrscr();
  • menu();
  • getch();
  • }
  • void introduction (void)
  • {
  • clrscr();
  • printf ("\n\n\n\n\n\n\n\n\t\t\tB I E N V E N U E.");
  • getch();
  • clrscr();
  • printf ("\n\n\n\n\n\n\n\n\n\t\tSondage pour les ,lections pr,sidentielles.");
  • getch();
  • }
  • void menu (void)
  • {
  • int n;
  • printf ("\n\t\t\t\tMenu G,n,ral\n\n\n\n");
  • printf ("\t\t1) Vous voulez vous inscrire.\n\n\n");
  • printf ("\t\t2) Rechercher une personne.\n\n\n");
  • printf ("\t\t3) Impression de la liste d'inscription.\n\n\n");
  • printf ("\t\t4) V,rifiez si vous ^tes d,j. inscrit.\n\n\n");
  • printf ("\t\t5) Stat:\n\n\n");
  • printf ("\nVotre choix:");
  • scanf("%d",&n);
  • if (n==1)
  • {
  • clrscr();
  • saisie();
  • getch();
  • }
  • if (n==2)
  • {
  • clrscr();
  • lecture();
  • getch();
  • }
  • if (n==3)
  • {
  • clrscr();
  • liste();
  • getch();
  • }
  • if (n==4)
  • {
  • clrscr();
  • verif();
  • getch();
  • }
  • if(n==5)
  • {
  • clrscr();
  • statistique();
  • getch();
  • }
  • }
  • void saisie (void)
  • {
  • sortie=fopen (nomfic,"a");
  • printf ("Entrez un nom en MAJUSCULES lors de la saisie.");
  • printf ("\n\nLaisser un nom VIDE . la fin de chaque saisie.");
  • gets (tampon);
  • while (printf ("\n\nNom:"), gets (fait.nom), strlen (fait.nom))
  • {
  • printf ("Pr,nom:");
  • scanf ("%s",&fait.prenom);
  • printf ("Jour:");
  • scanf ("%s",&fait.jour);
  • printf ("Mois:");
  • scanf ("%s",&fait.mois);
  • printf ("Ann,e:");
  • scanf ("%s",&fait.annee);
  • printf ("T,l,phone:");
  • scanf ("%s",&fait.tel);
  • printf ("Candidat LJ, JC, LP, RH, AL, NM:");
  • scanf ("%s",&fait.candidat);
  • fwrite (&fait, sizeof(fait), 1, sortie);
  • }
  • fclose (sortie);
  • }
  • void verif (void)
  • {
  • int intrus;
  • char verifnom[LGVERIFNOM+1];
  • char verifprenom[LGVERIFPRENOM+1];
  • char nom1[LGNOM1+1];
  • char prenom1[LGPRENOM1+1];
  • printf ("Entrer un nom et un prenom puis le prenom et le nom . v,rifier:");
  • scanf ("%s%s%s%s",&verifnom,&verifprenom,&prenom1,&nom1);
  • intrus=0;
  • entree=fopen (nomfic,"r");
  • do
  • {
  • fread (&fait, sizeof(fait), 1, entree);
  • if (((strcmp (verifnom, fait.nom)==0)&&(strcmp (verifprenom, fait.prenom)==0))||((strcmp (prenom1,fait.prenom)==0)&&(strcmp (nom1,fait.nom)==0)))
  • intrus=1;
  • }
  • while ((!intrus)&&(!feof (entree)));
  • if (intrus)
  • {
  • printf ("Vous ^tes d,j. inscrit.");
  • }
  • else
  • {
  • printf ("Inscrivez vous.");
  • menu();
  • }
  • fclose (entree);
  • }
  • void lecture (void)
  • {
  • char nomcher[LGNOMCHER+1];
  • int trouve;
  • entree=fopen (nomfic,"r");
  • printf ("Nom cherch,:");
  • scanf ("%s",&nomcher);
  • trouve=0;
  • do
  • {
  • fread (&fait, sizeof(fait), 1, entree);
  • if (strcmp (nomcher, fait.nom)==0)
  • trouve=1;
  • }
  • while ((!trouve)&&(!feof (entree)));
  • if (trouve)
  • {
  • printf ("prenom:%s\n",fait.prenom);
  • printf ("jour:%s\n",fait.jour);
  • printf ("mois:%s\n",fait.mois);
  • printf ("annee:%s\n",fait.annee);
  • printf ("t,l,phone:%s\n",fait.tel);
  • printf ("candidat:%s\n",fait.candidat);
  • }
  • else
  • printf ("Ce nom ne figure pas dans la base de donn,es.");
  • fclose (entree);
  • }
  • void liste (void)
  • {
  • entree=fopen (nomfic,"r");
  • printf ("\t\t\tListe des personnes inscrites.");
  • printf ("\n\n\n\tNom\tPr,nom\tJour\tMois\tAnnee\tT,l,phone\tCandidat");
  • while (fread (&fait, sizeof(fait), 1, entree), !feof(entree))
  • {
  • printf ("\n\t%s %s %s %s %s %s %s",fait.nom,fait.prenom,fait.jour,fait.mois,fait.annee,fait.tel,fait.candidat);
  • }
  • fclose (entree);
  • /*printf ("Impression de la liste");
  • fprintf (stdprn,"Liste des personnes inscrites");*/
  • }
  • void statistique (void)
  • {
  • float somme_LJ=0, somme_JC=0, somme_LP=0, somme_RH=0, somme_AL=0, somme_NM=0,som;
  • float pourcentage_LJ, pourcentage_JC, pourcentage_LP, pourcentage_RH, pourcentage_AL, pourcentage_NM;
  • entree=fopen (nomfic,"r");
  • do
  • {
  • fread (&fait, sizeof (fait), 1, entree);
  • if (fait.nom)
  • {
  • somme=somme+1;
  • printf ("\n\t%s",fait.nom);
  • printf ("\n%f",somme);
  • }
  • if (strcmp (fait.candidat,"LJ")==0)
  • {
  • somme_LJ=somme_LJ+1;
  • pourcentage_LJ=(somme_LJ/somme)*100;
  • printf ("\n%s",fait.candidat);
  • printf ("\t%f",somme);
  • printf ("\%f",somme_LJ);
  • printf ("\n%f",pourcentage_LJ);
  • }
  • if (strcmp (fait.candidat,"JC")==0)
  • {
  • somme_JC=somme_JC+1;
  • pourcentage_JC=(somme_JC/somme)*100;
  • printf ("\n%s",fait.candidat);
  • printf ("\t%f",somme);
  • printf ("\n%f",somme_JC);
  • printf ("\n%f",pourcentage_JC);
  • }
  • if (strcmp (fait.candidat,"LP")==0)
  • {
  • somme_LP=somme_LP+1;
  • pourcentage_LP=(somme_LP/somme)*100;
  • printf("\n%s",fait.candidat);
  • printf ("\t%f",somme);
  • printf ("\n%f",somme_LP);
  • printf ("\n%f",pourcentage_LP);
  • }
  • if (strcmp (fait.candidat,"RH")==0)
  • {
  • somme_RH=somme_RH+1;
  • pourcentage_RH=(somme_RH/somme)*100;
  • printf ("\n%s",fait.candidat);
  • printf ("\t%f",somme);
  • printf ("\n%f",somme_RH);
  • printf ("\n%f",pourcentage_RH);
  • }
  • if (strcmp (fait.candidat,"AL")==0)
  • {
  • somme_AL=somme_AL+1;
  • pourcentage_AL=(somme_AL/somme)*100;
  • printf ("\n%s",fait.candidat);
  • printf ("\t%f",somme);
  • printf ("\n%f",somme_AL);
  • printf ("\n%f",pourcentage_AL);
  • }
  • if (strcmp (fait.candidat,"NM")==0)
  • {
  • somme_NM=somme_NM+1;
  • pourcentage_NM=(somme_NM/somme)*100;
  • printf ("\n%s",fait.candidat);
  • printf ("\t%f",somme);
  • printf ("\n%f",somme_NM);
  • printf ("\n%f",pourcentage_NM);
  • }
  • }
  • while (!feof (entree));
  • printf ("%f %f %f %f %f",somme,somme_JC,somme_LP,somme_AL,somme_NM);
  • printf ("\n\tLionel Jospin Jacques Chirac Jean-Marie Le Pen");
  • printf ("\n\n\t %f \t %f \t %f", pourcentage_LJ, pourcentage_JC, pourcentage_LP);
  • printf ("\n\n\n\t Robert Hue Arlette Laguillier Noel Mamere");
  • printf ("\n\n\t %f \t %f \t %f", pourcentage_RH, pourcentage_AL, pourcentage_NM);
  • }
  • 
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define LGNOM 20
#define LGPRENOM 15
#define LGTEL 11
#define LGMOIS 25
#define LGJOUR 3
#define LGANNEE 5
#define LGNOMCHER 20
#define LGVERIFNOM 20
#define LGVERIFPRENOM 15
#define LGNOM1 20
#define LGPRENOM1 15
#define LGCANDIDAT 3


int i;
float somme=0;


FILE *sortie;

struct 	{ char nom[LGNOM+1];
	char prenom[LGPRENOM+1];
	char jour[LGJOUR+1];
	char mois[LGMOIS+1];
	char annee[LGANNEE+1];
	char tel[LGTEL+1];
	char candidat[LGCANDIDAT+1];
	}fait;

FILE *entree;

char * tampon;
char * nomfic="c:\meaux2.dat";




void main (void)
{
void introduction (void);
void menu (void);
void saisie (void);
void lecture (void);
void liste (void);
void verif (void);
void statistique (void);



clrscr();
introduction();
getch();

clrscr();
menu();
getch();

}








void introduction (void)
{
clrscr();
printf ("\n\n\n\n\n\n\n\n\t\t\tB I E N V E N U E.");
getch();
clrscr();
printf ("\n\n\n\n\n\n\n\n\n\t\tSondage pour les ,lections pr,sidentielles.");
getch();
}


void menu (void)
{
int n;

printf ("\n\t\t\t\tMenu G,n,ral\n\n\n\n");
printf ("\t\t1) Vous voulez vous inscrire.\n\n\n");
printf ("\t\t2) Rechercher une personne.\n\n\n");
printf ("\t\t3) Impression de la liste d'inscription.\n\n\n");
printf ("\t\t4) V,rifiez si vous ^tes d,j. inscrit.\n\n\n");
printf ("\t\t5) Stat:\n\n\n");
printf ("\nVotre choix:");
scanf("%d",&n);

if (n==1)
{
clrscr();
saisie();
getch();
}

if (n==2)
{
clrscr();
lecture();
getch();
}

if (n==3)
{
clrscr();
liste();
getch();
}

if (n==4)
{
clrscr();
verif();
getch();
}

if(n==5)
{
clrscr();
statistique();
getch();
}

}


void saisie (void)
{
sortie=fopen (nomfic,"a");

printf ("Entrez un nom en MAJUSCULES lors de la saisie.");
printf ("\n\nLaisser un nom VIDE . la fin de chaque saisie.");
gets (tampon);

while (printf ("\n\nNom:"), gets (fait.nom), strlen (fait.nom))
{
printf ("Pr,nom:");
scanf ("%s",&fait.prenom);
printf ("Jour:");
scanf ("%s",&fait.jour);
printf ("Mois:");
scanf ("%s",&fait.mois);
printf ("Ann,e:");
scanf ("%s",&fait.annee);
printf ("T,l,phone:");
scanf ("%s",&fait.tel);
printf ("Candidat LJ, JC, LP, RH, AL, NM:");
scanf ("%s",&fait.candidat);


fwrite (&fait, sizeof(fait), 1, sortie);
}
fclose (sortie);
}



void verif (void)
{
int intrus;
char verifnom[LGVERIFNOM+1];
char verifprenom[LGVERIFPRENOM+1];
char nom1[LGNOM1+1];
char prenom1[LGPRENOM1+1];

printf ("Entrer un nom et un prenom puis le prenom et le nom . v,rifier:");
scanf ("%s%s%s%s",&verifnom,&verifprenom,&prenom1,&nom1);
intrus=0;

entree=fopen (nomfic,"r");

do
{
fread (&fait, sizeof(fait), 1, entree);
if (((strcmp (verifnom, fait.nom)==0)&&(strcmp (verifprenom, fait.prenom)==0))||((strcmp (prenom1,fait.prenom)==0)&&(strcmp (nom1,fait.nom)==0)))
intrus=1;
}
while ((!intrus)&&(!feof (entree)));

if (intrus)
{
printf ("Vous ^tes d,j. inscrit.");
}

else
{
printf ("Inscrivez vous.");
menu();
}

fclose (entree);
}



void lecture (void)
{
char nomcher[LGNOMCHER+1];
int trouve;


entree=fopen (nomfic,"r");
printf ("Nom cherch,:");
scanf ("%s",&nomcher);
trouve=0;

do
{
fread (&fait, sizeof(fait), 1, entree);
if (strcmp (nomcher, fait.nom)==0)
trouve=1;
}
while ((!trouve)&&(!feof (entree)));

if (trouve)
{
printf ("prenom:%s\n",fait.prenom);
printf ("jour:%s\n",fait.jour);
printf ("mois:%s\n",fait.mois);
printf ("annee:%s\n",fait.annee);
printf ("t,l,phone:%s\n",fait.tel);
printf ("candidat:%s\n",fait.candidat);
}

else
printf ("Ce nom ne figure pas dans la base de donn,es.");


fclose (entree);
}


void liste (void)
{

entree=fopen (nomfic,"r");
printf ("\t\t\tListe des personnes inscrites.");
printf ("\n\n\n\tNom\tPr,nom\tJour\tMois\tAnnee\tT,l,phone\tCandidat");

while (fread (&fait, sizeof(fait), 1, entree), !feof(entree))
{
printf ("\n\t%s  %s   %s      %s    %s    %s         %s",fait.nom,fait.prenom,fait.jour,fait.mois,fait.annee,fait.tel,fait.candidat);
}

fclose (entree);


/*printf ("Impression de la liste");
fprintf (stdprn,"Liste des personnes inscrites");*/
}


void statistique (void)
{
float somme_LJ=0, somme_JC=0, somme_LP=0, somme_RH=0, somme_AL=0, somme_NM=0,som;
float pourcentage_LJ, pourcentage_JC, pourcentage_LP, pourcentage_RH, pourcentage_AL, pourcentage_NM;
entree=fopen (nomfic,"r");

do
{
fread (&fait, sizeof (fait), 1, entree);

  if (fait.nom)
	{
somme=somme+1;
printf ("\n\t%s",fait.nom);
printf ("\n%f",somme);
	}


 if (strcmp (fait.candidat,"LJ")==0)
	{
somme_LJ=somme_LJ+1;
pourcentage_LJ=(somme_LJ/somme)*100;
printf ("\n%s",fait.candidat);
printf ("\t%f",somme);
printf ("\%f",somme_LJ);
printf ("\n%f",pourcentage_LJ);
	}


 if (strcmp (fait.candidat,"JC")==0)
	{
somme_JC=somme_JC+1;
pourcentage_JC=(somme_JC/somme)*100;
printf ("\n%s",fait.candidat);
printf ("\t%f",somme);
printf ("\n%f",somme_JC);
printf ("\n%f",pourcentage_JC);
	}


 if (strcmp (fait.candidat,"LP")==0)
	{
somme_LP=somme_LP+1;
pourcentage_LP=(somme_LP/somme)*100;
printf("\n%s",fait.candidat);
printf ("\t%f",somme);
printf ("\n%f",somme_LP);
printf ("\n%f",pourcentage_LP);
	}

 if (strcmp (fait.candidat,"RH")==0)
	{
somme_RH=somme_RH+1;
pourcentage_RH=(somme_RH/somme)*100;
printf ("\n%s",fait.candidat);
printf ("\t%f",somme);
printf ("\n%f",somme_RH);
printf ("\n%f",pourcentage_RH);
	}

 if (strcmp (fait.candidat,"AL")==0)
	{
somme_AL=somme_AL+1;
pourcentage_AL=(somme_AL/somme)*100;
printf ("\n%s",fait.candidat);
printf ("\t%f",somme);
printf ("\n%f",somme_AL);
printf ("\n%f",pourcentage_AL);
	}

 if (strcmp (fait.candidat,"NM")==0)
	{
somme_NM=somme_NM+1;
pourcentage_NM=(somme_NM/somme)*100;
printf ("\n%s",fait.candidat);
printf ("\t%f",somme);
printf ("\n%f",somme_NM);
printf ("\n%f",pourcentage_NM);
	}

}
while (!feof (entree));


printf ("%f %f %f %f %f",somme,somme_JC,somme_LP,somme_AL,somme_NM);
printf ("\n\tLionel Jospin         Jacques Chirac        Jean-Marie Le Pen");
printf ("\n\n\t      %f \t             %f  \t            %f", pourcentage_LJ, pourcentage_JC, pourcentage_LP);

printf ("\n\n\n\t Robert  Hue         Arlette Laguillier         Noel Mamere");
printf ("\n\n\t      %f   \t            %f   \t            %f", pourcentage_RH, pourcentage_AL, pourcentage_NM);

}





Commentaires et avis

signaler à un administrateur
Commentaire de cmarsc le 20/06/2002 19:37:26

salut,

pour incrémenter une valeur de point 1 il faut simplement  écrire somme_NM ++; ou ++somme_NM;   au lieu de somme_NM = somme_NM+1; (comme en basic)
et il est parfois plus utile d'employer switch et case à la place de if

cordialement
cmarsc ;-)

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,359 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.