Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

Use a map container to store the words, where each word is represented by a pair < string, int >. 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.

In addition to the main ( ) routine, implement the following subroutines in your program:

void get_words ( map < string, int >& ) : It gets a word from the input stream and removes its punctuation marks.

void print_words ( const map < string, int >& ) : 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.

The main ( ) routine calls the subroutine get_words ( ) to get words from the input stream, and to clean an individual word from its punctuation marks, get_words ( ) calls the subroutine clean_entry ( ).

You can check the size of a string by the member function length ( ). For string s, the statement: s.length ( ) returns the total number of characters in s. If the returned length is 0 (i.e., the original word contains nothing but punctuation marks), simply ignore the word and read in the next one.

Use a map container to store the cleaned words (but not the empty words). The statement: m [ s ]++ copies the string s into the map m and updates its frequency. Remember a map keeps only one copy of each individual item (in sorted order) specified in its first argument, key, and stores its frequency in its second argument, value. When key is used as an index to a map, it returns the corresponding value in the map.

Print the number of nonempty words in the input stream and the number of distinct words. You can obtain the number of elements in a map by the member function size ( ). Also print the contents of your map: name of each word and its frequency (NO_ITEMS words per line and the words are left aligned). To allocate certain number of spaces for an output value, use the function setw ( ITEM_W ), and for its left alignment, use left in your cout statement. In your program, use NO_ITEMS = 3, and ITEM_W = 16. For printing, the main ( ) routine calls the subroutine print_words ( )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

Write the difference between sexual and asexual reproduction.

Answered: 1 week ago

Question

What your favourite topic in mathematics?

Answered: 1 week ago

Question

Understand why empowerment is so important in many frontline jobs.

Answered: 1 week ago