-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMKweather.cpp
161 lines (140 loc) · 6.05 KB
/
MKweather.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* MKweather.cpp, this is the executable main file */
#include <iostream>
#include <string>
#include <fstream> //included lib for read from file function
#include "Functions.h" //include all weather functions
using namespace std;
/* Driver program. */
int main(){
weatherData weatherDataArray[131]; //Creating an array with an index of 131, this is where the data will be saved later on
int arraySize = sizeof(weatherDataArray) / sizeof(weatherDataArray[0]); //calculating size of array, useful when calculating mean values
int i = 0; //This int is used locally in main() for case 7 & 8 in switch later on
string date; //Creating variables to save the data from when we read text file "tempdata4.txt"
string time;
string inOut;
string temperature;
string humidity;
float count = 0; //Counters used to calculate mean value
float inCount = 0;
float outCount = 0;
string currentDate = ""; //Date variables to check date in if conditions
string checkDate = "";
weatherData data; //From weatherData data we can access our struct variables
int userInput; //To navigate the menu and search for dates we need user input
string userSearch;
ifstream text("tempdata4.txt"); //This is the text file we want to read from
if (text.is_open())
{
while (!text.eof())
{
getline(text, date, ' '); //getline() reads from file
getline(text, time, ',');
getline(text, inOut, ',');
getline(text, temperature, ',');
getline(text, humidity);
if (date == checkDate) //If the date from "tempdata4.txt" is equal to the checkdate we start to separate the data into inside and outside data. This will not happen the first date we read.
{
if (inOut == "Inne") //With this if condition we want to seperate the outside and inside data to be able to calculate mean values
{
//Save temperatures and humidity data from "inne" as floats and ints to calculate later with the inCounter
data.tempAverageIn += stof(temperature);
data.humAverageIn += stof(humidity);
inCount++;
}
if (inOut == "Ute")
{
//Same here: save temperatures and humidity data from "ute" as floats and ints to calculate later with the outCounter
data.tempAverageOut += stof(temperature);
data.humAverageOut += stof(humidity);
data.fallDate += stof(temperature);
outCount++;
}
currentDate = date;
count++;
}
else
{
checkDate = date;
if (count != 0)
{
data.date = currentDate; //Calculate all mean values and fall date
data.tempAverageIn = data.tempAverageIn / inCount;
data.humAverageIn = data.humAverageIn / inCount;
data.fallDate = data.fallDate / outCount;
data.tempAverageOut = data.tempAverageOut / outCount;
data.humAverageOut = data.humAverageOut / outCount;
data.moldIndex = moldIndex(data.tempAverageOut, data.humAverageOut); //saves moldIndex() function in moldIndex variable
weatherDataArray[i] = data; //This saves our data in the weatherDataArray
inCount = 0; //Reset all values to 0 before entering next getline()
outCount = 0;
data.tempAverageIn = 0;
data.humAverageIn = 0;
data.tempAverageOut = 0;
data.humAverageOut = 0;
i++;
}
}
}
}
do
{
printMenu(); //Prints menu
cin >> userInput; //Takes in user input to be used on the switch cases
cout << endl;
switch (userInput)
{
case 1:
cout << "When searching use this format to access date -> yyyy-mm-dd: ";
cin >> userSearch;
cout << endl;
searchAll(weatherDataArray, userSearch, arraySize);
cout << endl;
break;
case 2: //To find fall date we have to select this case before case 4 - 8 because all dates are sorted when we first read from text file, the other cases sort their data
cout << endl;
findFall(weatherDataArray, weatherDataArray[i].fallDate, arraySize);
cout << endl;
break;
case 3:
cout << endl;
findWinter(weatherDataArray, weatherDataArray[i].tempAverageOut, arraySize);
cout << endl;
break;
case 4:
cout << endl;
sortTempInside(weatherDataArray, arraySize);
printTempInside(weatherDataArray, arraySize);
cout << endl;
break;
case 5:
cout << endl;
sortHumidityInside(weatherDataArray, arraySize);
printHumidityInside(weatherDataArray);
cout << endl;
break;
case 6:
cout << endl;
sortTempOutside(weatherDataArray, arraySize);
printTempOutside(weatherDataArray, arraySize);
cout << endl;
break;
case 7:
cout << endl;
sortHumidityOutside(weatherDataArray, arraySize);
printHumidityOutside(weatherDataArray);
cout << endl;
break;
case 8:
cout << endl;
sortMoldIndex(weatherDataArray, arraySize);
printMoldIndex(weatherDataArray, arraySize);
cout << endl;
break;
default:
cout << "OOOPS " << userInput << " is not a valid input you can use in this menu. Do try again." << endl;
cout << endl;
break;
}
} while (userInput != 0);
cout << "Good bye" << endl;
}