Question: C++14 Dynamic Array Program For this project you are to implement a generic dynamic array class. It will be a templated class that provides the

C++14 Dynamic Array Program

For this project you are to implement a generic dynamic array class. It will be a templated class that provides the basic features of an array. You will be given an incomplete file dynarr.h whose contents are shown above. You are to complete the code in that file and submit it. It is the only file you are to submit. Also, you should create a program to test your implementation. Make sure your test file exercises all the methods of the dynarray class.

C++14 Dynamic Array Program For this project you are to implement a

#include

#include

#include

class RuntimeException{ // generic run-time exception

protected:

std::string errorMsg;

public:

RuntimeException(const std::string& err) { errorMsg = err; }

std::string getMessage() const { return errorMsg; }

};

class InvalidIndex : public RuntimeException{

public:

InvalidIndex(const std::string& err): RuntimeException(err) {};

};

template

class dynarr{

private:

int capacity;

dynElem *A;

public:

dynarr() : capacity(0), A(NULL) {};

dynarr(int N): capacity(N), A(new dynElem[N]){}

dynarr(const dynarr &other);

~dynarr();

dynarr & operator=( const dynarr &other);

dynElem & operator[](int ndx);

int getCapacity();

void reserve(int newcap);

// if newcap

// if capacity is 0, allocates a dynamic array of

// capacity newcap and makes A point to that array;

// otherwise allocates a new dynamic array newA of capacity

// newcap, copies values in A to newA, deletes A and sets

// A equal to newA

};

template

dynarr::dynarr(const dynarr &other){

// code goes here

}

template

dynarr::~dynarr(){

// code goes here

}

template

dynarr & dynarr::operator=( const dynarr &other){

// code goes here

}

template

dynElem & dynarr::operator[](int ndx) throw(InvalidIndex){

// code goes here

}

template

int dynarr::getCapacity(){

// code goes here

}

template

void dynarr::reserve(int newcap){

// code goes here

}

Thanks in advance. Will rate.

#include #include #include assert 4 5 class RuntimeException generic run-time exception rotected std::string errorMsg; ublic: RuntimeException (const std: :string& err) { errorMsg = err; } std::string getMessage() const return errorMsg; 12 13 class InvalidIndex : public RuntimeException{ ublic: InvalidIndex(const std::string& err): RuntimeException (err) 15 16 template &other); dynarr); dynarrdynElem & operator=( const dynarrdynElem> &other); dynElem &operator[1 (int ndx); int getCapacity(); void reserve(int newcap); // if newc ap capacity, does nothing; // if capacity is 0, allocates a dynamic array of // capacity newcap and makes A point to that array; // otherwise allocates a new dynamic array newA of capacity // newcap, copies values in A to newA, deletes A and sets // A equal to newA 25 26 27 29 30 32 34 35 36 38 39 40 41 dynarr: :dynarr (const dynarrsdynElem> &other)[ 42 template : :operator-( const dynarr &other)\ 52 53 54 template ::operator [1 (int ndx) throw(InvalidIndex) 57 58 59 60 61 int dynarr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!