Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Using STL Multimap - Help with program I have the following code below using C++ & STL mapcontainers to count the frequency of letters

C++ Using STL Multimap - Help with program

I have the following code below using C++ & STL mapcontainers to count the frequency of letters in a given string(with no spaces). The map data structure stores pairs. In this map,the key is each character, and the value is the frequency.

Need help with: I have the code that retrieves the map valuesand displays to the map, now I need to input the same values into amultimap and output the letters in the order of itsoccurrence(amount of times it is repeated within the string).(arranged from: least # of times --- to greatest # of timesrepeated)

#include #include #include using namespace std;void getFrequency(string strInput,map<char,int> & fMap){    map<char,int>::iterator it; //iterator to find the entries in map    for(int i = 0 ; i < strInput.length() ; i++ )    {        char ch = strInput.at(i);        it = fMap.find(ch); //find the character in the map        if( it == fMap.end() ) //if not present in the map        {            fMap.insert( make_pair(ch,1) );//add an entry        }        else        {            it->second++; //else increment the frequency        }    }}void printFrequency(map<char,int> & fMap){    map<char,int>::iterator it;//iterator to loop through all the chars    for( it = fMap.begin() ; it != fMap.end() ; ++it )    {        cout<<"["<< it->first<<"]"<<"->">strInput;    map<char,int> frequencyMap; //frequency map    getFrequency(strInput, frequencyMap); //get the frequencies    printFrequency(frequencyMap); //print the frequencies}

Step by Step Solution

3.34 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

You can use the STL multimap container to store the same keyvalue pairs from the map but with the ad... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Statistical Investigations

Authors: Beth L.Chance, George W.Cobb, Allan J.Rossman Nathan Tintle, Todd Swanson Soma Roy

1st Edition

1118172140, 978-1118172148

More Books

Students also viewed these Electrical Engineering questions

Question

Were the participants sensitized by taking a posttest?

Answered: 1 week ago