#include #include #include #include "WordT.h" #include "WordListT.h" using namespace std; void PrintWords(WordListT & words); WordListT ReadFile(string fileName); string CleanWord(string word); int main() { WordListT words; words = ReadFile("ocap.txt"); PrintWords(words); return 0; } string CleanWord(string word){ string newWord; size_t i; for(i =0; i < word.size(); ++i) { if (isalpha(word[i])) { newWord += static_cast(tolower(word[i])); } } return newWord; } WordListT ReadFile(string fileName){ ifstream inFile(fileName); string word; WordListT dictionary; WordT entry; inFile >> word; while (inFile) { word = CleanWord(word); if (word != "") { dictionary.FindWord(word); if (dictionary.PastLastWord()) { cout << "Adding " << word << endl; dictionary.AddWord(word); } else { cout << "Incrementing " << word << endl; entry = dictionary.GetWord(); entry.Increment(); dictionary.SetWord(entry); } } inFile >> word; } return dictionary; } void PrintWords(WordListT & words){ WordT word; words.FirstWord(); while (not words.PastLastWord()) { word = words.GetWord(); cout << setw(20) << word.Word() << setw(10) << word.Count() << endl; words.NextWord(); } return; }