Question: 1. Write a C++ program freq.cc which reads in a list of words and produce two lists of output. You may assume that the words

1. Write a C++ program freq.cc which reads in a list of words and produce two lists of output. You may assume that the words are separated by white space. The list is terminated by end-of-file.

  • The first list (use map) is the list of distinct words in the file as well as the number of times each word occurs in the input. The words should first be converted to lower case (write a helper function to convert a character to its lower case equivalent and use transform in STL). This list should be sorted in dictionary order based on the words. If the list of words is:

     abcd Computer science computer games 

    The output should look like (the exact format is up to you):

     Word Frequency --------------------- --------- abcd 1 computer 2 games 1 science 1 
  • The second list (use vector pairs) is the list of distinct words sorted in decreasing frequency. Words with the same frequency should be listed in dictionary order. For the list above, the output should look like:

     Frequency Word --------- --------------------- 
     2 computer 1 abcd 1 games 1 science 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!