#ifndef SEARCHABLEVECTOR_H #define SEARCHABLEVECTOR_H #include "SimpleVector.h" template class SearchableVector : public SimpleVector { public: // Default constructor SearchableVector() : SimpleVector() {} // Constructor SearchableVector(int size) : SimpleVector(size) { } // Copy constructor SearchableVector(const SearchableVector &); // Accessor to find an item int findItem(const T); }; //******************************************************* // Copy constructor * //******************************************************* template SearchableVector::SearchableVector(const SearchableVector &obj) : SimpleVector(obj.size()) { for(int count = 0; count < this->size(); count++) this->operator[](count) = obj[count]; } //******************************************************* // findItem function * // This function searches for item. If item is found * // the subscript is returned. Otherwise -1 is returned. * //******************************************************* template int SearchableVector::findItem(const T item) { for (int count = 0; count <= this->size(); count++) { if (getElementAt(count) == item) return count; } return -1; } #endif