This repository has been archived by the owner on Sep 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
completer.cpp
69 lines (60 loc) · 1.64 KB
/
completer.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
#include <fstream>
#include <iostream>
#include <algorithm>
#include "search.h"
#include <string>
using namespace std;
//Displays instructions
void info() {
cout << "Search for strings by partial match.\n" << "Type C-z to halt." << endl;
}
//Function for getting user input for Yes/No
void decFunc(string &decision, string &word) {
if (decision == "y" || decision == "Y" || decision == "Yes" || decision == "YES" || decision == "yes") {
cout << "ok: accepting " << word << "\n";
}
else if (decision == "n" || decision == "N" || decision == "No" || decision == "NO" || decision == "no") {
cout << "ok: rejecting " << word << "\n";
}
}
//Function for reading the file and copying words into the vector
void readWords(ifstream &in,string &file,std::vector<string> &storage) {
in.open(file);
while (in.good())
{
std::string line;
getline(in, line);
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
storage.push_back(line);
}
}
int main(int argc, char *argv[])
{
string file;
string rword;
bool check = true;
std::vector<std::string> arguments;
for (int i = 0; i < argc; ++i) arguments.push_back(argv[i]);
file =argv[1] ;
ifstream in;
std::vector<string> myVec;
readWords(in,file, myVec);
while (check==true) {
info();
cin >> rword;
if (cin.eof()) {
break;
}
SearchResultType<string> result=iterative_binary_search(myVec, rword);
if (result.found == true) {
cout << "found: accepting " << rword << "\n";
}
else if (result.found == false) {
cout << "Not found: accept " << result.value << "? Y/N: ";
string decision;
cin >> decision;
decFunc(decision, result.value);
}
}
return 0;
}