Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions