Write a program that creates an array of integers from 1 to 10 then : Include in
ID: 3682182 • Letter: W
Question
Write a program that creates an array of integers from 1 to 10 then : Include in your program the following functions: A function that accepts the integer array and the array size as a arguments. The function should create a copy of the array, except the values will be reversed in the copy. The function should return a pointer to the new array. A function that accepts the integer array, and the array size as an argument. The function should create a new array that is twice the size of the original array. It should copy the original array information in and then initialize the unused elements to 0. It should return a pointer to the new array. A function that accepts the integer array and the array size as a arguments. It should print the array's data with spaces between the numbers Any other function you need. In main, call the reverse function, print then the doubling function and print.
Explanation / Answer
#include<iostream>
using namespace std;
int* reverse(int A[],const int n);
int* doubleIt(int A[],const int n);
void print(int A[],int n);
int main()
{
const int size=10;
int A[]={1,2,3,4,5,6,7,8,9,10};
int *B = reverse(A,size);
int *C = doubleIt(A,size);
cout<<" Initial Array ";
print(A,size);
cout<<" After reverse function ";
print(B,size);
cout<<" After doubling function ";
print(C,2*size);
}
int* reverse(int A[],const int n)
{
int *B=new int(n);
int i=0;
while(i<n)
{
B[i]=A[n-i-1];
i++;
}
return B;
}
int* doubleIt(int A[],const int n)
{
int *B=new int(n*2);
int i=0;
while(i<n*2)
{
if(i<n)
B[i]=A[i];
else
B[i]=0;
i++;
}
return B;
}
void print(int A[],int n)
{
int i =0;
while(i<n)
{
cout<<A[i]<<" ";
i++;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.