48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
/*
|
||
* ForecastDisplay.hpp
|
||
*
|
||
* Created on: 31 окт. 2021 г.
|
||
* Author: alexander
|
||
*/
|
||
|
||
#pragma once
|
||
|
||
#include "Observer.hpp"
|
||
#include "DisplayElement.hpp"
|
||
#include "WeatherData.hpp"
|
||
|
||
class ForecastDisplay: public Observer, public DisplayElement
|
||
{
|
||
private:
|
||
float currentPressure;
|
||
float lastPressure;
|
||
WeatherData &weatherData;
|
||
public:
|
||
ForecastDisplay(WeatherData &weatherData) :
|
||
currentPressure(29.92), lastPressure(0.0), weatherData(weatherData)
|
||
{
|
||
weatherData.registerObserver(*this);
|
||
}
|
||
|
||
void update(float temperature, float humidity, float pressure) override
|
||
{
|
||
this->lastPressure = this->currentPressure;
|
||
this->currentPressure = pressure;
|
||
|
||
display();
|
||
}
|
||
|
||
void display() const override
|
||
{
|
||
std::cout << "Forecast: ";
|
||
if (currentPressure > lastPressure) {
|
||
std::cout << "Improving weather on the way!";
|
||
} else if (currentPressure == lastPressure) {
|
||
std::cout << "More of the same";
|
||
} else if (currentPressure < lastPressure) {
|
||
std::cout << "Watch out for cooler, rainy weather";
|
||
}
|
||
std::cout << std::endl;
|
||
}
|
||
};
|