Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the attached file, complete the shift, expandArray, and showArray functions. The attached file has a completed main. Do not change the prototypes or the

Using the attached file, complete the shift, expandArray, and showArray functions. The attached file has a completed main. Do not change the prototypes or the main function. Do not add functions.

Your program output should look something the attached screenshot.

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.

The expandArray function accepts an int/ array and an int indicating the array's size. The function returns a pointer to an array that is twice the size of the array that was passed as an argument. The elements of the argument array

are copied to the new array, and the remaining elements are set to 0.

The showArray function displays the contents of an int array.

#include  using namespace std; // Prototypes // DO NOT CHANGE int *shift(int[], int); int *expandArray(int[], int); void showArray(int[], int); int main() //DO NOT CHANGE 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); // Display the contents of the array. cout << "The contents of the original array are: "; showArray(values, SIZE); // Make an expanded copy of the array. int *arrCopy2 = expandArray(values, SIZE); // Display the contents of the new array. cout << "The contents of the expanded array are: "; showArray(arrCopy2, SIZE*2); 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. //YOUR CODE NEEDED BELOW int *shift(int arr[], int size) { // Make sure the size is positive and // non-zero. // Allocate an array one element larger // than the array that was passed as // an argument. // Set the first element of the new // array to 0. // Copy arr's elements to the new array, // shifted one position toward the end // of the array. // Return a pointer to the new array. return copy; } int *expandArray(int arr[], int size) { // Make sure the size is positive and // non-zero. // Allocate an array twice the size // of the array that was passed as // an argument. // Copy arr's elements to the new array. // Set the remaining elements to 0. // Return a pointer to the new array. return copy; } // The showArray function displays the contents // of an int array. void showArray(int arr[], int size) { for (int index = 0; index < size; index++) cout << WHAT? << " "; cout << endl; }

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

Students also viewed these Databases questions

Question

Understand the nature of prepaid expenses. E-967

Answered: 1 week ago

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago

Question

Describe how language reflects, builds on, and determines context?

Answered: 1 week ago