Question: (c++) Using the pseudo code listed below, extend it to include: * Reading data strings from a file * Convert from int based container to

(c++) Using the pseudo code listed below, extend it to include:

* Reading data strings from a file * Convert from int based container to templates or generics based * Accommodate 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 2. Repeat from step 1a. as necessary 3. Note the data file is called "words.txt" (explained below)

---none of the previous answers to this question are correct on this site, so please don't copy/paste---

Resize C++

Data* ptemp = new Data[ size*2 ];

for (int i=0; i

ptemp[i] = _mdata[i];

delete [] _mdata;

_mdata = ptemp;

capacity *= 2;

<<<< DynamicArray Pseudo-code >>>>

DynamicArray Class

int* base // c++

int used = 0

int size = 0

DynamicArray(c) // constructor

size(c)

allocate(size)

void allocate(c)

size = c

base = new T[size]

for (i = 0 to size)

base[i] = 0

void pop()

for (i = 1 to used)

base[i - 1] = base[i]

void push(t)

set(t)

void set(v)

base[used] = v

used++

int get(offset)

return base[used]

int begin()

return base[0]

int end()

return base[used - 1]

int length()

return used

int capacity()

return size

words.txt is as follows. this code should work even if words.txt is changed to more words:

when

what

there

been

one

could

very

an

who

them

Mr

we

now

more

out

do

are

up

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!