-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAirMeasurement.cpp
More file actions
378 lines (343 loc) · 8.39 KB
/
AirMeasurement.cpp
File metadata and controls
378 lines (343 loc) · 8.39 KB
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*************************************************************************
AirMeasurement - description
-------------------
début : $DATE$
copyright : (C) $YEAR$ par $AUTHOR$
e-mail : $EMAIL$
*************************************************************************/
//---------- Réalisation de la classe <AirMeasurement> (fichier AirMeasurement.cpp) ------------
//---------------------------------------------------------------- INCLUDE
//-------------------------------------------------------- Include système
#include <algorithm>
#include <iostream>
using namespace std;
//------------------------------------------------------ Include personnel
#include "AirMeasurement.h"
//------------------------------------------------------------- Constantes
//----------------------------------------------------------------- PUBLIC
//----------------------------------------------------- Méthodes publiques
// type AirMeasurement::Méthode ( liste des paramètres )
// Algorithme :
//
//{
//} //----- Fin de Méthode
int AirMeasurement::GetAtmoIndex() const
{
return atmoIndex;
}
float AirMeasurement::GetO3() const
{
return o3;
}
float AirMeasurement::GetSO2() const
{
return so2;
}
float AirMeasurement::GetNO2() const
{
return no2;
}
float AirMeasurement::GetPM10() const
{
return pm10;
}
//------------------------------------------------- Surcharge d'opérateurs
AirMeasurement &AirMeasurement::operator=(const AirMeasurement &unAirMeasurement)
// Algorithme :
//
{
this->atmoIndex = unAirMeasurement.atmoIndex;
this->o3 = unAirMeasurement.o3;
this->so2 = unAirMeasurement.so2;
this->no2 = unAirMeasurement.no2;
this->pm10 = unAirMeasurement.pm10;
return *this;
} //----- Fin de operator =
AirMeasurement AirMeasurement::operator+(const AirMeasurement &unAirMeasurement) const
{
float sumO3 = this->o3 + unAirMeasurement.o3;
float sumSO2 = this->so2 + unAirMeasurement.so2;
float sumNO2 = this->no2 + unAirMeasurement.no2;
float sumPM10 = this->pm10 + unAirMeasurement.pm10;
return AirMeasurement(sumO3, sumSO2, sumNO2, sumPM10);
}
bool AirMeasurement::operator<(const AirMeasurement &other) const
{
float sum = atmoIndex + o3 + no2 + so2 + pm10;
float otherSum = other.atmoIndex + other.o3 + other.so2 + other.no2 + other.pm10;
return sum < otherSum;
}
AirMeasurement AirMeasurement::operator/(int diviseur) const
{
float divO3;
float divSO2;
float divNO2;
float divPM10;
if (this->o3 != 0)
{
divO3 = this->o3 / diviseur;
}
else
{
divO3 = 0;
}
if (this->so2 != 0)
{
divSO2 = this->so2 / diviseur;
}
else
{
divSO2 = 0;
}
if (this->no2 != 0)
{
divNO2 = this->no2 / diviseur;
}
else
{
divNO2 = 0;
}
if (this->pm10 != 0)
{
divPM10 = this->pm10 / diviseur;
}
else
{
divPM10 = 0;
}
// Créer et retourner un nouvel objet AirMeasurement avec les valeurs divisées
return AirMeasurement(divO3, divSO2, divNO2, divPM10);
}
AirMeasurement AirMeasurement::operator-(const AirMeasurement &unAirMeasurement) const
{
float sO3 = this->o3 - unAirMeasurement.o3;
float sSO2 = this->so2 - unAirMeasurement.so2;
float sNO2 = this->no2 - unAirMeasurement.no2;
float sPM10 = this->pm10 - unAirMeasurement.pm10;
AirMeasurement *res = new AirMeasurement(sO3, sSO2, sNO2, sPM10);
return *res;
}
//-------------------------------------------- Constructeurs - destructeur
AirMeasurement::AirMeasurement(const AirMeasurement &unAirMeasurement)
// Algorithme :
//
{
#ifdef MAP
cout << "Appel au constructeur de copie de <AirMeasurement>" << endl;
#endif
this->atmoIndex = unAirMeasurement.atmoIndex;
this->o3 = unAirMeasurement.o3;
this->so2 = unAirMeasurement.so2;
this->no2 = unAirMeasurement.no2;
this->pm10 = unAirMeasurement.pm10;
} //----- Fin de AirMeasurement (constructeur de copie)
AirMeasurement::AirMeasurement(float o3, float so2, float no2, float pm10)
// Algorithme :
//
{
#ifdef MAP
cout << "Appel au constructeur de <AirMeasurement>" << endl;
#endif
this->o3 = o3;
this->so2 = so2;
this->no2 = no2;
this->pm10 = pm10;
int indexo3 = 0;
int indexso2 = 0;
int indexno2 = 0;
int indexpm = 0;
if ((o3 <= 29) && (o3 >= 0))
{
indexo3 = 1;
}
if ((o3 <= 54) && (o3 >= 30))
{
indexo3 = 2;
}
if ((o3 <= 79) && (o3 >= 55))
{
indexo3 = 3;
}
if ((o3 <= 104) && (o3 >= 80))
{
indexo3 = 4;
}
if ((o3 <= 129) && (o3 >= 105))
{
indexo3 = 5;
}
if ((o3 <= 149) && (o3 >= 130))
{
indexo3 = 6;
}
if ((o3 <= 179) && (o3 >= 150))
{
indexo3 = 7;
}
if ((o3 <= 209) && (o3 >= 180))
{
indexo3 = 8;
}
if ((o3 <= 239) && (o3 >= 210))
{
indexo3 = 9;
}
if (o3 >= 240)
{
indexo3 = 10;
}
if ((so2 >= 0) && (so2 <= 39))
{
indexso2 = 1;
}
if ((so2 >= 40) && (so2 <= 79))
{
indexso2 = 2;
}
if ((so2 >= 80) && (so2 <= 119))
{
indexso2 = 3;
}
if ((so2 >= 120) && (so2 <= 159))
{
indexso2 = 4;
}
if ((so2 >= 160) && (so2 <= 199))
{
indexso2 = 5;
}
if ((so2 >= 200) && (so2 <= 249))
{
indexso2 = 6;
}
if ((so2 >= 250) && (so2 <= 299))
{
indexso2 = 7;
}
if ((so2 >= 300) && (so2 <= 399))
{
indexso2 = 8;
}
if ((so2 >= 400) && (so2 <= 499))
{
indexso2 = 9;
}
if (so2 >= 500)
{
indexso2 = 10;
}
if ((no2 >= 0) && (no2 <= 29))
{
indexno2 = 1;
}
if ((no2 >= 30) && (no2 <= 54))
{
indexno2 = 2;
}
if ((no2 >= 55) && (no2 <= 84))
{
indexno2 = 3;
}
if ((no2 >= 85) && (no2 <= 109))
{
indexno2 = 4;
}
if ((no2 >= 110) && (no2 <= 134))
{
indexno2 = 5;
}
if ((no2 >= 135) && (no2 <= 164))
{
indexno2 = 6;
}
if ((no2 >= 165) && (no2 <= 199))
{
indexno2 = 7;
}
if ((no2 >= 200) && (no2 <= 274))
{
indexno2 = 8;
}
if ((no2 >= 275) && (no2 <= 399))
{
indexno2 = 9;
}
if (no2 >= 400)
{
indexno2 = 10;
}
if ((pm10 >= 0) && (pm10 <= 6))
{
indexpm = 1;
}
if ((pm10 >= 7) && (pm10 <= 13))
{
indexpm = 2;
}
if ((pm10 >= 14) && (pm10 <= 20))
{
indexpm = 3;
}
if ((pm10 >= 21) && (pm10 <= 27))
{
indexpm = 4;
}
if ((pm10 >= 28) && (pm10 <= 34))
{
indexpm = 5;
}
if ((pm10 >= 35) && (pm10 <= 41))
{
indexpm = 6;
}
if ((pm10 >= 42) && (pm10 <= 49))
{
indexpm = 7;
}
if ((pm10 >= 50) && (pm10 <= 64))
{
indexpm = 8;
}
if ((pm10 >= 65) && (pm10 <= 79))
{
indexpm = 9;
}
if (pm10 >= 80)
{
indexpm = 10;
}
this->atmoIndex = max({indexpm, indexo3, indexno2, indexso2});
} //----- Fin de AirMeasurement
AirMeasurement::AirMeasurement()
// Algorithme :
//
{
#ifdef MAP
cout << "Appel au constructeur de <AirMeasurement>" << endl;
#endif
o3 = 0.0;
so2 = 0.0;
no2 = 0.0;
pm10 = 0.0;
atmoIndex = 0;
} //----- Fin de AirMeasurement
AirMeasurement::~AirMeasurement()
// Algorithme :
//
{
#ifdef MAP
cout << "Appel au destructeur de <AirMeasurement>" << endl;
#endif
} //----- Fin de ~AirMeasurement
//------------------------------------------------------------------ PRIVE
//----------------------------------------------------- Méthodes protégées
//------------------------------------------------------------------friend
AirMeasurement abs(const AirMeasurement &measurement)
{
AirMeasurement *res = new AirMeasurement(
fabs(measurement.o3),
fabs(measurement.so2),
fabs(measurement.no2),
fabs(measurement.pm10));
return *res;
}