CMPT 120: Assignment 4


This assignment can be done in pairs. You don't have to work with another student. Each pair working together should only submit one file. Include in the file both names/ids so we know who worked on it. If you don't work in a pair, all of your work must be completely your own.

Spell Checker

For the fourth assignment you will write a relatively functional spell checker. It will allow the user to check single words as well as spell check an entire file. It will maintain a user-dictionary that will be separate from the main dictionary. This will be a relatively simple spell checker as it will not suggest correct words when a misspelled word is found.

Unlike the previous assignments you will not be given complete example runs to look through. You will decide what the output of the program will look like and other small details. You are expected to make a program that is easily understandable from the user's point of view. You can just follow the basic look of the earlier assignments or try something new.

Dictionaries

There will be two dictionary files that your program will open every time it starts. The main dictionary file called 'dict.txt', which you can download here. Each line in the file contains one word in all lower case letters. The words are stored in alphabetical order. Load the words of the dictionary into a list for use by your program. This file should never be changed.

The second dictionary will contain only words added by the user. Give it the file name 'userDict.txt'. The program will load the user-dictionary into a separate list from the main dictionary. While the program is running the user will be able to add words to the dictionary. When checking a word the program will check both the main and the user-dictionary. When the program exits, the user-dictionary should be written back to the file with all of its words in alphabetical order.

When searching the dictionaries for a word you should use binary search. You can use/adapt the code given in the study guide or in class for binary search. If you use a linear search, you will lose some points. Remember that to use the binary search you must keep the user-dictionary in sorted order at all times.

Spell Checking a Word

If the user chooses to check a single word, the program will prompt the user to enter the word. It will then check if the word is in either dictionary. If it is in one of the dictionaries, it will say so, specifying which dictionary the word was found in. If the word was not found, the program will ask the user if the word should be added to the user-dictionary.

Spell Checking a File

If the user chooses to spell check a file you first ask the user for the filename. If the file can't be opened, you should display a message and then present the user with the menu again.

Once the file is open the program should check every word in the file. When checking a word you need to convert it into all lower case letters before checking if it is in the dicitonaries. If a word is not in the dictionaries you will display the entire line that the word is on and identify what word was not found. For example, the output could look like this.
The word "th" from the following line is not in either dictionary.
"There was a dog sleeping on th lawn."
After displaying this, the program will give the user the option to enter a word that will replace the incorrect one, add the word to the user-dictionary, or do nothing. The changes the user made to the file will be saved to the same file when the program finishes spell checking that file.

To simplify things, you can make some assumptions about the file. There will be a single space between every word and after each sentence. The only punctuation in the file will be a period at the end of each sentence. You don't have to worry about handling any other punctuation such as commas, question marks, and so forth.

Functions

There are no assigned functions to write, but you should break up the logic of your program into sensible functions.