Question

bool process_words(map_type&, string); Takes in an empty map and a string representing a file name. The...

bool process_words(map_type&, string);

Takes in an empty map and a string representing a file name. The function opens the file, reads the file one line at a time, splits the line, cleans each word and then records it in the map where the key of the map is the string and the value of the map is how many times that string occurred. Error: if the file represented by the string cannot be opened, the function returns false and makes no changes to the map. Otherwise the map is updated as indicated and the function returns true.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

bool process_words(map<string,int>& mp,string filename)
{
ifstream in;
in.open(filename.c_str());
if(in.fail())
{
return false;
}
string t;
while (getline(in, t))
{
vector<string> v = split(t);
for(int i=0;i<v.size();i++)
{
string str = clean_word(v[i]);
mp[str]++;
}
}

in.close();
return true;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
bool process_words(map_type&, string); Takes in an empty map and a string representing a file name. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT