This repository has been archived on 2022-11-09. You can view files and clone it, but cannot push or open issues or pull requests.
patterns-old/lesson_2/CurrentConditionsDisplay.hpp

39 lines
899 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* CurrentConditionsDisplay.hpp
*
* Created on: 31 окт. 2021 г.
* Author: alexander
*/
#pragma once
#include "Observer.hpp"
#include "DisplayElement.hpp"
#include "WeatherData.hpp"
class CurrentConditionsDisplay: public Observer, public DisplayElement
{
private:
float temperature;
float humidity;
WeatherData &weatherData;
public:
CurrentConditionsDisplay(WeatherData &weatherData) :
temperature(0.0), humidity(0.0), weatherData(weatherData)
{
weatherData.registerObserver(*this);
}
void update(float temperature, float humidity, float pressure) override
{
this->temperature = temperature;
this->humidity = humidity;
display();
}
void display() const override
{
std::cout << "Current conditions: " << temperature << "F degrees and " << humidity << "% humidity" << std::endl;
}
};