//This is the IMPLEMENTATION FILE: pfarrayd.cpp. //This is the IMPLEMENTATION of the class PFArrayD. //The interface for the class PFArrayD is in the file pfarrayd.h. #include "pfarrayd.h" #include using std::cout; PFArrayD::PFArrayD(int size) :capacity(size), used(0) { a = new double[capacity]; } PFArrayD::PFArrayD(const PFArrayD& pfaObject) :capacity(pfaObject.getCapacity( )), used(pfaObject.getNumberUsed( )) { a = new double[capacity]; for (int i =0; i < used; i++) a[i] = pfaObject.a[i]; } void PFArrayD::addElement(double element) { /* Modified */ if (used >= capacity) { int newCapacity = capacity * 2; double *temp = new double[newCapacity]; for (int i = 0; i < capacity; i++) temp[i] = a[i]; delete [] a; a = temp; capacity = newCapacity; } a[used] = element; used++; } double& PFArrayD::operator[](int index) { if (index >= used) { cout << "Illegal index in PFArrayD.\n"; exit(0); } return a[index]; } double PFArrayD::operator[](int index) const { if (index >= used) { cout << "Illegal index in PFArrayD.\n"; exit(0); } return a[index]; } PFArrayD& PFArrayD::operator =(const PFArrayD& rightSide) { if (capacity != rightSide.capacity) { delete [] a; a = new double[rightSide.capacity]; } capacity = rightSide.capacity; used = rightSide.used; for (int i = 0; i < used; i++) a[i] = rightSide.a[i]; return *this; } PFArrayD::~PFArrayD( ) { delete [] a; }