Question: Instructions: One of the useful things about dynamic memory is that you can essentially change the size of a dynamically created array (make a bigger

Instructions: One of the useful things about dynamic memory is that you can essentially change the size of a dynamically created array (make a bigger one, copy values, change pointer, etc.)

  • For this lab, you will use the program given to you (lab3.cpp) and finish it by writing the definition of the addSize function called on line 25.
    • Prototype on top, definition on bottom
    • Dont forget about deallocating, if necessary (probably)
  • You will also add code to main that adds values to the new spaces that were added
    • See the comment on line 28
  • You dont have to change anything else in main()
// Complete the program given by writing the definition of the 'addSize' function // (it is being called in line 25) // Also, add code to fill in the extra space created in the array // before it is displayed at the end #include using namespace std; //function prototype goes here int main() { int SIZE = 10, currentSize; int *arrPtr = new int[SIZE]; for (int i = 0; i < SIZE; i++) arrPtr[i] = i; currentSize = SIZE; //why is this here, what is it for?? (might be useful later) //What does the function call in the next line tell you about the function?? arrPtr = addSize(arrPtr, SIZE); //SIZE now has the new size //ADD VALUES TO THE ARRAY TO FILL IN THE EXTRA SPACE CREATED cout << "The new array is: "; // This just displays the array for (int i = 0; i < SIZE; i++) cout << arrPtr[i]<<' '; return 0; } //function definition goes here

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!