-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemperature_reading.h
58 lines (48 loc) · 1.77 KB
/
temperature_reading.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <iostream>
#include <string>
#include <vector>
/**
* This file contains data structures to represent a structured file of temperature readings:
*
* - A file holds years
* - A year starts with "{ year" followed by an integer giving the year, zero or more months,
* and ends with "}"
* - A month starts with "{ month" followed by a three-letter month name, zero or more readings,
* and ends with "}"
* - A reading starts with a "(" followed by day of the month, hour of the day, and temperature,
* and ends with a ")"
*/
const int not_a_reading = -7777; // less than absolute zero
const int not_a_month = -1;
const int implausible_min = -200;
const int implausible_max = 200;
// a day of temperature readings
struct Day {
std::vector<double> hour = std::vector<double>(24, not_a_reading);
};
// a month of temperature readings
struct Month {
int month = not_a_month; // [0:11] January is 0
std::vector<Day> day{32}; // [1:31] one vector of readings per day
};
// a year of temperature readings, organized by month
struct Year {
int year; // positive == A.D.
std::vector<Month> month{12}; // [0:11] January is 0
};
struct Reading {
int day;
int hour;
double temperature;
};
std::istream& operator>>(std::istream& is, Reading& r);
std::istream& operator>>(std::istream& is, Month& m);
std::istream& operator>>(std::istream& is, Year& y);
int month_to_int(const std::string& s);
std::string int_to_month(int m);
bool is_valid(const Reading& r);
void end_of_loop(std::istream& ist, char terminator, const std::string& message);
std::ostream& operator<<(std::ostream& os, const Reading& r);
std::ostream& operator<<(std::ostream& os, const Month& m);
std::ostream& operator<<(std::ostream& os, const Year& y);