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

Using the C++ code below, Create a function/method that will increase the size o

ID: 3743643 • Letter: U

Question

Using the C++ code below, Create a function/method that will increase the size of an array by 2 (double the size). The function/method must return a pointer to the new array. Main will create the initial array and pass it to the function/method. The pointer in main will point to the array with the new size. No data should be lost from the array passed in and all the new locations should be set to zero.

Instructions

Using the C++ code below, Create a function/method that will increase the size of an array by 2 (double the size). The function/method must return a pointer to the new array. Main will create the initial array and pass it to the function/method. The pointer in main will point to the array with the new size. No data should be lost from the array passed in and all the new locations should be set to zero.

  #include <iostream>  using namespace std;    int* ExpandArray(int data[], int size)  {    }    int main()  {          int size = 2;          int* values = new int[size];          values[0] = 55;          values[1] = 77;            for (int index = 0; index < size; index++)          {                  cout << values[index] << endl;          }            values = ExpandArray(values, size);            for (int index = 0; index < size * 2; index++)          {                  cout << values[index] << endl;          }            delete[] values;            return 0;  }

Explanation / Answer

#include using namespace std; int* ExpandArray(int data[], int size) { int *arr = new int[2*size]; for(int i = 0; i < 2*size; ++i) { if(i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote