-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.cpp
More file actions
172 lines (163 loc) · 4.86 KB
/
Copy pathdriver.cpp
File metadata and controls
172 lines (163 loc) · 4.86 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
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
169
170
171
172
#include <iostream>
#include "hash.hpp"
#include "PriorityQueue.hpp"
#include <vector>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <chrono>
using namespace std;
using namespace std::chrono;
void displayMenu() // do not modify
{
cout << "------------------" << endl;
cout << "1: Build the data structure (execute this option one time)" << endl;
cout << "2: Add a review" << endl;
cout << "3: Retrieve most recent review for a restaurant" << endl;
cout << "4: Pop most recent review for a restaurant" << endl;
cout << "5: Print reviews for a restaurant" << endl;
cout << "6: Display number of collisions" << endl;
cout << "7: Display table results" << endl;
cout << "8: Exit" << endl;
cout << "------------------" << endl;
}
int main(int argc, char* argv[])
{
if (argc <3)
{
cout<<"need correct number of arguments"<<endl;
}
string fname = argv[1];
int tableSize = stoi(argv[2]);
int ch = 0;
string chs;
HashTable ht(5);
bool data_built = false;
node *search = nullptr;
while(ch!=8)
{
// Input Validation
// Checks to make sure that the first charcter the user inputs is valid by checking the
// ASCII vaule, (Should be between 49 and 58 for the number 1 - 8)
while(true)
{
displayMenu();
cout << "Enter your choice >>";
getline(cin, chs);
if(chs[0] >= 49 && chs[0] <= 56)
{
chs = chs[0];
ch = stoi(chs);
break;
}
else
{
cout << "That is not a valid input." << endl;
}
}
// Used in case for 2 for implementing
string resturant_name, customer, review, time;
switch (ch)
{
case 1:
{
//Add flag to check if this was already done so it is only called once
if(!data_built)
{
ht.setup(fname);
data_built = true;
cout << "Data structure build sucessful." << endl;
}
else
{
cout << "The data structure has already been built." << endl;
}
break;
}
case 2:
{
//
cout << "Resturant Name: ";
getline(cin, resturant_name);
if(ht.searchItem(resturant_name) == nullptr)
{
cout << "Could not find that resturant." << endl;
}
else
{
cout << "Customer: ";
getline(cin, customer);
cout << "Review: ";
getline(cin, review);
cout << "Time: ";
getline(cin, time);
ReviewInfo ri;
ri.restaurantName = resturant_name;
ri.customer = customer;
ri.review = review;
ri.time = stoi(time);
search = ht.searchItem(resturant_name);
search->pq->insertElement(ri);
}
break;
}
case 3:
{
//
cout << "Resturant Name: ";
getline(cin, resturant_name);
search = ht.searchItem(resturant_name);
if(!search)
{
cout << "Could not find that resturant." << endl;
break;
}
cout << "Retrived Result." << endl;
search->pq->peek();
break;
}
case 4:
{
//
cout << "Resturant Name: ";
getline(cin, resturant_name);
search = ht.searchItem(resturant_name);
if(!search)
{
cout << "Could not find that resturant." << endl;
break;
}
search->pq->pop();
break;
}
case 5:
{
//
cout << "Resturant Name: ";
getline(cin, resturant_name);
search = ht.searchItem(resturant_name);
if(!search)
{
cout << "Could not find that resturant." << endl;
break;
}
search->pq->print();
break;
}
case 6:
//
cout << "Number of Collison: " << ht.getNumCollision();
break;
case 7:
//
ht.displayTable();
break;
case 8:
return 0;
break;
default:
cout << "Enter a valid option." << endl;
break;
}
}
}