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();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.