//This is the implementation file: pfarray.cpp. //This is the implementation of the template class PFArray. //The interface for the template class PFArray is in the file pfarray.h. #include "pfarray.h" #include using std::cout; namespace PFArraySavitch { template PFArray::PFArray( ) :capacity(50), used(0) { a = new T[capacity]; } template PFArray::PFArray(int size) :capacity(size), used(0) { a = new T[capacity]; } template PFArray::PFArray(const PFArray& pfaObject) :capacity(pfaObject.getCapacity( )), used(pfaObject.getNumberUsed( )) { a = new T[capacity]; for (int i =0; i < used; i++) a[i] = pfaObject.a[i]; } template void PFArray::addElement(T element) { if (used >= capacity) { cout << "Attempt to exceed capacity in PFArray.\n"; exit(0); } a[used] = element; used++; } template bool PFArray::full( ) const { return (capacity == used); } template int PFArray::getCapacity( ) const { return capacity; } template int PFArray::getNumberUsed( ) const { return used; } template void PFArray::emptyArray( ) { used = 0; } template T& PFArray::operator[](int index) { if (index >= used) { cout << "Illegal index in PFArray.\n"; exit(0); } return a[index]; } template PFArray& PFArray::operator =(const PFArray& rightSide) { if (capacity != rightSide.capacity) { delete [] a; a = new T[rightSide.capacity]; } capacity = rightSide.capacity; used = rightSide.used; for (int i = 0; i < used; i++) a[i] = rightSide.a[i]; return *this; } template PFArray::~PFArray( ) { delete [] a; } }// PFArraySavitch