-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (69 loc) · 1.68 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (69 loc) · 1.68 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
#include <string>
#include <fstream>
#include <iostream>
#include "stringset.h"
using namespace std;
void spellcheck(void)
{
Stringset S;
string word;
string alternative;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
ifstream wordfile("words.txt");
while (wordfile >> word)
S.insert(word);
wordfile.close();
cout << "Dictionary loaded. Please enter words to spell check.\n";
while (cin >> word) {
cout << "Possible alternatives for word '" << word << "':\n";
// TBD: print out all words that differ by exactly one character...
alternative = word;
for (char &w:alternative) {
for (const char &c:alphabet) {
w = c;
if (S.find(alternative) && alternative != word)
cout << alternative << "\n";
}
alternative = word;
}
}
}
void test(void)
{
Stringset S;
string key, command;
while(cin >> command) {
if (command == "insert") {
cin >> key;
if (S.find(key))
cout << "Error! Key " << key << " already in structure!\n";
else
S.insert(key);
} else if (command == "remove") {
cin >> key;
if (!S.find(key))
cout << "Error! Key " << key << " not in structure!\n";
else
S.remove(key);
} else if (command == "find") {
cin >> key;
if (S.find(key))
cout << "Key " << key << " present.\n";
else
cout << "Key " << key << " absent.\n";
} else if (command == "print") {
cout << "Contents of structure:\n";
S.print();
} else if (command == "quit") {
break;
} else {
cout << "Error! Unknown command '" << command << "'!\n";
}
}
}
int main(void)
{
//test();
spellcheck();
return 0;
}