Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following question is for C++ Create a \"Dynamic Array\" container with this

ID: 3781498 • Letter: T

Question

The following question is for C++

Create a "Dynamic Array" container with this user interface:

int getCurrentSize()   // Gets the current number of entries in container

int capacity()   // Returns the current capacity of the container

boolean isEmpty() // Checks whether the container is empty.

boolean insert(newEntry) // Adds a new entry to the container

boolean remove(anEntry) // Removes an entry from the container and moves all entries above anEntry down one

int getValue(index) // Get index value

void clear()   // Removes all entries from the container

int resize()   // Resize a container by doubling current capacity

*   Implement dynamic resizing using this algorithm:

1. Starting with a dynamic size of 10, if the number of elements exceed this number:

    a. Reallocate the container size to double the current size

    b. Move the contents of the current container to the newly sized container

    c. Delete the previously sized container.

  Resize C++
        Data* ptemp = new Data[capacity*2 ];
        for (int i=0; i<size; i++)
              ptemp[i] = _mdata[i];
        delete [] _mdata;
       _mdata = ptemp;
        capacity *= 2;

2. Repeat from step 1a. as necessary.

3. Note the data file called "Words.CSV" can be downloaded from https://www.dropbox.com/s/jwi5x6zc4f18o6e/Words.csv?dl=0 ... (downoad this data file such that the code written for Words.CSV is read from the computer desktop/project file)

4. Read the data file and store the words in the dynamic array.

Explanation / Answer

int getCurrentSize(){

return arr.size();

}

int getValue(index) {

val=arr[index];

return 0;

}

int main()

{

ifstream readFile("sales.txt");
copy(istream_iterator<string>(readFile), {}, back_inserter(input));// input vectors contains the words of the file.

// read this vector and copy elements in array

// opreations

int size1=getsize();

if(size1<input.size())

{

resize();

}

else

{

}

return 0;

}

// other modules are simple and can be coded.