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

C++ Write a random number generator function “ rand_integer” that returns a rand

ID: 3838964 • Letter: C

Question

C++ Write a random number generator function “ rand_integer” that returns a random integer between -10 and 10. To test this function, declare a function Array named “rand_array with a size of 32, call the rand_integer function to generate 32 random numbers, and store these number in the array. Print out each item in the array as the program output. C++ Write a random number generator function “ rand_integer” that returns a random integer between -10 and 10. To test this function, declare a function Array named “rand_array with a size of 32, call the rand_integer function to generate 32 random numbers, and store these number in the array. Print out each item in the array as the program output. C++ Write a random number generator function “ rand_integer” that returns a random integer between -10 and 10. To test this function, declare a function Array named “rand_array with a size of 32, call the rand_integer function to generate 32 random numbers, and store these number in the array. Print out each item in the array as the program output.

Explanation / Answer

#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <iostream>
using namespace std;
int rand_integer();
int main()
{
   srand (time(NULL));
   int rand_array[32];
   for(int i=0;i<32;i++)
   {
       rand_array[i]=rand_integer();
   }
   for(int i=0;i<32;i++)
   {
       cout<<rand_array[i]<<endl;
   }
   return 0;
}
int rand_integer()
{
   return rand()%(21)-10;
}

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