#pragma once template class ArrayT { public: ArrayT() = default; ArrayT( const ArrayT & other); ~ArrayT(); ArrayT & operator =(const ArrayT & other); bool PushBack(DataT newWord); DataT & operator[](size_t index); const DataT & operator[](size_t index) const; DataT & at(size_t index); const DataT & at(size_t index) const; size_t Capacity() const; size_t Size() const; private: DataT * data{nullptr}; size_t capacity{0}; size_t size{0}; }; template ArrayT::ArrayT(const ArrayT & other) { if (other.data != nullptr) { capacity = other.capacity; size = other.size; data = new DataT[capacity]; for(size_t i = 0; i < size; ++i) { data[i] = other.data[i]; } } } template ArrayT::~ArrayT() { if (data != nullptr) { delete [] data; } } template ArrayT & ArrayT::operator =(const ArrayT & other){ // do a deep copy if (this != &other) { capacity = other.capacity; size = other.size; if (other.data == nullptr) { data = nullptr; } else { if (data != nullptr) { delete [] data; } data = new DataT [capacity]; for(size_t i = 0; i < size; ++i) { data[i] = other.data[i]; } } } return *this; } template bool ArrayT::PushBack(DataT newWord){ bool good { true}; if (data == nullptr) { data = new DataT[3]; capacity = 3; } else if (size >= capacity) { capacity *= 2; DataT * tmp {new DataT[capacity]}; for(size_t i =0; i < size; ++i) { tmp[i] = data[i]; } delete [] data; data = tmp; } data[size] = newWord; ++size; return good; } template DataT & ArrayT::operator[](size_t index){ return data[index]; } template const DataT & ArrayT::operator[](size_t index) const{ return data[index]; } template DataT & ArrayT::at(size_t index){ if (data != nullptr and index < size) { return data[index]; } cerr << "Error: Out of bounds index " << index << endl; return data[0]; } template const DataT & ArrayT::at(size_t index) const{ if (data != nullptr and index < size) { return data[index]; } cerr << "Error: Out of bounds index " << index << endl; return data[0]; } template size_t ArrayT::Capacity() const{ return capacity; } template size_t ArrayT::Size() const{ return size; }