Bonjour � tous, j'ai un petit soucis lors de ma compilation, j'ai une erreur me disant que la structure athl�te est red�finie plusieurs fois. J'ai voulus utiliser la commande #ifndef, #endif mais je sais pas exactement si je doit l'utiliser seulement dans le main ou alors dans tous les .cpp. Je ne sais pas non plus ce que je doit englober dedans.
Merci de m'aider.
Voici le programme:
- gestion_type.h //D�finition de la structure athlete
- gestion_saisie.h
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5 struct athlete { int numero; float record; };
- gestion_saisie.cpp //Saisie du num�ro et du record de chaque participants
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9 #include<iostream> #ifndef athlete #include "gestion_type.h" #endif using namespace std; void saisie(athlete part[],int nbp);
- gestion_tri.h
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13 #include"gestion_saisie.h" void saisie(athlete part[],int nbp) { int i; for(i=0;i<nbp;i++) { cout<<"N est record ?"<<endl; cin>>part[i].numero>>part[i].record; } };
- gestion_tri.cpp //Classement dans l'ordre croissant
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9 #include<iostream> #ifndef athlete #include "gestion_type.h" #endif using namespace std; void tri(athlete part[],int nbp);
- gestion_affichage.h
Code : S�lectionner tout - Visualiser dans une fen�tre � part
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 #include"gestion_tri.h" void tri(athlete part[],int nbp) { int i,j,indiceMin,min; athlete tmp; for(j=0;j<nbp-1;j++) { min=part[j].record; indiceMin=j; for(i=j+1;i<nbp;i++) { if(part[i].record<min) { min=part[i].record; indiceMin=i; } } if(indiceMin!=j) { tmp=part[j]; part[j]=part[indiceMin]; part[indiceMin]=tmp; } } };
- gestion_affichage.cpp //Affichage de la liste des participants
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9 #include<iostream> #ifndef athlete #include "gestion_type.h" #endif using namespace std; void affichage(athlete part[],int nbp);
- main.cpp
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include"gestion_affichage.h" void affichage(athlete part[],int nbp) { int rang; int i; cout<<"Rang Participant Record"<<endl; cout<<"1 "<<part[0].numero<<" "<<part[0].record<<endl; rang=1; for(i=1;i<nbp;i++) { if(part[i].record>part[i-1].record) rang++; cout<<rang<<" "<<part[i].numero<<" "<<part[i].record<<endl; } };
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include <iostream> #include "gestion_tri.h" #include "gestion_affichage.h" #include "gestion_saisie.h" #ifndef athlete #include "gestion_type.h" #endif using namespace std; const int nbParticipants = 10; athlete participants [ nbParticipants ]; int main (void) { saisie (participants,nbParticipants); tri(participants,nbParticipants); affichage(participants,nbParticipants); return 0; }
Partager