(C++)
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.
There are no prompts for the integer and no labels for the
expandedreversed array that is printed out.
If the integer read in from standard input exceeds 50 or is less than 0 the program terminates silently.
#include <iostream>
#include <fstream>
using namespace std;
int * arrayExpander(int *arr,int size)
{
int doubledSize=size*2;
int* arrExpanded = new int[doubledSize];
for(int i=0;i<size;i++)
{
arrExpanded[i]=arr[i];
}
for(int i=size;i<2*size;i++)
{
arrExpanded[i]=0;
}
return arrExpanded;
}
int main()
{
cout<<"Enter N value: ";
int N;
cin>>N;
cout<<"Enter "<<N<<" values:
";
int arr[N];
for(int i=0;i<N;i++)
cin>>arr[i];
int* answer=new int[N*2];
answer=arrayExpander(arr,N);
for(int i=0;i< 2*N;i++)
{
cout<<answer[i]< < endl;
}
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
int * arrayExpander(int *arr,int size)
{
int doubledSize=size*2;
int* arrExpanded = new int[doubledSize];
for(int i=0;i<size;i++)
{
arrExpanded[i]=arr[i];
}
for(int i=size;i<2*size;i++)
{
arrExpanded[i]=0;
}
return arrExpanded;
}
int main()
{
cout<<"Enter N value: ";
int N;
cin>>N;
cout<<"Enter "<<N<<" values:
";
int arr[N];
for(int i=0;i<N;i++)
cin>>arr[i];
int* answer=new int[N*2];
answer=arrayExpander(arr,N);
for(int i=0;i< 2*N;i++)
{
cout<<answer[i]< < endl;
}
return 0;
}
(C++) Write a function that accepts an int array and the array’s size as arguments. The function...
9.10: 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 the 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...
/* Array expander: Write a function that accepts an int array as argument. The function should create a new array that is n times the size of the argument array, where n is a user input. 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 */ #include <iostream> using namespace std; const int NUM_ELEM...
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....
1. The following program calls the function countLarger that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n. The function countLarger should return the number of integers in the array that are greater than the value of the argument n. Update the program to include the definition of the function countLarger. #include <iostream> using namespace std; int countLarger(int[], int, int); // Function prototype int main() const int...
in a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n.
write the program in c++ Pointen & A???ys: Write u function that is passed a pointer to a float array, and the size the array as an int. The function should return a pointer to the maximum element in the array The function should be: int *maxp(float* ap, int size) Write a main() program to lest the function with different input arrays. Grading Criteria (1 point each): Uses cin/cout correct function definition prompts user for input, reads it in correct...
- Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...
c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...
In C++ Write a function that receives an integer array with its size and determines whether the array is already sorted in increasing order. Write a test program (main function) that prompts the use to enter a list and displays whether the list is sorted or not. The first number in the input indicates the size of the list. Assume the maximum list size is 20.
In C++ Write a function that receives an integer array with its size and determines whether the array is already sorted in increasing order. Write a test program (main function) that prompts the use to enter a list and displays whether the list is sorted or not. The first number in the input indicates the size of the list. Assume the maximum list size is 20.