Question: Use project9B Write a function that accepts an int array and the arrays size as an arguments. The function should create a new array that

Use project9B Write a function that accepts an int array and the arrays size as an arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 should be copied to element 1, the element 1 should be copied to element 2, and so forth. The function should return a pointer to the new array.

Project9B

#include using namespace std;

// Prototype int *shift(int[], int); void showArray(int[], int);

int main() { const int SIZE = 5; int values[SIZE] = { 1, 2, 3, 4, 5 };

// Display the contents of the array. cout << "The contents of the original array are: "; showArray(values, SIZE);

// Call the shift function to make a copy of // the array, with the elements shifted one // position toward the end if the array. int *arrCopy = shift(values, SIZE);

// Display the contents of the new array. cout << "The contents of the new array are: "; showArray(arrCopy, SIZE + 1); system("PAUSE"); return 0; }

// ******************************************************** // The shift function accepts an int array and an int * // indicating the array's size. The function returns a * // pointer to an array that is one element larger than * // the array that was passed as an argument. The elements * // of the argument array are copied to the new array, * // shifted one position toward the end of the array. * // ******************************************************** int *shift(int arr[], int size) { // your code here }

// ******************************************************** // The showArray function displays the contents of an int * // array. * // ******************************************************** void showArray(int arr[], int size) { for (int index = 0; index < size; index++) { cout << arr[index] << " "; }

cout << endl << endl; }

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!