This repository has been archived by the owner on Aug 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNote.cpp
316 lines (293 loc) · 9.42 KB
/
Note.cpp
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include "Note.h"
#include "templatemanager.h"
#include "Etudiant.h"
Note::Note(std::string n, std::string d, unsigned int r, unsigned int e)
{
if(e>2)
{
throw NoteException("Erreur : le dernier parametres doit etre compris entre 0 et 2 inclus :(0:pas eliminatoire,1 eliminatoire, 2 non determinante)");
}
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
if(!tNote.alreadyExist(n))
{
if(tNote.size()>0)
{
// qDebug()<<"taille : "<<tNote.size();
if((getEliminatoryNotes().size()>0)&&(getBestEliminatoryNote().getRang()<r)&&(e!=1))
{
throw NoteException("Erreur : cette Note "+n+" doit etre eliminatoire etant donne son rang!");
}
if((getValidatoryNotes().size()>0)&&(getWorstValidatoryNote().getRang()>r)&&(e==1))
{
throw NoteException("Erreur : cette Note "+n+" ne doit pas etre eliminatoire etant donne son rang!");
}
if((e==2)&&(r!=0))
{
throw NoteException("Erreur : Une note non determinante doit etre de rang 0!("+n+")");
}
if((e!=2)&&(r==0))
{
throw NoteException("Erreur : Une note determinante doit etre de rang > 0!("+n+")");
}
}
note=QString::fromStdString(n);
description=QString::fromStdString(d);
rang=r;
eliminatoire=e;
tNote.New(*this);
}
else
{
throw NoteException("Erreur : la note "+n+" existe deja !");
}
}
Note::Note(QString n, QString d, unsigned int r, unsigned int e)
{
Note(n.toStdString(),d.toStdString(),r,e);
}
Note::Note(const char* n, const char *d, unsigned int r, unsigned int e)
{
Note(std::string(n),std::string(d),r,e);
}
void Note::setRang(unsigned int r)
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
if(tNote.size()>1)
{
// qDebug()<<"taille : "<<tNote.size();
if((getEliminatoryNotes().size()>0)&&(getBestEliminatoryNote().getRang()<r)&&(!isEliminatory()))
{//le nouveau rang la rend éliminatoire
rang=r;
eliminatoire=1;
}
if((getValidatoryNotes().size()>0)&&(getWorstValidatoryNote().getRang()>r)&&(isEliminatory()))
{ //le nouveau rang la rend non éliminatoire
rang=r;
if(r==0)
{
eliminatoire=2;//rang 0 implique non déterminante
}
else
{
eliminatoire=0;
}
}
}
}
void Note::destroy()
{
TemplateManager<Etudiant>& tEtudiant=TemplateManager<Etudiant>::getInstance();
if(tEtudiant.size()>0)//pour chaque étudiant, on enlève les isncriptions
{
for(std::vector<Etudiant>::iterator it = tEtudiant.getIterator();it!=tEtudiant.end();it++)//on supprime toutes les inscriptions ayant cette note
{
Dossier dos=it->getDossier();
std::vector<Inscription> inscr = dos.getInscription();
for(std::vector<Inscription>::iterator it2= inscr.begin();it2 != inscr.end();it2++)
{
if(it2->getResultat()==*this)
{
dos.deleteInscription(*it2);
it->setDossier(dos);
}
}
}
}
}
Note getBestNote(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
if(begin==end)
{
throw NoteException("Erreur getBestNote() les itérateurs sont egaux, vous iterez probablement sur un tableau vide");
}
Note max = *begin;
begin++;
for(std::vector<Note>::iterator itNote=begin;itNote != end;itNote++)
{
if(itNote->getRang()<max.getRang())
{
max=*itNote;
}
}
return max;
}
Note getWorstNote(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
if(begin==end)
{
throw NoteException("Erreur getBestNote() les itérateurs sont egaux, vous iterez probablement sur un tableau vide");
}
Note min = *begin;
begin++;
bool foundDeterminantNote=false;//les notes non déterminantes ne comptes pas.
for(std::vector<Note>::iterator itNote=begin;itNote != end;itNote++)
{
if((!foundDeterminantNote)&&(itNote->getRang()>0))
{
foundDeterminantNote=true;
min=*itNote;
}
if((foundDeterminantNote)&&(itNote->getRang()>min.getRang()))
{
min=*itNote;
}
}
return min;
}
Note getBestNote()
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
std::vector<Note>::iterator begin =tNote.getIterator();
std::vector<Note>::iterator end =tNote.end();
return getBestNote(begin,end);
}
Note getWorstNote()
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
std::vector<Note>::iterator begin =tNote.getIterator();
std::vector<Note>::iterator end =tNote.end();
return getWorstNote(begin,end);
}
Note getBestEliminatoryNote()
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
std::vector<Note>::iterator begin =tNote.getIterator();
std::vector<Note>::iterator end =tNote.end();
return getBestEliminatoryNote(begin,end);
}
Note getWorstValidatoryNote()
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
std::vector<Note>::iterator begin =tNote.getIterator();
std::vector<Note>::iterator end =tNote.end();
return getWorstValidatoryNote(begin,end);
}
Note getBestEliminatoryNote(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
std::vector<Note> test=getEliminatoryNotes(begin,end);
if(test.size()==0)
{
throw NoteException("Erreur getBestEliminatoryNote(...,...), il n'y a pas de notes eliminatoires dans ce tableau");
}
return getBestNote(begin,end);
}
Note getWorstValidatoryNote(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
std::vector<Note> test=getValidatoryNotes(begin,end);
if(test.size()==0)
{
throw NoteException("Erreur getWorstValidatoryNote(...,...), il n'y a pas de notes validantes dans ce tableau");
}
return getWorstNote(begin,end);
}
std::vector<Note> getEliminatoryNotes()
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
std::vector<Note>::iterator begin =tNote.getIterator();
std::vector<Note>::iterator end =tNote.end();
return getEliminatoryNotes(begin,end);
}
std::vector<Note> getEliminatoryNotes(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
std::vector<Note> res;
for(std::vector<Note>::iterator itNote=begin;itNote !=end;itNote++)
{
if(itNote->isEliminatory())
{
res.push_back(*itNote);
}
}
return res;
}
std::vector<Note> getValidatoryNotes()
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
std::vector<Note>::iterator begin =tNote.getIterator();
std::vector<Note>::iterator end =tNote.end();
return getValidatoryNotes(begin,end);
}
std::vector<Note> getValidatoryNotes(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
std::vector<Note> res;
for(std::vector<Note>::iterator itNote=begin;itNote !=end;itNote++)
{
if(itNote->isValidatory())
{
res.push_back(*itNote);
}
}
return res;
}
std::vector<Note> getDeterminantNotes()
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
std::vector<Note>::iterator begin =tNote.getIterator();
std::vector<Note>::iterator end =tNote.end();
return getDeterminantNotes(begin,end);
}
std::vector<Note> getDeterminantNotes(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
std::vector<Note> res;
for(std::vector<Note>::iterator itNote=begin;itNote != end;itNote++)
{
if((itNote->isValidatory())||(itNote->isEliminatory()))
{
res.push_back(*itNote);
}
}
return res;
}
std::vector<Note> getNonDeterminantNotes()
{
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
std::vector<Note>::iterator begin =tNote.getIterator();
std::vector<Note>::iterator end =tNote.end();
return getNonDeterminantNotes(begin,end);
}
std::vector<Note> getNonDeterminantNotes(std::vector<Note>::iterator begin,std::vector<Note>::iterator end)
{
std::vector<Note> res;
for(std::vector<Note>::iterator itNote=begin;itNote != end;itNote++)
{
if((!itNote->isValidatory())&&(!itNote->isEliminatory()))
{
res.push_back(*itNote);
}
}
return res;
}
Note StringToNote(const QString& str){//renvoie une référence vers la catégorie si elle existe, exception sinon.
TemplateManager<Note>& tNote=TemplateManager<Note>::getInstance();
if(tNote.alreadyExist(str))
{
return tNote.getElement(str);
}
else
{
throw NoteException("Erreur la note "+str.toStdString()+" n'existe pas.");
}
}
bool operator<(const Note n1,const Note n2)
{
return n1.getRang()<n2.getRang();
}
bool operator>(const Note n1, const Note n2)
{
return n1.getRang()>n2.getRang();
}
bool operator<=(const Note n1, const Note n2)
{
return !(n1>n2);
}
bool operator>=(const Note n1, const Note n2)
{
return !(n1<n2);
}
bool operator==(const Note n1, const Note n2)
{
return (n1.getRang()==n2.getRang());
}
bool operator!=(const Note n1, const Note n2)
{
return !(n1==n2);
}