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