47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
/*
|
||
* HeatIndexDisplay.hpp
|
||
*
|
||
* Created on: 31 окт. 2021 г.
|
||
* Author: alexander
|
||
*/
|
||
|
||
#pragma once
|
||
|
||
#include "Observer.hpp"
|
||
#include "DisplayElement.hpp"
|
||
#include "WeatherData.hpp"
|
||
|
||
class HeatIndexDisplay: public Observer, public DisplayElement
|
||
{
|
||
private:
|
||
float heatIndex;
|
||
WeatherData &weatherData;
|
||
|
||
float computeHeatIndex(float t, float rh)
|
||
{
|
||
float index = (float) ((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;
|
||
}
|
||
public:
|
||
HeatIndexDisplay(WeatherData &weatherData) : heatIndex(0.0), weatherData(weatherData)
|
||
{
|
||
weatherData.registerObserver(*this);
|
||
}
|
||
|
||
void update(float temperature, float humidity, float pressure) override
|
||
{
|
||
heatIndex = computeHeatIndex(temperature, humidity);
|
||
|
||
display();
|
||
}
|
||
|
||
void display() const override
|
||
{
|
||
std::cout << "Heat index is " << heatIndex << std::endl;
|
||
}
|
||
};
|