Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this computer assignment, you are to write and implement an interactive C++

ID: 3755493 • Letter: F

Question

For this computer assignment, you are to write and implement an interactive C++ program to scan and process a stream of words of a plain text Your program should start with an empty list of words. (Combinations of blanks, tabs, and newline characters to separate words.) After reading each word from the input stream, do the followings Check the word for punctuation marks. If the first letter of the word is preceded or its last letter is followed by punctuation marks, delete them from the word; however, if a word contains punctuation marks in the middle, ignore the letters beyond these punctuation marks. For example, if the word is fish, then the resulting word should be fish; however, if the word is fish net then the resulting word should still be fish. in 1. Use a map container to store the words, where each word is represented by a pair . The first element of the pair, named first, contains the name of the input word, and the second element of the pair, named second, contains its frequency in the input stream. To use a map container in your program, you need to insert the statement: #include in your header file, and to use the functions in the STL, you also need to insert the statement: #include in your header file. 2. In addition to the main () routine, implement the following subroutines in your program . void get words map & ): It gets a word from the input stream and removes its punctuation marks . void print words ( const map&): It prints the final list of words and their frequencies. It also prints the number of nonempty words and the number of distinct words in the input stream . void clean entry (const string&, string&): It cleans a word from its punctuation marks. The first argument is the original word in the input stream and the second argument contains the same word after cleaning

Explanation / Answer

Ans to Question Number 1.

#include <iostream>
#include <string.h>
#include <map>
#include <utility>


using namespace std;


int main()
{
map<string, int> func;
cout<<"Number of words you have in your stream"<< endl;
int n;
cin>>n;// number of words in stream
  
string coi[n];
  
for(int i=0;i<n;i++)
{ string name;
cout<<"Enter the word the strem"<< endl;
cin>>name;
coi[i]=name; // storing each word in the stream in coi array


  
}
  
for(int i=0;i<n;i++){
int count=0;
for(int j=0;j<n;j++){
if(coi[i].compare(coi[j])==0)
count++;}//counting number of occurence of a word in stream
  
if(func.find(coi[i])== func.end())
func.insert(pair <string, int> (coi[i], count));// inserting in map fun
}

map <string, int> :: iterator itr;

for (itr = func.begin(); itr != func.end(); ++itr) // iterating through map and printing word and its frequency
{
cout << ' ' << itr->first  
<< ' ' << itr->second << ' ';
}
cout << endl;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote