-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCsvSearch.cpp
151 lines (118 loc) · 3.26 KB
/
CsvSearch.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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
ifstream ip("data1.csv");
if(!ip.is_open()) std::cout << "ERROR OPENING FILE" << '\n';
string timestamp;
string city;
string temperature;
string light;
string airquality_raw;
string sound;
string humidity;
string dust;
string day;
string month;
string year;
string cityinput;
string dayinput;
string monthinput;
string yearinput;
string choice;
cout<<"Press 1 to search City\n";
cout<<"Press 2 to search Day\n";
cout<<"Press 3 to search Month\n";
cout<<"Press 4 to search Year\n";
cin>> choice;
// cout <<choice;
if (choice == "1"){
cout<<"Enter City\n";
cin>> cityinput;
while(ip.good()){
getline(ip,timestamp,',');
getline(ip,city,',');
getline(ip,temperature,',');
getline(ip,light,',');
getline(ip,airquality_raw,',');
getline(ip,sound,',');
getline(ip,humidity,',');
getline(ip,dust,',');
getline(ip,year, ',');
getline(ip,month,',');
getline(ip,day,'\n');
if (cityinput == city)
{
std::cout<<timestamp <<" "<<city<< " " <<temperature<<" "<<light<<" " <<airquality_raw<<" "<<sound<<" "<<humidity<< " " << dust<< '\n';
}
}
ip.close();
}
if (choice == "2"){
cout<<"Enter Day\n";
cin>> dayinput;
while(ip.good()){
getline(ip,timestamp,',');
getline(ip,city,',');
getline(ip,temperature,',');
getline(ip,light,',');
getline(ip,airquality_raw,',');
getline(ip,sound,',');
getline(ip,humidity,',');
getline(ip,dust,',');
getline(ip,year, ',');
getline(ip,month,',');
getline(ip,day,'\n');
if (dayinput == day)
{
std::cout<<timestamp <<" "<<city<< " " <<temperature<<" "<<light<<" " <<airquality_raw<<" "<<sound<<" "<<humidity<< " " << dust<< '\n';
}
}
ip.close();
}
if (choice == "3"){
cout<<"Enter Month\n";
cin>> monthinput;
while(ip.good()){
getline(ip,timestamp,',');
getline(ip,city,',');
getline(ip,temperature,',');
getline(ip,light,',');
getline(ip,airquality_raw,',');
getline(ip,sound,',');
getline(ip,humidity,',');
getline(ip,dust,',');
getline(ip,year, ',');
getline(ip,month,',');
getline(ip,day,'\n');
if (monthinput == month)
{
std::cout<<timestamp <<" "<<city<< " " <<temperature<<" "<<light<<" " <<airquality_raw<<" "<<sound<<" "<<humidity<< " " << dust<< '\n';
}
}
ip.close();
}
if (choice == "4"){
cout<<"Enter Year\n";
cin>> yearinput;
while(ip.good()){
getline(ip,timestamp,',');
getline(ip,city,',');
getline(ip,temperature,',');
getline(ip,light,',');
getline(ip,airquality_raw,',');
getline(ip,sound,',');
getline(ip,humidity,',');
getline(ip,dust,',');
getline(ip,year, ',');
getline(ip,month,',');
getline(ip,day,'\n');
if (yearinput == year)
{
std::cout<<timestamp <<" "<<city<< " " <<temperature<<" "<<light<<" " <<airquality_raw<<" "<<sound<<" "<<humidity<< " " << dust<< '\n';
}
}
ip.close();
}
}