Lab 9

For lab this week, we'll practice reading a file into a two dimensional character array.  Specifically, we'll be taking a dictionary of words, one word per line, and storing it into a dictionary that we can use in our code.  Then, given our dictionary, we'll take user input, and determine whether the word is valid by performing a binary search of our dictionary.  Both of these things will be useful for this next project, so if you haven't done them yet, here's your opportunity to get a step up.  If you have, then well done working ahead, your reward is an easier lab.

For the first point: Successfully read from the file "dictionary.txt" in the same directory as the executable.  Store each word in a char** or char[sizeOfDictionary][MaxWordLength].  If only completing the first point, print out every 1000th word in the dictionary after they've all been read in.

For the second point: Form a loop taking user input.  As long as the input is not equal to the word "x", perform a binary search for the word.  Print out the index at which the word occurs if it is in the dictionary, others print that input is not a valid word.  If the user enters just an x, exit the loop and the program.

For extra credit: Support dictionaries of arbitrary size.  This means reading in the dictionary once to determine the number of words in the dictionary, then dynamically allocating the two dimensional array, then proceeding as usual.

Optionally, though for no credit, count the number of comparisons binary search makes as it finds the word, and output that as well.  See if you can find the words which maximize this number.

Examples (user input in bold)

Enter the word to lookup: ersatz

ersatz was found at position 2207

Enter the word to lookup: able

able was found at position 18

Enter the word to lookup: zoo

zoo was found at position 7656

Enter the word to lookup: muffin

muffin was found at position 4336

Enter the word to lookup: corn

corn was found at position 1474

Enter the word to lookup: x

Press any key to continue . . .

Please don't forget your name(s) at the top of your code.  Don't forget to use the resources available to you if you're not familiar with how to accomplish the tasks described.  If you finish early, feel free to ask questions to the TAs.

If you don't finish on time, you can submit by noon tomorrow for a 1 point penalty.

Example code:

http://logos.cs.uic.edu/Examples%20And%20Notes/examples/TheExamples/arraysAndStrings/strings/lookupWord1.cpp

http://logos.cs.uic.edu/Examples%20And%20Notes/examples/TheExamples/arraysAndStrings/mysort.cpp

Dictionary:

https://sites.google.com/site/uiccs141/programs/prog-4-texttwist/dictionary.txt?attredirects=0&d=1