Question: Reverse Array Write a function that accepts an int array and the array s size as arguments . The function should create a copy of
Reverse Array Write a function that accepts an int array and the array s size as arguments . The function should create a copy of thearray , except that the element values should be reversed in the copy. The function should return a pointer to the newarray . 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.
Here is my program but i am not getting any output :(
/* C++ Program that reads data from file and reverse the array and prints back */
#include
using namespace std;
//Function that reverses the array int* reverseArray(int arr[], int N) { int i, j=0;
int* rev;
//Allocating memory rev = new int[N];
//Looping in back side for(i=N-1; i>=0; i--, j++) { //Storing values rev[j] = arr[i]; }
//Returning pointer return rev; }
//Main function int main() { int N, i;
//Array declaration int *values;
cin >> N;
//Validating N value if(N > 50 || N < 0) return 0;
//Allocating memory values = new int[N];
//Opening file for reading fstream fin("data.txt", ios::in);
i = 0;
//Reading 10 values while(i
//Reverse array and print to console values = reverseArray(values, N);
cout << " ";
//Printing values for(i=0; i cout << " "; //Closing file fin.close(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
