Dev-C++ et applications multi-fichiers
Bonjour,
j'ai cr�� une application mutli-fichiers qui se compose de quatre fichiers :
GestEntrMain.cpp
Code:
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
| //--------------------------------------------------------------------------//
// Fichier : GestEntrMain.cpp //
// Descriptif : //
// Gestion simplifiée d'une entreprise //
// Version multi fichiers //
//--------------------------------------------------------------------------//
#include <cstdlib>
#include <stdio.h> // Pour printf(), scanf(), etc...
#include "GestEntr.h"
using namespace std;
//--------------------------------------------------------------------------//
// Procédure principale () //
//--------------------------------------------------------------------------//
int main (int argc, char *argv[])
{
//----- Variables locales -----//
char choix;
bool fini;
//----- Instructions ----------//
Init ();
fini = false;
while (!fini)
{
AfficherMenu ();
fflush (stdin);
scanf ("%c", &choix);
switch (choix)
{
case '1' :
ListerLesNoms ();
break;
case '2' :
AjouterUnNom ();
break;
case '3' :
SupprimerUnNom ();
break;
case 'f' :
case 'F' :
fini = true;
printf ("\n");
break;
default :
printf ("ERREUR : Choix non reconnu\n");
}
}
system("pause");
return EXIT_SUCCESS;
} |
GestUtils.cpp
Code:
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
| //--------------------------------------------------------------------------//
// Fichier : GestEntrMain.cpp //
// Descriptif : //
// Gestion simplifiée d'une entreprise //
// Version multi fichiers
// Fonctions de base //
//--------------------------------------------------------------------------//
#include <stdio.h> // Pour printf(), scanf(), etc...
#include <string.h>
#include "GestEntr.h"
using namespace std;
//--------------------------------------------------------------------------//
// Fonction PlaceLibre () //
// Valeur retournée : //
// - -1 s'il n'y a pas de place libre dans le tableau //
// - Sinon, indice de la première place libre //
//--------------------------------------------------------------------------//
int PlaceLibre ()
{
int tempo,i;
bool trouvePlaceLibre;
tempo=-1;
i=0;
trouvePlaceLibre=false;
while((trouvePlaceLibre==false) && (i<MAX))
{
if(entreprise[i].present==false)
{
trouvePlaceLibre=true;
tempo=i;
}
else
{
i++;
}
}
return tempo;
}
//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
// Procédure Init () : Initialisation du tableau entreprise //
//--------------------------------------------------------------------------//
void Init ()
{
int i;
for(i=0;i<=(NBE_MAX-1);i++)
{
entreprise[i].present=false;
}
}
//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
// Procédure ListerLesNoms () : Affichage du contenu du tableau entreprise //
//--------------------------------------------------------------------------//
void ListerLesNoms ()
{
int i;
for(i=0;i<=(NBE_MAX-1);i++)
{
if(entreprise[i].present==true)
{
printf("Nom de la personne :%s \n", entreprise[i].individu.nom);
printf("prénom de la personne :%s \n", entreprise[i].individu.prenom);
}
}
}
//--------------------------------------------------------------------------// |
GestEntrGestion.cpp
Code:
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
| //--------------------------------------------------------------------------//
// Fichier : GestEntrMain.cpp //
// Descriptif : //
// Gestion simplifiée d'une entreprise //
// Version multi fichiers
// Fonctions complexes //
//--------------------------------------------------------------------------//
#include <cstdlib>
#include <stdio.h> // Pour printf(), scanf(), etc...
#include <string.h>
#include "GestEntr.h"
using namespace std;
//--------------------------------------------------------------------------//
// Fonction EstPresent () //
// Valeur retournée : //
// - -1 si l'employé n'est pas dans le tableau //
// - Sinon, indice de l'employé dans le tableau //
//--------------------------------------------------------------------------//
int EstPresent (Personne p)
{
//
int tempo,i ;
bool trouvePresent;
//
tempo=-1;
i=0;
trouvePresent=false;
//
while((trouvePresent==false) && (i<MAX))
{
if((entreprise[i].present==true) && (strcmp(entreprise[i].individu.nom,p.nom)==0)
&& (strcmp(entreprise[i].individu.prenom,p.prenom)==0))
{
trouvePresent=true;
tempo=i;
}
else
{
i++;
}
}
return tempo;
printf("%d",tempo);
}
//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
// Procédure AjouterUnNom () : Ajout d'un nom dans le tableau entreprise //
//--------------------------------------------------------------------------//
void AjouterUnNom ()
{
int libre, present;
libre=PlaceLibre();
if(libre==-1)
{
printf("Il n'y a plus de place");
}
else
{
printf("Entrez le nom :\n");
scanf("%s",&entreprise[libre].individu.nom);
printf("Entrez le prénom :\n");
scanf("%s",&entreprise[libre].individu.prenom);
present=EstPresent(entreprise[libre].individu);
if(present==-1)
{
printf("Entrez le jour : \n");
scanf("%d",&entreprise[libre].entree.jour);
entreprise[libre].present=true;
}
else
{
printf("L'individu est déja présent\n");
}
}
}
//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
// Procédure SupprimerUnNom () : Retrait d'un nom dans le tableau //
//--------------------------------------------------------------------------//
void SupprimerUnNom ()
{
Personne p;
int presence;
printf("Entrez un nom :");
scanf("%s",p.nom);
printf("Entrez un prénom :");
scanf("%s",&p.prenom);
presence=EstPresent(p);
if(presence==-1)
{
printf("Votre individu n'éxiste pas !");
}
else
{
entreprise[presence].present=false;
printf("La personne a bien été supprimée \n");
}
}
//--------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
// Procédure AfficheMenu () //
//--------------------------------------------------------------------------//
void AfficherMenu ()
{
printf ("\n--- GESTION SIMPLIFIEE D'UNE ENTREPRISE (V1) ---\n");
printf (" 1 : Lister les noms\n");
printf (" 2 : Ajouter un nom\n");
printf (" 3 : Supprimer un nom\n");
printf (" f : Fin du programme\n");
printf (" Votre choix : ");
}
//--------------------------------------------------------------------------// |
GestEntr.h
Code:
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
| //-------------------------------------------------------------------------//
// Fichier : GestEntr.h //
// //
// Descriptif : //
// Ce fichier contient les déclarations
//-------------------------------------------------------------------------//
//--------------------------------------------------------------------------//
// CONSTANTES //
//--------------------------------------------------------------------------//
const int MAX = 80; // Longueur maxi des chaînes de caractères
const int NBE_MAX = 5; // Nombre maxi d'éléments du tableau
//--------------------------------------------------------------------------//
// TYPES //
//--------------------------------------------------------------------------//
struct Date
{
int jour, mois, annee;
};
struct Personne
{
char nom[MAX], prenom[MAX];
};
struct Employe
{
bool present;
Personne individu;
Date entree; // Date d'entrée dans l'entreprise
};
//--------------------------------------------------------------------------//
// Variables globales //
//--------------------------------------------------------------------------//
Employe entreprise[NBE_MAX];
//--------------------------------------------------------------------------//
// Fonctions principales //
//--------------------------------------------------------------------------//
void Init();
void AfficherMenu ();
void ListerLesNoms ();
int PlaceLibre ();
int EstPresent (Personne p);
void AjouterUnNom ();
void SupprimerUnNom (); |
Si je compile les trois fichiers C++ s�par�ment il y a aucun probl�me, mais si je compile tous les fichiers de ce projet j'ai les erreurs suivantes qui doivent venir du fichier d'en t�te sous dev-C++ 4.9.9.2 :
multiple definition of 'entreprise'
first defined here
multiple definition of 'entreprise'
first defined here
Id returned 1 exit status
C:\Documents and Settings\--FloFlo--\Mes documents\Dev-C++\Makefile.win [Build Error] [Projet1.exe] Error 1
Le probl�me vient du fichier d'ent�te, mais je vois pas ou exactement.
Merci d'avance