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>> Dictionary;

vector part_of_speech = { "verb", "noun", "adjective",

"conjunction", "interjection", "pronoun",

"preposition", "adverb" };

bool data_loading(const string&, Dictionary&, ifstream&);

void search(const string&, Dictionary&);

vector split(const string&, const string&);

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 res = split(bs, "|");

vector> details;

for (int i = 1; i

vector detail_res = split(res[i], dict_attr_delim);

pair p = make_pair(detail_res[0], detail_res[1]);

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 split(const string& s, const string& c) {

vector v;

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 res = split(str, " ");

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::iterator it =

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> distinct_res;

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:

Please help to correct the code for matching Sample Run below. ThePlease help to correct the code for matchingPlease help to correct the code for matchingPlease help to correct the code for matchingPlease help to correct the code for matching

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 Reverse [adjective] : On back side. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [noun] : A dictionary program's parameter.Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] : To be updated. . . Reverse [noun] To be updated. .. Reverse [noun] To be updated. . . Reverse [noun] : To be updated. . . Reverse [verb] : Change something to opposite. Reverse [verb] : Go back Reverse [verb] : Revoke ruling. Reverse [verb] : To be updated. . . Reverse [verb] To be updated. . . Reverse [verb] : Turn something inside out. Search [17] : reverse noun ok Reverse [noun] : A dictionary program's parameter. Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] : To be updated. . . Reverse [noun] : To be updated. . . Reverse [noun] : To be updated. . . Reverse [noun] : To be updated. . . Search [18] : reverse noun ok distinct "The entered 4th parameter 'distinct' was disregarded.> Reverse [noun] : A dictionary program's parameter. Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun ] : To be updated. . . Reverse [noun] : To be updated. . . Reverse [noun] : To be updated. . . Reverse [noun] : To be updated. . . Search [19] : reverse noun distinct ok Reverse [noun] : A dictionary program's parameter. Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] : To be updated. . . Search [20]: reverse ok ok ok (The entered 4th parameter 'ok' was disregarded.> Reverse [adjective] : On back side. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [noun] : A dictionary program's parameter. Reverse [noun] Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] To be updated. . . Reverse [noun] : To be updated. . . Reverse [noun] To be updated. . . Reverse [noun] : To be updated. . . Reverse [verb] : Change something to opposite. Reverse [verb] : Go back Reverse [verb] : Revoke ruling. Reverse [verb] To be updated. . . Reverse [verb] : To be updated. . . Reverse [verb] : Turn something inside out. Search [21] : reverse reverse ok ok 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] 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 [22] : reverse distinct reverse ok 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 [23]: reverse distinct reverse ok ok PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' Search [24]: reverse adverb To be considered for the next release. Thank you. PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' Search [25]: facebook To be considered for the next release. Thank you. PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' Search [26]: !Q ----THANK YOU-----Opening data file. . . C: \\Users\\MickeyMouse\\AbsolutePath\\DB\\Data. CS. SFSU. txt ERROR ===> File could not be opened. ERROR > > Provided file path: C: \\Users\\MickeyMouse\\AbsolutePath\\DB\\Data. CS. SFSU, txt Enter the CORRECT data file path: ./Data. CS. SFSU. txt Loading data. . . Loading completed. . . ! Closing data file. . . . /Data . CS . SFSU. txt DICTIONARY 340 C++ mmm Keywords : 19 Definitions: 61 Search [1] : !help PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' Search [2] : PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' Search [3] : aRRow Arrow [noun] : Here is one arrow: -=>> . Search [4]: adverb 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. Search [5] : noun noun reverse 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) . Search [6] : cSc220 csc220 [adjective] : Ready to create complex data structures. csc220 [noun] : Data Structures. csc220 [verb] To create data structures. Search [7]: CSc340 noun distinct REVERSE CSC340 [noun] : Programming Methodology. CSC340 [noun] : Many hours outside of class. CSC340 [noun] : A CS upper division course. Search [8]: book NOUN distinct reverse Book [noun] : A written work published in printed or electronic form. Book [noun] : A set of pages. Search [9]: placeHOLDER Placeholder [adjective] : To be updated. .. Placeholder [adjective] : To be updated. . . Placeholder [adverb] : To be updated. . . Placeholder [conjunction] : To be updated. . . Placeholder [interjection] : To be updated. . . Placeholder [noun] : To be updated. . . Placeholder [noun] To be updated. . . Placeholder [noun] To be updated. . . Placeholder [preposition] : To be updated. . . Placeholder [pronoun] : To be updated. . . Placeholder [verb] : To be updated. . . Search [10]: placeholder distinct Placeholder [adjective] : To be updated

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!