-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForcastDisplay.h
More file actions
41 lines (36 loc) · 1.08 KB
/
ForcastDisplay.h
File metadata and controls
41 lines (36 loc) · 1.08 KB
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
#ifndef FORCAST_DISPLAY_H
#define FORCAST_DISPLAY_H
#include "DisplayElement.h"
#include "Observer.h"
#include "Subject.h"
#include <iostream>
class ForcastDisplay : public Observer, public DisplayElement {
public:
ForcastDisplay() = default;
ForcastDisplay(Subject *wd) : weatherData(wd) { weatherData->registerObserver(this); }
void update(double t, double h, double p) override;
void display() const override;
private:
double currentPressure = 29.92f;
double prevPressure = 0.0f;
Subject *weatherData = nullptr;
};
inline
void
ForcastDisplay::update([[maybe_unused]] double t, [[maybe_unused]] double h, double p) {
prevPressure = currentPressure;
currentPressure = p;
display();
}
inline
void
ForcastDisplay::display() const {
std::cout << "Forcast: ";
if (currentPressure > prevPressure)
std::cout << "Improving weather on the way!\n";
else if (currentPressure == prevPressure)
std::cout << "Forcast: More of the same\n";
else if (currentPressure < prevPressure)
std::cout << "Forcast: Watch out for cooler, rainy weather\n";
}
#endif /* ifndef FORCAST_DISPLAY_H */