Bonjour à tous,
Je dois pour l'école faire une application de gestion d'horaire dans laquelle est géré des cours.
La classe cours hérite de la classe event,
classe event:
classe cours:
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 #include "Event.h" Event::Event() { Code = 0; Intitule = NULL; strcpy(Lieu, "0"); timing=new Timing(); } Event::~Event() { if(Intitule != NULL) delete Intitule; Intitule = NULL; } Event::Event(const int C, const char *I, const char *L ,const Timing &T) { //cout << "Constructeur d'initialisation Event" << endl; setCode(C); setIntitule(I); setLieu(L); timing=new Timing(T); } Event::Event(const int C, const char *I, const char *L ) { //cout << "Constructeur d'initialisation Event" << endl; Intitule = NULL; timing=new Timing(); setCode(C); setIntitule(I); setLieu(L); } Event::Event(const Event &copie) { setCode(copie.getCode()); setIntitule(copie.getIntitule()); setLieu(copie.getLieu()); setTiming(copie.getTiming()); } int Event::getCode()const { return Code; } char *Event::getIntitule()const { return Intitule; } char *Event::getLieu()const { return (char *)Lieu; } Timing &Event::getTiming()const { return *timing; } void Event::setCode(const int code) { //cout << "SetCode Event" << endl; Code = code; } void Event::setIntitule(const char *I) { //cout << "SetIntitule Event" << endl; if(Intitule) delete Intitule; if(I) { Intitule = new char[strlen(I)+1]; strcpy(Intitule, I); } else Intitule = NULL; } void Event::setLieu(const char lieu[] ) { //cout << "SetLieu Event" << endl; if(strlen(lieu) <= 21) strcpy(Lieu, lieu); else strcpy(Lieu, ""); } void Event::setTiming(const Timing &t) { //cout << "SetTiming Event" << endl; timing = NULL; timing = new Timing(t); /*timing->setJour(t.getJour()); timing->setHeure(t.getHeure()); timing->setDuree(t.getDuree());*/ } void Event::Affiche()const { cout << "Code: " << getCode() << endl; if(Intitule) { cout << "Intitule: " << Intitule << endl; } cout << "Lieu: " << Lieu << endl; } ostream& operator<< (ostream& flux, const Event &P) { /*if(P.getNom() && P.getPrenom()) { flux << "Nom: " << P.getNom() << endl; flux << "Prenom: " << P.getPrenom() << endl; }*/ return flux; } istream& operator>> (istream& flux, Event &P) { int Code; char *Intitule = new char[50]; char Lieu[21]; Timing timing; cout << "Code: "; flux >> Code; cout << "Intitule: "; flux >> Intitule; cout << "Lieu: "; flux >> Lieu; flux >> timing; P.setCode(Code); P.setIntitule(Intitule); P.setLieu(Lieu); P.setTiming(timing); return flux; } Event & Event::operator=(const Event &e) { } bool Event::operator==(const Event &e) { } bool Event::operator>(const Event &e) { } bool Event::operator<(const Event &e) { } void Event::Save(ofstream &fichier)const { int TailleInt = strlen(getIntitule()); int code = getCode(); fichier.write((char *) &code, sizeof(int)); fichier.write((char *)&TailleInt, sizeof(TailleInt)); fichier.write((char *)getIntitule(), TailleInt*sizeof(char)); fichier.write((char *)getLieu(), sizeof(Lieu)); timing->Save(fichier); } void Event::Load(ifstream &fichier) { int TailleInt, code; char *Int; char lieu[sizeof(Lieu)]; fichier.read((char *) &code, sizeof(int)); fichier.read((char *) &TailleInt, sizeof(int)); Int = new char[TailleInt]; fichier.read((char *) Int, TailleInt); fichier.read((char *) &lieu, sizeof(Lieu)); setCode(code); setIntitule(Int); setLieu(lieu); timing->Load(fichier); }
J'ai ensuite 3 autres classes (Professeur, Local et Groupe) qui héritent de planifiable.
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 #include "Cours.h" #include "Timing.h" #include "Professeur.h" #include "Groupe.h" #include "Local.h" Cours::Cours() { Professeur = NULL; } Cours::~Cours() { if(Professeur) delete Professeur; } char *Cours::getProfesseur()const { return Professeur; } void Cours::setProfesseur(const char *professeur) { if(Professeur) delete Professeur; if(professeur) { Professeur = new char[strlen(professeur)+1]; strcpy(Professeur, professeur); } else Professeur = NULL; } void Cours::setGroupe(const int g) { groupe.insere(g); } Cours & Cours::operator=(const Cours &c) { setProfesseur(c.getProfesseur()); } bool Cours::operator==(const Cours &c) { return getTiming() == c.getTiming(); } bool Cours::operator>(const Cours &c) { return getTiming() > c.getTiming(); } bool Cours::operator<(const Cours &c) { return getTiming() < c.getTiming(); } ostream& operator<< (ostream& flux, const Cours &c) { flux << "Code: "<< c.getCode() << endl; flux << "Intitule: "; if(!(c.getIntitule())) flux << "Inconnu" << endl; else flux << c.getIntitule() << endl; flux << "Lieu: "; if(!(c.getLieu()) || strcmp(c.getLieu(), "")==0) flux << "Inconnu" << endl; else flux << c.getLieu() << endl; if(c.timing) flux << c.getTiming(); flux << "Professeur: "; if(c.getProfesseur()) flux << c.getProfesseur(); flux << endl << "Groupe: "; c.groupe.Affiche(); return flux; }
classe Professeur:
classe Groupe:
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 #include "Professeur.h" Professeur::Professeur() { Nom = NULL; Prenom = NULL; strcpy(Identifiant, " "); setType('h'); } Professeur::Professeur(const char *N, const char *P) { Nom = NULL; Prenom = NULL; setNom(N); setPrenom(P); strcpy(Identifiant, getIdentifiant()); setType('h'); } Professeur::~Professeur() { //cout << "destructeur professeur"<<endl; if(Nom) delete Nom; if(Prenom) delete Prenom; Nom = NULL; Prenom = NULL; } Professeur::Professeur(const Professeur &copie) { Nom = NULL; Prenom = NULL; setNom(copie.getNom()); setPrenom(copie.getPrenom()); } void Professeur::setNom(const char *N) { if(Nom) delete Nom; Prenom = NULL; if(N) { Nom = new char[strlen(N)+1]; strcpy(Nom, N); } } void Professeur::setPrenom(const char *P) { if(Prenom) delete Prenom; Prenom = NULL; if(P) { Prenom = new char[strlen(P)+1]; strcpy(Prenom, P); } } char *Professeur::getNom()const { return Nom; } char *Professeur::getPrenom()const { return Prenom; } const char *Professeur::getIdentifiant() { sprintf(Identifiant, "%s %s", Nom, Prenom); return Identifiant; } void Professeur::Affiche() { if(Nom) cout << Nom; else cout << "NULL"; cout << ", "; if(Prenom) cout << Prenom; else cout << "NULL"; cout << ", "; cout << getIdentifiant() << endl; } ostream& operator<< (ostream& flux, const Professeur &P) { if(P.getNom() && P.getPrenom()) { flux << "Nom: " << P.getNom() << endl; flux << "Prenom: " << P.getPrenom() << endl; } return flux; } istream& operator>> (istream& flux, Professeur &P) { char nom[30], prenom[30]; do { cout << "Nom : "; flux >> nom; }while(strlen(nom) >= 30); do { cout << "Prenom : "; flux >> prenom; }while(strlen(prenom) >= 30); P.setNom(nom); P.setPrenom(prenom); return flux; } Professeur& Professeur::operator=(const Professeur& p) { setNom(p.getNom()); setPrenom(p.getPrenom()); getIdentifiant(); return *this; } bool Professeur::operator==(const Professeur &e) { if(strcmp(e.getNom(), getNom()) == 0) return true; return false; } bool Professeur::operator>(const Professeur &e) { if(strcmp(getNom(), e.getNom()) > 0) return true; if(strcmp(getNom(), e.getNom()) == 0 && strcmp(getPrenom(), e.getPrenom()) > 0) return true; return false; } bool Professeur::operator<(const Professeur &e) { if(strcmp(getNom(), e.getNom()) < 0) return true; if(strcmp(getNom(), e.getNom()) == 0 && strcmp(getPrenom(), e.getPrenom()) < 0) return true; return false; } void Professeur::Load(ifstream &fichier) { char *nom = NULL, *prenom = NULL; string NomPrenom; getline(fichier, NomPrenom, ';'); nom = new char[NomPrenom.size()+1]; strcpy(nom, NomPrenom.c_str()); //NomPrenom.copy(nom, NomPrenom.size(), 0); NomPrenom.erase(0, NomPrenom.size()); getline(fichier, NomPrenom); prenom = new char [NomPrenom.size()+1]; strcpy(prenom, NomPrenom.c_str()); //NomPrenom.copy(prenom, NomPrenom.size(), 0); setNom(nom); setPrenom(prenom); }
classe local:
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
104
105
106
107
108
109
110 #include "Groupe.h" Groupe::Groupe() { Numero = 0; strcpy(Identifiant, " "); setType('m'); } Groupe::Groupe(int N) { setNumero(N); strcpy(Identifiant, getIdentifiant()); setType('m'); } Groupe::~Groupe() { } Groupe::Groupe(const Groupe &copie) { setNumero(copie.getNumero()); } void Groupe::setNumero(const int N) { Numero = N; } int Groupe::getNumero()const { return Numero; } const char *Groupe::getIdentifiant() { sprintf(Identifiant, "G%d", Numero); return Identifiant; } void Groupe::Affiche() { cout << "Numero : " << Numero << endl; } Groupe& Groupe::operator=(const Groupe& g) { setNumero(g.getNumero()); return *this; } bool Groupe::operator==(const Groupe &g) { if(g.getNumero() == getNumero()) return true; return false; } bool Groupe::operator>(const Groupe &g) { if(g.getNumero() > getNumero()) return true; return false; } bool Groupe::operator<(const Groupe &g) { if(g.getNumero() < getNumero()) return true; return false; } ostream& operator<< (ostream& flux, const Groupe &G) { flux << "Groupe: " << G.getNumero()<< endl; return flux; } istream& operator>> (istream& flux, Groupe &G) { int groupe; cout << "Groupe : "; flux >> groupe; G.setNumero(groupe); } void Groupe::Load(ifstream &fichier) { int grp; string g; string temp; if(getline(fichier, g)) { temp = g.substr(g.find_last_of(';')+1); grp = atoi(temp.c_str()); setNumero(grp); } }
et la classe planifiable.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 #include "Local.h" #include <string> Local::Local() { Nom = NULL; NbPlaces = 0; setType('m'); strcpy(Identifiant, getIdentifiant()); } Local::Local(const char *N, const int Nb) { Nom = NULL; setNom(N); setNbPlaces(Nb); setType('m'); strcpy(Identifiant, getIdentifiant()); } Local::~Local() { if(Nom) delete Nom; Nom = NULL; } Local::Local(const Local &copie) { setNom(copie.getNom()); setNbPlaces(copie.getNbPlaces()); } void Local::setNom(const char *N) { if(Nom) delete Nom; if(N) { Nom = new char[strlen(N)+1]; strcpy(Nom, N); } else Nom = NULL; } void Local::setNbPlaces(const int Nb) { NbPlaces = Nb; } char *Local::getNom()const { return Nom; } int Local::getNbPlaces()const { return NbPlaces; } const char *Local::getIdentifiant() { sprintf(Identifiant, "%s(%d)", Nom, NbPlaces); return Identifiant; } void Local::Affiche() { if(Nom) cout << "Nom: " << Nom << endl; else cout << "Nom: NULL" << endl; cout << "NbPlaces: " << NbPlaces << endl; } Local& Local::operator=(const Local& l) { setNom(l.getNom()); setNbPlaces(l.getNbPlaces()); return *this; } bool Local::operator==(const Local &l) { if(l.getNbPlaces() == getNbPlaces()) return true; return false; } bool Local::operator>(const Local &l) { if(getNbPlaces() > l.getNbPlaces()) return true; return false; } bool Local::operator<(const Local &l) { if(getNbPlaces() < l.getNbPlaces()) return true; return false; } ostream& operator<< (ostream& flux, const Local& L) { flux << "Nom : " << L.getNom() << endl; flux << "NbPlaces : " << L.getNbPlaces() << endl; return flux; } istream& operator>> (istream& flux, Local& L) { char nom[30]; int place; do { cout << "Nom: "; flux >> nom; }while(strlen(nom) >=30); cout << "NbPlaces : "; flux >> place; L.setNom(nom); L.setNbPlaces(place); return flux; } void Local::Load(ifstream &fichier) { int nbi; string nb; char *loc = new char[20]; string loca; getline(fichier, loca, ';'); strcpy(loc, loca.c_str()); setNom(loc); delete loc; getline(fichier, nb); nbi = atoi(nb.c_str()); setNbPlaces(nbi); }
planifiable.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
21
22
23
24
25
26
27 #ifndef PLANIFIABLE_H #define PLANIFIABLE_H #include <iostream> using namespace std; #include "Timing.h" #include "ListeTriee.h" #include "SmartPointer.h" class Planifiable { protected: char Type; ListeTriee< SmartPointer<Cours> > horaire; public: Planifiable(); Planifiable(Planifiable &); virtual ~Planifiable(); void setType(const char); const char getType(); virtual const char *getIdentifiant() = 0; bool estDisponible(const Timing &t); void Affiche(); }; #endif
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 #include "Planifiable.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include <iostream> using namespace std; Planifiable::Planifiable() { } Planifiable::Planifiable(Planifiable &copie) { setType(copie.getType()); } Planifiable::~Planifiable() { } void Planifiable::setType(const char T) { Type = T; } const char Planifiable::getType() { return Type; } void Planifiable::Affiche() { cout << "Type: " << getType() << endl; }
Et pour finir une classe SmartPointer:
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 #include "SmartPointer.h" template<class T> SmartPointer<T>::SmartPointer() { val = NULL; } template<class T> SmartPointer<T>::SmartPointer(T*v) { val = v; } template<class T> SmartPointer<T>::~SmartPointer() { val = NULL; } template<class T> SmartPointer<T>::SmartPointer(const SmartPointer &s) { val = s.val; } template<class T> void SmartPointer<T>::Delete() { delete val; } template<class T> T* SmartPointer<T>::getValeur() { return val; } template<class T> T SmartPointer<T>::operator*(void) { return *val; } template<class T> bool SmartPointer<T>::operator==(const SmartPointer &s) { return operator==(s); } template<class T> bool SmartPointer<T>::operator>(const SmartPointer &s) { return operator>(s); } template<class T> bool SmartPointer<T>::operator<(const SmartPointer &s) { return operator<(s); } template class SmartPointer<Cours>;
à l'aide de la classe SmartPointer, je dois créer une liste triée de smartpointer<cours>.
J'ai juste un soucis, lors de la compilation j'ai une erreur:
louis@ubuntu:~/Documents/C++2015$ make
Creation de Planifiable
Creation de App
Planifiable.o: dans la fonction « ListeTriee<SmartPointer<Cours> >::ListeTriee() »:
Planifiable.cpp.text._ZN10ListeTrieeI12SmartPointerI5CoursEEC2Ev[_ZN10ListeTrieeI12SmartPointerI5CoursEEC5Ev]+0x14): référence indéfinie vers « ListeBase<SmartPointer<Cours> >::ListeBase() »
Planifiable.o: dans la fonction « ListeTriee<SmartPointer<Cours> >::~ListeTriee() »:
Planifiable.cpp.text._ZN10ListeTrieeI12SmartPointerI5CoursEED2Ev[_ZN10ListeTrieeI12SmartPointerI5CoursEED5Ev]+0x1f): référence indéfinie vers « ListeBase<SmartPointer<Cours> >::~ListeBase() »
collect2: error: ld returned 1 exit status
make: *** [App] Erreur 1
louis@ubuntu:~/Documents/C++2015$
J'ai beau chercher partout sur internet, je ne trouve rien m'aidant à régler ce problème..
Votre aide est donc la bienvenue !
Je vous mets en pièce jointe mon dossier complet si jamais les extraits de code que j'ai mis ci contre ne suffiraient pas.
Partager