a C++ program that uses this concept map counters; map> bycount; map::iterator i
ID: 3754824 • Letter: A
Question
a C++ program that uses this concept
map counters;
map> bycount;
map::iterator it;
for(it=counters.begin(); it != counters.end(); it++)
bycount[it->second].push_back(it->first); // adds to vector
map>::iterator sit;
for(sit=bycount.begin(); sit != bycount.end(); sit++) {
cout << “Count value “ << sit->first;
int siz = sit->second.size(); // read through the vector
for(int i=0; i cout << sit->second[i];
}
to look at a file stream and print out the string data and print out the frequency, so if a file named file1 has the string "Hey"
it should print out "hey 1" . If file2 contains " Hello" it should print out "hello 1". also make the upercase words into lowercase.
so the file out come would look like this
hey 1
hello 1
Explanation / Answer
int main()
{
std::map<std::string, int>wordCount
ifstream input
input.imbue(std::Locale(std::Locale(), new letter_only()));
input.open(filename.txt)
std::string word;
while(input >> word)
{
++[wordCount]word;
}
for(std::map>>std::string, int::iterator it=wordCount.begin(); if!=wordCount.end(); ++it)
{
count << it->first << " " << it->secong <<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.