CSE 321 Closed Lab 7 Warm-up Exercise


Counting occurrences of items to determine their frequencies in some input is a very common task in the solution to many problems. For instance, counting the occurrences of letters in text to determine the frequencies of letters in different languages or in texts written by different authors can be useful in cryptoanalysis and to prove or disprove authorship of texts (see Letter frequencies at Wikipedia). Counting the occurrences of words in a given text is another example that has a variety of applications (including the ones above). See here for an original and interesting application of word counting (be patient if it takes some time to load).

For this assignment, you are given a simple program, CountLetters.cpp, that can be used to count the occurrences of letters in a text read from standard input. You should review it carefully to make sure you understand how it achieves its intended behavior.

Your task is to modify this program to count words instead of letters. A word for the purposes of this assignment is simply a string of letters; no other symbols are allowed in words. To get you started, we have provided a skeleton for the new program, CountWords.cpp. Review this file carefully, and write the code needed to complete it. In particular, you need to

For your data structure you can use any of the components from the Resolve Catalog. You will need to include the needed component(s) and provide instantiation(s) for the template(s). You can either write all the code as part of the main procedure or choose to declare new global operations to organize your solution.

Note that a global procedure, Get_Next_Word, has already been provided in the skeleton to facilitate the input of the words from the input stream.

It would be a good idea to use emacs to create a file with all the code you will need. That way you'll be able to save time during closed lab by using copy and paste to get the code into the CountWords.cpp file. Electronic copies of this file will be provided in closed lab, and please do not attempt to complete and compile this file before closed lab.