Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How is the following done ? implement the public member function void resize(int newsize) that will resize the *elements arrray., steps to be taken are

How is the following done ?

implement the public member function void resize(int newsize) that will resize the *elements arrray., steps to be taken are follwoing :

Allocate memory of the new array of size newsize, Copy elements from old *elements array, f the size of the new array is bigger than the current

*elements array, then fill the additional elements with 0 value, f the size of the new array is smaller than the current *elements array, then copy only newsize

elements from the current *elements array, Delete the memory currently assigned to *elements, and Remap *elements pointer to the new array

Below is my code so far, we have class smartarray wiht public member dynamic array int *elements and private int size;. my code doesnt ouput new size

void smartArray:: resize(int newsize){ int *newarray = new int [newsize]; if (newsize >= size){ for (int i =0 ; i< size;i++) { newarray[i] = elements[i];} for (int i=size;i < newsize;i++) newarray[i-size]= 0; } else { for (int i =0 ; i< size ;i++) newarray[i] = elements[i]; } delete [] elements; * elements =* newarray; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions