Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve in C++, please; Complete the reverseArray function which takes in a dynamically allocated array of integers and its size as arguments, and returns a

Solve in C++, please;

Complete the reverseArray function which takes in a dynamically allocated array of integers and its size as arguments, and returns a new dynamically allocated array that contains the elements of the input array in reverse order.

Note: The function should not modify the original array.

Example

Here is the function signature:

int* reverseArray(int* arr, int size); 

Here is an example of how the function should behave:

int* arr = new int[5]{1, 2, 3, 4, 5}; int* reversed = reverseArray(arr, 5); // reversed should contain {5, 4, 3, 2, 1}

This is the starter code:

#include

#include

using namespace std;

int* reverseArray(int* arr, int size) {

//add code below this line

//add code above this line

}

void printArray(int* arr, int size) {

for (int i = 0; i < size; i++) {

cout<

}

}

int main(int argc, char* argv[]) {

int size = stoi(argv[1]);

int* arr = new int[size];

for(int i=0; i

int num = stoi(argv[i + 2]);

arr[i] = num;

}

int *reverse = reverseArray(arr, size);

printArray(reverse, size);

return 0;

}

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

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

Students also viewed these Databases questions

Question

4. Identify the supernatural aid in The Wizard of Oz.

Answered: 1 week ago