Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (49 loc) · 1.67 KB
/
Copy pathmain.cpp
File metadata and controls
60 lines (49 loc) · 1.67 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
/******************************************************************
Title: main.cpp
Author: Erin Williams
Date Created: 4/30/2017
Class: Spring 2017, CSCI 235-04, Mon & Wed 7:00pm-8:15pm
Professor: Aarsh Vora
Purpose: Assignment #3
Description: main file for Assignment 3 - Autocomplete
*******************************************************************/
#include <fstream>
#include <iostream>
#include <cassert>
#include <vector>
#include "trie.h"
#include "trienode.h"
#include "dictionary.h"
int main(int argc, char *argv[]) {
//Only one command line arguement is accepted, or program ends
if(argc != 2) {
std::cout << "No command line argument, program ending.\n";
return 0;
}
else {
//Command line arguement is name of file
std::ifstream file(argv[1]);
if(!file) {
std::cout << "Command line argument was not the name of a file. Program ending.\n";
return 0;
}
dictwilliams::Dictionary dict(file);
std::string inputString;
int numSuggestions;
while(true) {
std::cout << "Enter a string to be autocompleted: ";
std::cin >> inputString;
std::cout << "Enter number of suggestions: ";
std::cin >> numSuggestions;
std::vector<std::string> vec = dict.suggest(inputString, numSuggestions);
if(vec.empty()) {
std::cout << "No suggestions!\n";
}
for(unsigned int i = 0; i < vec.size(); ++i) {
std::cout << vec[i] << std::endl;
}
}
file.close();
}
return 0;
}