Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. 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 your array expander function, and prints the values of the new expanded 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.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
Where we have to paste the input file in DEV C++ ??
===================================
// nosData.txt (Input file)
45
56
67
78
89
99
88
77
66
55
44
33
22
11
17
73
39
98
=========================================
#include <fstream>
#include <iostream>
using namespace std;
int * expandArray(int arr[],int N);
int main() {
// Declaring constant
const int SIZE=50;
// declaring variables
string fielname="nosData.txt";
int N;
ifstream dataIn;
//Getting the input entered by the user
cout<<"Enter N :";
cin>>N;
if(N<0 || N>50)
{
return 1;
}
else
{
// opening the input file
dataIn.open(fielname.c_str());
int arr[N];
/* reading the values from the file
and
* populate those values into an
array
*/
for(int i=0;i<N;i++)
{
dataIn>>arr[i];
}
// closing the input file
dataIn.close();
// calling the function
int *nos=expandArray(arr,N);
//Displaying the array
cout<<"\nDisplaying Array
Elements :"<<endl;
for(int i=0;i<2*N;i++)
{
cout<<nos[i]<<endl;
}
}
return 0;
}
// this function will double the array
int * expandArray(int arr[],int N)
{
int *nos=new int[2*N];
for(int i=0;i<2*N;i++)
{
nos[i]=0;
}
for(int i=0;i<N;i++)
{
nos[i]=arr[i];
}
return nos;
}
========================================
========================================
Output:
===================== Thank You
Get Answers For Free
Most questions answered within 1 hours.