Question: Modify the header file and the source file given below so that they now work as template class (the array elements in the dynamically allocated

Modify the header file and the source file given below so that they now work as template class (the array elements in the dynamically allocated memory can be any type as the user defines).

dynarr.h #ifndef DYNARR H INCLUDED #define DYNARR_H_INCLUDED class dynArr private: int *data;

dynarr.h #ifndef DYNARR H INCLUDED #define DYNARR_H_INCLUDED class dynArr private: int *data; int size; public: dynArr(); dynArr (int); ~dynArr(); void setValue (int, int); int getValue (int); }; #endif // DYNARR H INCLUDED dynarr.cpp #include "dynarr.h" #include using namespace std; dynArr::dynArr () data = NULL; size = 0; { } dynArr::dynArr(int s) data= new int [s]; size = s; { } dynArr::~dynArr() { delete [] data; } int dynArr::getValue (int index) { //write the code void dynArr::setValue(int index, int value) { } //write the code

Step by Step Solution

3.54 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

dynArrh ifndef DYNARRHINCLUDED define DYNARRHINCLUDED template cl... View full answer

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 Programming Questions!