#include #include #include // this is the original code. // using namespace std; const size_t MAX_WORDS{100}; string StripWord(string word); void InsertWord(string word, string words[], size_t & size); void PrintArray(const string words[], size_t size); void ReadArray(string words[], size_t & size); size_t FindWord(string word, const string words[], size_t size); int main() { string words[MAX_WORDS]; size_t wordCount{0}; ReadArray(words, wordCount); return 0; } void ReadArray(string words[], size_t & size) { ifstream inFile("ocap.txt"); string word; inFile >> word; while(inFile) { word = StripWord(word); if (word!= "") { InsertWord(word, words, size); } inFile >> word; } inFile.close(); } void PrintArray(const string words[], size_t size){ for(size_t i = 0; i < size; ++i) { cout << words[i] << endl; } } string StripWord(string word){ string newWord; for(size_t i = 0; i < word.size(); ++i) { if (isalpha(word[i])) { newWord += static_cast(tolower(word[i])); } } return newWord; } size_t FindWord(string word, const string words[], size_t size) { size_t i = 0; while (i < size and words[i] != word) { ++i; } return i; } void InsertWord(string word, string words[], size_t & size){ size_t pos; pos = FindWord(word, words, size); if (pos >= size) { if (size < MAX_WORDS) { words[size] = word; ++size; } else { cout << "The array is too small, can not add " << word << endl; } } }