C++ Reverse Array Write a function that accepts an int array and the array ’s si
ID: 3855081 • Letter: C
Question
C++ Reverse Array
Write a function that accepts an int array and the array ’s size as arguments . The function should create a copy of the array , except that the element values should be reversed in the copy. The function should return a pointer to the new array . Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an array . The program then passes the array to the your reverse array function, and prints the values of the new reversed array on standard output , one value per line. You may assume that the file data has at least N values
Prompts And Output Labels. There are no prompts for the integer and no labels for the reversed array that is printed out.
Input Validation. If the integer read in from standard input exceeds 50 or is less than 0 the program terminates silently.
Thank you
Explanation / Answer
#include <iostream>
using namespace std;
int reverseArray(int, int, int *);
int main() {
const int size = 5;
int array1 [size] = {10,20,30,40,50};
int newArray [size];
int* numptr = array1;
reverseArray(array1, size, numptr);
}
int reverseArray(int array1[], int size, int *numptr) {
int count;
cout << "This is the orginal array: " ;
while (numptr < &array1[4]) {
cout << *numptr << " ";
numptr ++;
}
return 0;
;}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.