


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



The CEO of the Computer Sciences Corporation, Dr. Link Queue has decided that the second product in the company’s arsenal of applications will be a tool that determines what words (i.e., combinations of letters) can replace a seven digit telephone number. For example, the number 866-2665 could be represented as “TOOCOOL”. In this assignment, you will develop a program that takes in a seven digit phone number and outputs all possible word combinations for that number. In addition, the program will analyze these combinations to find words that have correct spelling (this will help to prune out the gibberish). Your program will utilize recursion and trees.
There are two parts to this assignment.
Part I: Telephone Words
In the first part, you will use the keypad shown in the figure for the mappings between letters and numbers. Your program should take as input a seven digit number (a string in this case) and output a list of all possible “words” that can represent the given number. Note that since 0 and 1 do not have letters they do not need to be changed. However, any phone number you give your program should be able to deal with 0’s and 1’s. Use the following function prototype
void DoPrintTelephoneWords(int phoneNumber [], int curDigit, char result[]);
where phoneNumber is an array of seven integers with each digit being one digit in the number, curDigit is an index to the current digit, and result stores the result. Assume that only valid phone numbers will be passed to your function. Also use
char GetCharKey(int telephoneKey, int place);
which takes a telephone key (0-9) and a place of either 1,2,3,4 and returns the character corresponding to the letter in the key. Note for this part of the assignment you MUST use recursion.
Part II: Spell Checking with a Trie
For the second part of the assignment, you are to implement a special form of tree called a “trie” (properly pronounced “tree,” although some pronounce it “try” to avoid confusing it with the more traditional “tree” data structure), which can be used to efficiently spell check the strings produced in the first part of the assignment.
Like any tree, your trie will have a root node. Furthermore, every node in the tree has 26 children nodes – one for each letter of the alphabet. The node structure will be:
struct trieNode { int wordFlag; struct trieNode *children[26]; };
If the path taken from the root node to the current node forms a correctly spelled word, the wordFlag is set to 1. Otherwise, it is set to 0.
For example, since “spelled” is an English word, root->children[18]->children[15]-
children[4]->children[11]->children[11]->children[4]->children[3]->wordFlag should be set to 1 (because the letters s-p-e-l-l-e-d correspond with the integers 18-15-4-11-11-4- 3 when the letters of the alphabet are scaled to the integers 0 through 25).
Notice that since “spell” is also a word, root->children[18]->children[15]->children[4]-
children[11]->children[11]->wordFlag should also be set to 1. However, “spelle” is not a word, so root->children[18]->children[15]->children[4]->children[11]->children[11]- children[4]->wordFlag should still be 0.
We will deal only with words that have 7 characters or less. Therefore, we may be tempted to allocate a trie with 7 levels in addition to the root node at the beginning of our program. However, that would result in a trie of (1 + 26 + 26^2 + … + 26^7 ) nodes – a task that your system’s memory is not likely to be capable of handling!
Instead of allocating a fully fleshed-out trie, we will allocate only the branches we need.
To begin, prompt the user for a filename. The file given will contain a list of correctly spelled English words, one per line, with a guarantee that none of them will be over 7 characters in length. Your program should read each line, and terminate when it reaches the end of the input file.
Each time you read a line, you should traverse the trie and perform two tasks:
For testing purposes, you should create your own (small) sample lexicon file by hand.
Find a recurrence relation for PrintTelephoneWords and find its running time.
You must document your routines. Each function should be commented with what the function does, its input parameters, and what it returns. Comments are very important and will account for 20% of your grade.
You must test your program and ensure that it works. You should provide output files that show what phone numbers you have tried, what the different words were, and subset of these words you found with the pruning step.
You must submit all source files in addition to your test files to WebCT by the due date. Also, include a README file explaining how you tested your code and what problems you encountered. Note the code must be able to be compiled and executed on the Olympus unix system.
Grading will be based on the following:
70% correct functionality 20% documentation 10% testing