-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeatIndex.h
50 lines (40 loc) · 1.39 KB
/
HeatIndex.h
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
#ifndef HEAT_INDEX_H
#define HEAT_INDEX_H
#include "Subject.h"
#include "Observer.h"
#include "DisplayElement.h"
#include <iostream>
double computeHeatIndex(const double &, const double &);
class HeatIndex : public Observer, public DisplayElement {
public:
HeatIndex(Subject *wd) : weatherData(wd) { weatherData->registerObserver(this); }
void update(double t, double h, double p) override;
void display() const override;
private:
double heatIndex = 0.0f;
Subject *weatherData;
};
inline
void
HeatIndex::update(double t, double h, [[maybe_unused]] double p) {
heatIndex = computeHeatIndex(t, h);
display();
}
inline
void
HeatIndex::display() const {
std::cout << "Heat Index is " << heatIndex << '\n';
}
// non-member function
inline
double computeHeatIndex(const double &t, const double &rh) {
double index = (double)((16.923 + (0.185212 * t) + (5.37941 * rh) - (0.100254 * t * rh)
+ (0.00941695 * (t * t)) + (0.00728898 * (rh * rh))
+ (0.000345372 * (t * t * rh)) - (0.000814971 * (t * rh * rh)) +
(0.0000102102 * (t * t * rh * rh)) - (0.000038646 * (t * t * t)) + (0.0000291583 *
(rh * rh * rh)) + (0.00000142721 * (t * t * t * rh)) +
(0.000000197483 * (t * rh * rh * rh)) - (0.0000000218429 * (t * t * t * rh * rh)) +
0.000000000843296 * (t * t * rh * rh * rh)) - (0.0000000000481975 * (t * t * t * rh * rh * rh)));
return index;
}
#endif /* ifndef HEAT_INDEX_H */