-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
168 lines (145 loc) · 6.23 KB
/
main.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
162
163
164
165
166
167
168
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "Sample.h"
#include "Helpers.h"
#include "Algorithms.h"
using namespace std;
int main() {
// Constants
const string SAMPLE_DATA = "Project3data.csv";
const int SAMPLE_SIZE = 181546;
const int UNDEFINED = -99;
ifstream inFile(SAMPLE_DATA);
string inputData;
getline(inFile, inputData);
string latitude, longitude, waterDepth, obsvnTop, obsvnBot, gravel, sand, mud, clay, grainSize, sorting, munslColr, orgCarbn, porosity;
auto *samples = new Sample[SAMPLE_SIZE];
int index = 0;
while (getline(inFile, inputData)) {
istringstream stream(inputData);
getline(stream, latitude, ',');
getline(stream, longitude, ',');
getline(stream, waterDepth, ',');
getline(stream, obsvnTop, ',');
getline(stream, obsvnBot, ',');
getline(stream, gravel, ',');
getline(stream, sand, ',');
getline(stream, mud, ',');
getline(stream, clay, ',');
getline(stream, grainSize, ',');
getline(stream, sorting, ',');
getline(stream, munslColr, ',');
getline(stream, orgCarbn, ',');
getline(stream, porosity, ',');
Sample log(stof(latitude), stof(longitude), stof(waterDepth), stof(obsvnTop),
stof(obsvnBot), stof(gravel), stof(sand), stof(mud), stof(clay), stof(grainSize),
stof(sorting), munslColr, stof(orgCarbn), stof(porosity));
samples[index] = log;
index++;
}
int valueType = 0;
int sortType = 0;
DataType result;
cout << "Welcome to the Camparison of Sediment Rates on the Coast of the US and its Territories Program! \n";
cout << "Choose what to sort by! \n";
cout << "1. Latitude\n2. Longitude\n3. Water Depth\n4. Gravel\n5. Sand\n6. Mud\n7. Clay\n8. Grain Size\n9. Standard Deviation of Grain Size in Sample\n10. Percent Carbon\n11. Porosity\n";
while (valueType < 1 || valueType > 11) {
cin >> valueType;
switch (valueType) {
case 1: result = Latitude; break;
case 2: result = Longitude; break;
case 3: result = WaterDepth; break;
case 4: result = Gravel; break;
case 5: result = Sand; break;
case 6: result = Mud; break;
case 7: result = Clay; break;
case 8: result = GrainSize; break;
case 9: result = Sorting; break;
case 10: result = OrgCarbn; break;
case 11: result = Porosity; break;
default: cout << "Please choose a valid response!\n"; valueType = 12; break;
}
if (valueType == 12) {
continue;
}
}
cout << "\nChoose how to Sort!\n";
cout << "1. Merge Sort\n2. Quick Sort\n3. Shell Sort\n";
while (sortType < 1 || sortType > 3) {
cin >> sortType;
switch (sortType) {
case 1: {
auto t1 = Clock::now();
mergeSort(samples, 0, SAMPLE_SIZE, result);
auto t2 = Clock::now();
cout << "The Merge Sort took " << duration_cast<nanoseconds>(t2 - t1).count() << " nano seconds to run." << endl;
break;
}
case 2: {
auto t1 = Clock::now();
QuickSort(samples, 0, SAMPLE_SIZE - 1, result);
auto t2 = Clock::now();
cout << "The Quick Sort took " << duration_cast<seconds>(t2 - t1).count() << " seconds to run." << endl;
break;
}
case 3:
cout << "Which sequence do you want to use?\n";
cout << "1. Sedgewick\n2. Hibbard\n";
while (sortType < 1 || sortType > 2) {
cin >> sortType;
switch (sortType) {
case 1: shellSort(samples, SAMPLE_SIZE, Sedgewick, result); break;
case 2: shellSort(samples, SAMPLE_SIZE, Hibbard, result); break;
default: cout << "Please choose a valid response!\n"; break;
}
}
break;
default: cout << "Please choose a valid response!\n"; break;
}
}
// for (int i = SAMPLE_SIZE - 1; i >= 100; i--) {
// cout << fixed << showpoint;
// cout << setprecision(2);
// cout << ArrayType(samples, i, result) << " ";
// }
cout << endl;
float searchVal;
string tempStr;
cout << "Choose a value of your type " << "to search for!" << endl;
cin >> tempStr;
searchVal = stof(tempStr);
index = Search(samples, 0, SAMPLE_SIZE - 1, searchVal, result);
//index = Search(samples, 0, SAMPLE_SIZE - 1, searchVal, result);
if (searchVal == UNDEFINED) {
cout << "Sorry, there is no sample corresponding to this value. Goobye!" << endl;
}
else {
cout << "Latitude: " << samples[index].latitude << endl;
cout << "Longitude: " << samples[index].longitude << endl;
cout << "Water Depth: " << samples[index].waterDepth << endl;
cout << "Observation Top: " << samples[index].obsvnTop << endl;
cout << "Observation Bottom: " << samples[index].obsvnBot << endl;
cout << "Gravel: " << samples[index].gravel << endl;
cout << "Sand: " << samples[index].sand << endl;
cout << "Mud: " << samples[index].mud << endl;
cout << "Clay: " << samples[index].clay << endl;
cout << "Grain Size: " << samples[index].grainSize << endl;
cout << "Sorting: " << samples[index].sorting << endl;
cout << "Organic Carbon Ratio: " << samples[index].orgCarbn << endl;
cout << "Porosity: " << samples[index].porosity << endl;
cout << endl;
cout << "Here are similar samples and their locations!" << endl;
cout << "Latitude: " << samples[index + 1].latitude << " Longitude: " << samples[index + 1].longitude << endl;
cout << "Latitude: " << samples[index - 1].latitude << " Longitude: " << samples[index - 1].longitude << endl;
cout << endl;
cout << endl;
}
return 0;
}
//Citation for Shell Sort sequences
//Source: https://en.wikipedia.org/wiki/Shellsort
//Use: Source for conceptualization of shell sort sequences