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

Write a function that will generate an array of random numbers. It needs to: tak

ID: 3789787 • Letter: W

Question

Write a function that will generate an array of random numbers. It needs to:

take 3 integers as parameters

The first is the minimum value

the second is the maximum value

the third is the size of the new array

create a dynamically allocated array of the correct size

generate a random number (between min and max) for each element in the array

return a pointer to the array

Create a main() function that tests the above function and displays the values in the random array.

Do not use array notation inside the function. Use pointer notation only.

This is C++. Please make sure the answer is readable and executable. Thanks

Explanation / Answer

#include<iostream.h>

#include<cstdlib.h>

#include<ctime.h>

int main()

{

srand((time));

int min=5;

int max =25;

const int total_numbers=8;

int _array[total_numbers]={0};

int random_number=-1;

for(int i=0;i<total_numbers;i++)

{

random_number=min+rand()%((max-min)+1);

array[i]=random_number;

}

for(int i:array)

std::cout<<"random number"<<i<<" ";

return 0;

}

OR===========================

#include<iostream.h>

#include<math.h>

#include<cstlib.h>

int getrandomnumber(int min,int max);

int main()

{

int min,max seed,s1,s2,s3,random;

cout<<"enter a min and max";

cin>>min>>max;

if(min>max)

{

std::swap(min,max);

}

cout<<min<<max<<endl;

cout<<"enter random number s1,s2,and s3";

cin>>s1>>s2>>s3;

seed=(s1+s2*s3);

random=getrandomnumber(min,max);

cout<<"random number"<<random;

srand(seed);

return 0;

}

int getrandomnumber(int min,int max)

{

rand();

}

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