Assignment 1 - A Spell Checker

due Tuesday, 1/15   9:30 am

Follow these instructions for Programming Assignments:

Programming Assignments

This assignment is meant to be a review of some of the introductory concepts covered in CIS22B. It involves writing some classes, contructors, destructors, memory allocation, file I/O, and program planning. You are to use the two classes, Word and Dictionary, the suggested main() (or a main() that is very similar), the dictionary "word" file, and the input file, "gettysburg.txt".

Your program should adhere to the following specifications:

  1. You are to use the Word and Dictionary classes defined below and write all member functions and any necessary supporting functions to achieve the specified result.
  2. The Word class should dynamically allocate memory for each word to be stored in the dictionary.
  3. The Dictionary class should contain an array of pointers to Word. Memory for this array must be dynamically allocated. You will have to read the words in from the file. Since you do not know the "word" file size, you do not know how large to allocate the array of pointers. You are to let this grow dynamically as you read the file in. Start with an array size of 8, When that array is filled, double the array size, copy the original 8 words to the new array and continue. You can see the expected behavior in the sample program output listed below.
  4. You can assume the "word" file is sorted, so your Dictionary::find() function must contain a binary search algorithm. You might want to save this requirement for later - until you get the rest of your program running.
  5. Make sure you store words in the dictionary as lower case and that you convert the input text to the same case - that way your Dictionary::find() function will successfully find "Four" even though it is stored as "four" in your Dictionary.
  6. Make sure you remove leading or trailing punctuation from a word, such as "nation,".
  7. Do not use the string class for this assignment.  All text data should be stored and managed as C-strings.
Warning: If you are using a Mac or Linux compiler, you may want to remove the \r at the end of each line in both input files.  You can do that like this:

Word class
class Word 
   char* word_; 
   Word(const char* text = 0); 
   const char* word() const; 

Dictionary class
class Dictionary 
   Word** words_; 
   unsigned int capacity_;   // max number of words Dictionary can hold 
   unsigned int numberOfWordsInDictionary_; 
   void resize(); 
   void addWordToDictionary(char* word); 
   Dictionary(const char* filename); 
   bool find(const char* word);


int main()
   char buffer[MaxWordSize];
   Dictionary Websters(wordfile);
   ifstream fin(document);
   cout << "\nSpell checking " << document << "\n\n";
   while (fin >> buffer) {
      // remove leading/trailing punctuation, change to lowercase
      if (cleanupWord(buffer)) {      
         if (!Websters.find(buffer)) {
            cout << buffer << " not found in the Dictionary\n";

Program output

Dictionary resized to capacity: 16            <--- This illustrates Dictionary resizing
Dictionary resized to capacity: 32
Dictionary resized to capacity: 64
Dictionary resized to capacity: 128
Dictionary resized to capacity: 256
Dictionary resized to capacity: 512
Dictionary resized to capacity: 1024
Dictionary resized to capacity: 2048
Dictionary resized to capacity: 4096
Dictionary resized to capacity: 8192
Dictionary resized to capacity: 16384
Dictionary resized to capacity: 32768

Spell checking /deanza/data/gettysburg.txt       <--- spell checking begins

created not found in the Dictionary	    <--- words not found in the Dictionary
struggled not found in the Dictionary
consecrated not found in the Dictionary
por not found in the Dictionary
remember not found in the Dictionary
unfinished not found in the Dictionary
nobly not found in the Dictionary
advanced not found in the Dictionary

Hint: there are between 10 and 20 misspelled words 

"word" file and "gettysburg.txt" (this is a zip file)