/* * StaticDisplay.hpp * * Created on: 31 окт. 2021 г. * Author: alexander */ #include "Observer.hpp" #include "DisplayElement.hpp" #include "WeatherData.hpp" class StaticDisplay: public Observer, public DisplayElement { private: float maxTemp; float minTemp; float tempSum; int numReadings; WeatherData &weatherData; public: StaticDisplay(WeatherData &weatherData) : maxTemp(0.0), minTemp(200.0), tempSum(0.0), numReadings(0), weatherData(weatherData) { weatherData.registerObserver(*this); } void update(float temperature, float humidity, float pressure) override { this->tempSum += temperature; this->numReadings++; if (temperature > this->maxTemp) { this->maxTemp = temperature; } if (temperature < this->minTemp) { this->minTemp = temperature; } display(); } void display() const override { std::cout << "Avg/Max/Min temperature = " << (tempSum / numReadings) << "/" << maxTemp << "/" << minTemp << std::endl; } };