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

How can you write a program in C++ with the following? Write a function that dyn

ID: 3758047 • Letter: H

Question

How can you write a program in C++ with the following?

Write a function that dynamically allocates an array of integers. The function should accept an integer argument indicating the number of elements to allocate. The function should return a pointer to the array.

Write a function to fill an array with random integers.

Write a function that writes an array's contents to the standard output stream.

No global variables

Use default_random_engine and uniform_int_distribution to generate the random integers.

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>


void fill(int a[],int n)
{
   int i;
   for(i=0;i<n;i++)
   {
       a[i]=rand();
   }
}

void disp(int a[],int n)
{
   int i;

   for(i=0;i<n;i++)
   {
       cout<<a[i]<<" ";
   }
}

void main()
{
   int a[100];


   clrscr();
   fill(a,10);
   disp(a,10);
   getch();
}

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