Question
I have below program in C++. All input passing by command line argument. In here the key is string as word and Value is an
I have below program in C++. All input passing by command line argument. In here the key is string as word and Value is an int as number of frequency.
1) If the value of map repeated (duplicate), if so then and printout the There is duplicated
Example:
bag 2
bad 2
girl 2
We have to see if the frequnct is repeted. It stored already in the value of map.
2) What is most highest frequency in the map and printout the message.
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main (int argc, char *argv[])
{
......
for (int i = 5; i < argc; i++)
{
ifstream inFile;
inFile.open (argv[i]);
if (!inFile.is_open ()
{
return 0;
}
}
}
for (int i = 5; i < argc; i++){
ifstream file (argv[i]);
string dataIn;
map < string, int > myMap;
// split words from input
while (file >> input)
{
// inc. count
myMap[dataIn]++;
}
map::iterator it;
for (it = myMap.begin(); it != myMap.end(); it++) {
// first is key AND second is value
cout << it->first << " " << it->second << endl;
// More code need to be added...
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started