Question: For this computer assignment, you are to write a C++ program to generate random integers in the range [ LOW = 1, HIGH = 10000

For this computer assignment, you are to write a C++ program to generate random integers in the range [ LOW = 1, HIGH = 10000 ] and to store them in a vector < int > of size VEC_SIZE = 250. Then, sort the contents of the vector (in ascending order) and display it on stdout

To sort the contents of a vector, use the sort ( ) function in the STL. In addition to the main ( ) routine, implement the following subroutines in your program:

void genRndNums ( vector < int >& v ) : This routine generates VEC_SIZE integers and puts them in vector v. Initializes the random number generator (RNG) by calling the function srand ( ) with the seed value SEED = 1, and generates random integers by calling the function rand ( ).

void printVec ( const vector < int >& v ) : This routine displays the contents of vector v on stdout, printing exactly NO_ITEMS = 12 numbers on a single line, except perhaps the last line. The sorted numbers need to be properly aligned on the output. For each printed number, allocate ITEM_W = 5 spaces on stdout.

Name your source file as prog1.cc and your header file as prog1.h

Guard the statements in your header file using the following format. (This is necessary because you dont want the statements in a header file are processed more than once.) #ifndef CONSTVALUE // which is not defined any place else #define CONSTVALUE // same const value as for ifndef directive // put all statements for your header file here #endif

Let v be a vector of integers, then the call: sort ( v.begin ( ), v.end ( ) ) sorts the elements of v in ascending order. The detailed description of the sort ( ) routine can be found on the course website and in the course textbook.

Execute the srand ( ) function (only once) before generating the first random integer with the seed value SEED. The rand ( ) function generates a random integer in the range [ 0, RAND_MAX ], where the constant value RAND_MAX is the largest random integer returned by the rand ( ) function and its value is system dependent. To normalize the return value to a value in the range [ LOW, HIGH ], execute: rand ( ) % ( HIGH LOW + 1 ) + LOW

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!