#include #include "WordListT.h" #include "WordT.h" using namespace std; WordListT::WordListT(){ capacity = 10; words = new WordT[capacity]; size = 0; current = 0; } WordListT::~WordListT(){ delete [] words; words = nullptr; } WordListT::WordListT(const WordListT & other ){ int i; words = new WordT[other.capacity]; for(i =0; i < other.size; ++i) { words[i] = other.words[i]; } size = other.size; current = other.current; capacity = other.capacity; } WordListT & WordListT::operator =(const WordListT & other){ int i; if (this != &other) { delete[] words; words = new WordT[other.capacity]; for(i =0; i < other.size; ++i) { words[i] = other.words[i]; } size = other.size; current = other.current; capacity = other.capacity; } return *this; } void WordListT::AddWord(string word){ WordT * tmp{nullptr}; int i; if (size == capacity) { capacity *= 2; tmp = new WordT[capacity]; for (i = 0; i < size; ++i) { tmp[i] = words[i]; } delete [] words; words = tmp; tmp = nullptr; } words[size].Word(word); size++; } int WordListT::WordCount(void) const{ return size; } void WordListT::FirstWord(){ current = 0; } void WordListT::NextWord(){ if (current < size) { current ++; } } bool WordListT::PastLastWord(){ return current >= size; } void WordListT::FindWord(string word) { current = 0; while (current < size and words[current].Word() != word) { current ++; } } void WordListT::SetWord(WordT word) { if (current < size) { words[current] = word; } else { cout << "Current is invalid, not setting word" << endl; } } WordT WordListT::GetWord(){ WordT word; if (current < size) { word = words[current]; } else { cout << "Current is invalid, returning blank word" << endl; } return word; }