salut voila j'ai voulu reprendre un code, j'ai installé dev C++ sur mon portable et un code qui fonctionnait bien ne marche plus.
main.cpp
personne.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
31
32
33
34
35
36
37
38
39
40
41
42
43 #include <cstdlib> #include <iostream> #include <list> #include <string> #include "Personne.h" using namespace std; int main(int argc, char *argv[]) { //declaration Collection MaCollection; Personne MaPersonne; int i; string Nom[3]={"test1","test2","test3"}; string Prenom[3]={"le","la","les"}; int Age[3]={25,21,22}; /*---- en automatique ------*/ for (i=0;i<3;i++){ MaPersonne.setNom(Nom[i]); MaPersonne.setPrenom(Prenom[i]); MaPersonne.setAge(Age[i]); //Ajout MaCollection.AjoutPersonne(MaPersonne);//on ajoute la personne dans la collection MaCollection.NbPersonne();// On rajoute une personne au total } /*--- Affichage --*/ cout<<"Il y a : "<<MaCollection.getNbPersonnes()<<" personne(s) dans ma collection"<<endl<<endl; //cout<<MaCollection[0].getNom(); MaCollection.Parcourir(); MaCollection.SupprimePersonne("Erard"); cout<<endl; system("PAUSE"); return EXIT_SUCCESS; }
Ca ne compile plus, et il s'arrete sur le main sur :
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
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 #ifndef PERSONNE_H #define PERSONNE_H #include <iostream> #include <string> using namespace std; class Personne{ private: string Nom; string Prenom; int Age; public: Personne(); void setNom(string LeNom); void setPrenom(string LePrenom); void setAge(int lage); string getNom(); string getPrenom(); int getAge(); }; class Collection{ private: int NbPersonnes; list <Personne> MaCollection; public: Collection(); int getNbPersonnes(); void AjoutPersonne(Personne MaPersonne); void NbPersonne(); void Parcourir(); void SupprimePersonne(string Nom); }; /*------------------------------- /* Methode de Personne /*------------------------------*/ Personne::Personne(){ Nom=""; Prenom=""; Age=0; } void Personne::setNom(string LeNom){ Nom=LeNom; } void Personne::setPrenom(string LePrenom){ Prenom=LePrenom; } void Personne::setAge(int lage){ Age=lage; } string Personne::getNom(){return Nom;} string Personne::getPrenom(){return Prenom;} int Personne::getAge(){return Age;} /*------------------------------- /* Methode de Collection /*------------------------------*/ Collection::Collection(){ NbPersonnes=0; } void Collection::NbPersonne(){ NbPersonnes++; } int Collection::getNbPersonnes(){return NbPersonnes;} void Collection::AjoutPersonne(Personne MaPersonne){ MaCollection.push_back(MaPersonne); } void Collection::Parcourir(){ for(list<Personne>::iterator parcours = MaCollection.begin(); parcours != MaCollection.end();parcours++) { cout<<"Nom: "<<parcours->getNom()<<endl; cout<<"Prenom: "<<parcours->getPrenom()<<endl; cout<<"Age: "<<parcours->getAge()<<endl<<endl; } } void Collection::SupprimePersonne(string Nom){ for(list<Personne>::iterator parcours = MaCollection.begin(); parcours != MaCollection.end();parcours++) { if (Nom==parcours->getNom()){ cout<<"le supprime est:"<<endl; cout<<"Nom: "<<parcours->getNom()<<endl; cout<<"Prenom: "<<parcours->getPrenom()<<endl; cout<<"Age: "<<parcours->getAge()<<endl<<endl; delete parcours; } } } #endif
#include "Personne.h"
Merci d'avance pour votre aide
Partager