Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming Array Meets Pointers (20 Points) The goal of this problem is to

ID: 3691209 • Letter: C

Question

C++ Programming

Array Meets Pointers (20 Points) The goal of this problem is to perform operations on an array, without using the "subscript operator", but only with pointers. 3. Step 1: Inside the main function, ask user to input a positive integer N less than or equal to 30. Input validation is necessary here. Create an array randomnums of N integer elements using new operator, and initialize it with unique random integers. Print the array. Step 2: Write a function int* arrayManipulator(int arrayPoiner, const int size). This function receives a pointer to the array created in Step 1 Inside arrayManipulator create a new array reversedarray and dynamically allocate memory for this array using new operator with length as size. Initialize reversedarray with the elements pointed by arrayPoiner. Now, reverse the elements of reversedarray strictly using pointers, you cannot use subscript Write a function int* arrayManipulator(int'arrayPoiner, const int size). This function receives a operator. Return the pointer to reversedarray Step 3: Inside the main function, receive the pointer returned in step 2.

Explanation / Answer

#include <iostream>
using namespace std;

int* arrayManipulator(int* array,const int size)
{
    int* reversedarray=new int[size];
    printf(" Inside arraymanipulator:");
    printf(" The elements of reversed array: ");
     for ( int i = 0; i < size; i++ ) {
         *(reversedarray+i)=*(array+i);
       printf("%d ",*(reversedarray+i));
   }

    int *temparray=new int[size];
    for(int i=0;i<size;i++)
    {
        *(temparray +size -1 -i)=*(array + i);
    }
   reversedarray=temparray;
    return reversedarray;
}
int main()
{
    int n;
    bool flag=true;
    while(flag)
    {
        cout << "Please input N in range of (1-20): ";
        cin>>n;
        if(!(n>20))
        flag=false;
    }
    printf(" The initial array elemnts of randomnums are: ");
    int * arrayMain = new int[n];
    for ( int i = 0; i < n; i++ ) {
       *(arrayMain + i)=(i*2)+1;
       printf("%d ",*(arrayMain+i));
   }

   int* reversearray=arrayManipulator(arrayMain,n);
    printf(" Inside main:");
    printf(" The elements of reversed array: ");
    for ( int i = 0; i < n; i++ ) {
       printf("%d ",*(reversearray+i));
   }

   delete[] reversearray;
   delete[] arrayMain;
   printf(" Statements used to deallocate memory ");
   printf("delete[] reversedarray");
   printf(" delete[] arrayMain");
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote