Question: Please help to correct the code for matching Sample Run below. The text file is also uploaded in my library. Code: #include #include #include #include
Please help to correct the code for matching Sample Run below. The text file is also uploaded in my library.
Code:
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef map
vector
"conjunction", "interjection", "pronoun",
"preposition", "adverb" };
bool data_loading(const string&, Dictionary&, ifstream&);
void search(const string&, Dictionary&);
vector
int main() {
string filename = "./Data.CS..txt";
Dictionary dict;
ifstream in;
data_loading(filename, dict, in);
cout
while (true) {
string str;
cout
getline(cin, str);
if (str == "!Q") {
cout
break;
}
cout
search(str, dict);
cout
}
return 0;
}
bool data_loading(const string& filename, Dictionary& dict, ifstream& in) {
// the delim use to split the word attr and its description
string dict_attr_delim = " -=>> ";
cout
in.open(filename);
if (!in) {
cerr
return false;
}
cout
char buffer[512];
while (!in.eof()) {
in.getline(buffer, 512, ' ');
string bs(buffer, buffer + strlen(buffer));
vector
vector
for (int i = 1; i
vector
pair
details.push_back(p);
}
// sort to make printed in order
sort(details.begin(), details.end());
dict[res[0]] = details;
}
cout
in.close();
cout
return true;
}
vector
vector
string::size_type pos1, pos2;
pos2 = s.find(c);
pos1 = 0;
while (string::npos != pos2) {
v.push_back(s.substr(pos1, pos2 - pos1));
pos1 = pos2 + c.size();
pos2 = s.find(c, pos1);
}
if (pos1 != s.length()) v.push_back(s.substr(pos1));
return v;
}
void search(const string& str, Dictionary& dict) {
// split the search str, check whether the search str has three fields
vector
string search_key = res[0];
string search_attr = "";
bool distinct = false;
if (res.size() > 1) {
if (res[1] == "distinct") {
distinct = true;
}
else {
search_attr = res[1];
}
}
if (res.size() > 2) {
distinct = true;
}
// check whether the input parameter is valid
if (search_attr != "") {
vector
find(part_of_speech.begin(), part_of_speech.end(), search_attr);
if (it == part_of_speech.end()) {
cout
"
return;
}
}
// convert all upper case letter to lower case
for (int i = 0; i
if (search_key[i] >= 'A' && search_key[i]
search_key[i] += 32;
}
}
// convert the first letter to upper case for printing the result
string print_key = search_key;
print_key[0] -= 32;
// the course name should all be upper case
for (int i = 1; i
if (search_key[i] >= '0' && search_key[i]
for (int j = 1; j
print_key[j] -= 32;
}
break;
}
}
// some special deal when distinct flag is true, using "set" data structure
set
int res_counter = 0;
for (int i = 0; i
if (distinct) {
if (search_attr == "" || dict[search_key][i].first == search_attr) {
res_counter++;
distinct_res.insert(
make_pair(dict[search_key][i].first, dict[search_key][i].second));
}
}
else if (search_attr == "" || dict[search_key][i].first == search_attr) {
res_counter++;
cout
}
}
if (res_counter == 0) {
cout "
return;
}
if (distinct) {
for (auto iter = distinct_res.begin(); iter != distinct_res.end(); iter++) {
cout
}
}
}
Data.CS.txt:
arrow|noun -=>> Here is one arrow: -=>> ..
book|noun -=>> A set of pages.|verb -=>> To arrange something on a particular date.|verb -=>> to arrange for someone to have a seat on a plane.|noun -=>> A written work published in printed or electronic form.
bookable|adjective -=>> Can be ordered in advanced.
bookbinder|noun -=>> A person who fastens the pages of books.
bookcase|noun -=>> A piece of furniture with shelves.
csc210|adjective -=>> ready for CSC 220.|adjective -=>> Comfortable with Objects and Classes.|noun -=>> Intro to Java.|verb -=>> To learn Java.
csc220|noun -=>> data Structures.|verb -=>> To create data structures.|adjective -=>> Ready to create complex data structures.
csc340|adjective -=>> = C++ version of CSC210 + CSC220 + more.|noun -=>> a CS upper division course.|noun -=>> many hours outside of class.|noun -=>> Programming Methodology.
placeholder|noun -=>> To be updated...|adjective -=>> To be updated...|adjective -=>> To be updated...|adverb -=>> To be updated...|conjunction -=>> To be updated...|interjection -=>> To be updated...|noun -=>> To be updated...|noun -=>> To be updated...|preposition -=>> To be updated...|pronoun -=>> To be updated...|verb -=>> To be updated...
distinct|noun -=>> Distinct is a parameter in this assignment.|noun -=>> a keyword in this assignment.|adjective -=>> unique. No duplicates. Clearly different or of a different kind.|adjective -=>> Familiar. Worked in Java.|noun -=>> An advanced search option.|noun -=>> A keyword in this assignment.|noun -=>> A keyword in this assignment.|adverb -=>> Uniquely. Written "distinctly".
adverb|noun -=>> Adverb is a word that adds more information about place, time, manner, cause or degree to a verb, an adjective, a phrase or another adverb.
adjective|noun -=>> Adjective is a word that describes a person or thing, for example big, red and clever in a big house, red wine and a clever idea.
conjunction|noun -=>> Conjunction is a word that joins words, phrases or sentences, for example 'and', 'but', 'or'.
interjection|noun -=>> Interjection is a short sound, word or phrase spoken suddenly to express an emotion. Oh!, Look out! and Ow! are interjections.
noun|noun -=>> Noun is a word that refers to a person, (such as Ann or doctor), a place (such as Paris or city) or a thing, a quality or an activity (such as plant, sorrow or tennis).
preposition|noun -=>> preposition is a word or group of words, such as in, from, to, out of and on behalf of, used before a noun or pronoun to show place, position, time or method.
pronoun|noun -=>> pronoun is a word that is used instead of a noun or noun phrase, for example he, it, hers, me, them, etc...
verb|noun -=>> verb is a word or group of words that expresses an action (such as eat), an event (such as happen) or a state (such as exist).
reverse|verb -=>> Change something to opposite.|verb -=>> go back.|verb -=>> turn something inside out.|verb -=>> revoke ruling.|adjective -=>> Opposite to usual or previous arrangement.|adjective -=>> On back side.|noun -=>> The opposite.|noun -=>> Change to opposite direction.|noun -=>> A dictionary program's parameter.|noun -=>> To be updated...|verb -=>> To be updated...|noun -=>> To be updated...|noun -=>> To be updated...|verb -=>> To be updated...|noun -=>> To be updated...
Sample Run:





Placeholder [adverb] : To be updated. . . Placeholder [conjunction] : To be updated. . . Placeholder [interjection] : To be updated. . . Placeholder [noun] : To be updated. .. Placeholder [preposition] : To be updated. . . Placeholder [pronoun] : To be updated. . . Placeholder [verb] : To be updated. . . Search [ll] : placeHolder adjective reverse Placeholder [adjective] : To be updated. . . Placeholder [adjective] : To be updated. . . Search [12]: distinCT DISTINct Distinct [adjective] : Familiar. Worked in Java. Distinct [adjective] : Unique. No duplicates. Clearly different or of a different kind. Distinct [adverb] : Uniquely. Written "distinctly". Distinct [noun] : A keyword in this assignment. Distinct [noun] : An advanced search option. Distinct [noun] : Distinct is a parameter in this assignment. Search [13]: distinct noun distinct REVERSE Distinct [noun] : Distinct is a parameter in this assignment. Distinct [noun] : An advanced search option. Distinct [noun] : A keyword in this assignment. Search [14] : reverse reverse Reverse [verb] : Turn something inside out. Reverse [verb] To be updated. . . Reverse [verb] To be updated. . . Reverse [verb] Revoke ruling. Reverse [verb] Go back Reverse [verb] Change something to opposite. Reverse [noun] To be updated. . . Reverse [noun] To be updated. . . Reverse [noun] To be updated. . . Reverse [noun] To be updated. . . Reverse [noun] The opposite Reverse [noun] : Change to opposite direction. Reverse [noun] : A dictionary program's parameter. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [adjective] : On back side. Search [15] : reverse distinct reVERSE Reverse [verb] : Turn something inside out. Reverse [verb] To be updated. . . Reverse [verb] Revoke ruling. Reverse [verb] Go back Reverse [verb] : Change something to opposite. Reverse [noun] : To be updated. . . Reverse [noun] : The opposite, Reverse [noun] : Change to opposite direction. Reverse [noun] : A dictionary program's parameter. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [adjective] : On back side. Search [16] : reverse ok
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
