Menu

(Solved) : Part 1 First Step Project Implement C Function Map Getcounts String Filename File Name Tex Q35631367 . . .

Part 1:
For the first step of the project, implement in C++ afunction:
map<string, int> get_counts(string file_name) {}

file name: textFile.txt
Early to bed and early to rise makes a man healthy, wealthy, andwise. I think, therefore I am. It does not matter how slowly you goso long as you do not stop. Love the life you live. Live the lifeyou love.
**Note the removal of the capitalization and punctuation.

int main()
{
map<string, int> r = get_counts(“testFile.txt”);
cout << “early: ” << r[“early”] << endl;
cout << “you: ” << r[“lyou”] << endl;
cout << ” love: ” << r[“love “] << endl;
cout << ” the: ” << r[“the “] << endl;
cin.get();
}

The output should be:

early: 2
you: 4
love: 2
the: 2

Note that the way used to remove punctuation may affect thesenumbers by a small percentage.
Submit your .ccp file (not the .sln file)

part 2:
Using the file in Part 1, the following code:

use the map created in part 1 to implement the followingfunction:
string get_suggestion(map<string, int> counts, stringinput)

Which given the map and a string, it returns the most likelyword to be auto-completed. Most likely equals the word thatstarting with the input string appears the most in the text.

int main()
{
map<string, int> r = get_counts(“testFile.txt “);
vector<string> input =
{
“t”, “th”, “the”,
“l”, “lo”, “lov”, “love”,
“y”, “yo”, “you”,
“e”, “ea”, “ear”, “earl”, “early”,
};

for (string s : input)
{
cout << s << “: ” << get_suggestion(r, s)<< endl;
}
}

Should output the following:

t: the
th: the
the: the

l: long
lo: long
lov: love
love: love

y: you
yo: you
you: you
e: early
ea: early
ear: early
earl: early
early: early

Expert Answer


Answer to Part 1 First Step Project Implement C Function Map Getcounts String Filename File Name Tex Q35631367 . . .

OR