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

The code so far is under the sample section. The int main() is complete and it c

ID: 3812334 • Letter: T

Question

The code so far is under the sample section. The int main() is complete and it calls the 3 function that already have the prototypes. Please finish the 3 functions completely as they are suppose to be created following the instruction 1-4. Thanks! Please show that it works. UllU USB pointer arithmetic to navigate them. 4 points for each function you complete. allocate STRATEGY The main function is provided. It will 1. declares a pointervariable (p and an integer variable called n. 2. calls function makearray to dynamically allocate an array assigned to p. of a random size (from 1 to 10 elements). Variable n contains the size of the The function returns a pointer that is assigned to p. 3. calls function fillarray0 that assigns random values between 1 and 10o to each element of the array using array element indexing. 4. calls function display to display all of the data in the array using pointer arithmetic Run your main program several times to demonstrate different sizes and random data. SAMPLE Here are the function prototypes with pre and post condition comments along with maino. Pre: none allocated Post an array of up to 10 elements is dynamically a pointer to that array is returned the size is assigned to reference parameter n int makearray (int& n) Pre: p points to an array of n integers Post: p is filled with random values from 1 to 100 void fillarray (int p, int n) Pre: p is an array of n integers Post: the contents of p have been displayed void display (int p, int n) int main int p, n; srand (time (0) p make array (n) cout "The size of the array is n endl; fillarray (p, n); display (p, n);

Explanation / Answer

#include <iostream>
#include <cstdlib>
using namespace std;

int* makearray(int &n)
{
    int * ptr;
    ptr = new int[n];
    return ptr;
}
void fillarray(int *p,int n)
{
    int i;
    for(i=0;i<10;i++)
    {
    *(p+i) = rand() % 100 +1;
    }
}
void display(int *p,int n)
{
    int i;
    for(i=0;i<10;i++)
    {
    cout << *(p+i)<<" ";
    }
}
int main()
{
   int *p,n;
   srand(time(0));

    n = 10;
   p = makearray(n);
   cout<<"The size of the array is "<<n<<endl;
   fillarray(p,n);
   cout<<" The elements of array : ";
   display(p,n);
  
   return 0;
}


Output: