CS 19 Fall 2014
Assignment 2 (Letter Pair Frequency)
In this assignment, you will read multiple lines of text from STDIN. The number of lines to be input is not specified. Read all input until EOF (ctrl-d for keyboard input.) After you have completed reading all of the input, you will output a table with 26 rows and 26 columns showing the number of occurences for each ordered pair of letters (either upper or lower case) in the input ("AA", "AB", "AC" ... "AY", "AZ", "BA", "BB", "BC", ... "ZY", "ZZ") The first letter will determine which row your entry will be printed in, and the second letter will determine the column. Spaces, punctuation, or any other non-letter characters (including newlines) are to be ignored for purposes of finding the sequential letter pairs. (Letters on either side of a space or the last letter on one line and the first letter on the next line are a pair, for example.) You may assume that each line will have fewer than 255 characters. You may use either C style strings (character arrays) or C++ style strings (string class) for this assignment—both are described in chapter 9 of our text. Please use whichever you are more familiar with. In this project you are required to have at least one function in addition to main. That function must be passed a line of text to be scanned/processed to find the letter pairs, plus any other parameters that you deem necessary. You may have more than two functions if you wish.
Your output should consist of 26 rows of 26 integer values, with a single space after each integer. The first row output will be a count of the pairs AA, AB, AC, AD ... AZ. The second row will be a count of the pairs BA, BB, BC, BD ... BZ. Each row to follow will start with the next letter in the alphabet. The last row will represent the pairs ZA, ZB, ZC, ZD ... ZZ. Remember that the pair AA means that you saw the letter 'a' or 'A' followed by the letter 'a' or 'A'. AB means that you saw the letter 'a' or 'A' followed by the letter 'b' or 'B'. You program will have no output other than the table (result.)
The input text "This is a test." has the following ten letter pairs: TH, HI, IS, SI, IS, SA, AT, TE, ES, ST.
What to turn in
As usual, leave your .cpp file for this program ("freq.cpp") in your home directory on pengo.
You may find it easiest to complete this program in stages. Begin by writing a program that echos input lines of text to output until no more input remains. Then add the ability to pass a line of text to a second function to be processed for letter pairs.