due October 1
This assignment is meant to be a review of some of the introductory concepts covered in CIS27. 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:
Word class
class Word
{
char* word_;
public:
Word(const char* text = 0);
~Word();
const char* const 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);
public:
Dictionary(const char* filename);
~Dictionary();
bool find(const char* word);
};
main()
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";
}
}
}
return 0;
}
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
...
"word" file and "gettysburg.txt" (this is a zip file)