subject

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 ( SEED ) 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.
Programming Notes:
• You are not allowed to use any I/O functions from the C library, such as scanf or printf. Instead, use the I/O functions from the C++ library, such as cin or cout.
• 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 don’t want the statements in a header file are processed more than once.) #ifndef A-CONST-VALUE // should not be defined any place else #define A-CONST-VALUE // same const value as for ifndef directive // put all statements for your header file here #endif
• Include all system header files (that you need in your program) in your header file. For example, to gain access to the iostream library, which defines a set of simple I/O operations, insert the line #include in your header file, to gain access the I/O manipulators such as setw, insert the line #include in your header file; to access the vector container in the STL, insert the line #include in your header file; and to use the functions in the Randomly Generated Integers 2 STL such as sort, insert the line #include in your header file. At the top of your source file, insert your header file by the following statement: #include "prog1.h".
• To compile and link your program with the system library routines execute: Make N=1. (Assuming you’ve already a link to the script Make in directory: ~cs340/bin from your bin directory.) To test your program, execute: Make execute N=1. This command executes your program and displays its output as well as any error messages both on the terminal screen and in prog1.out. After you are done with the program, you don’t need its object and executable files any more. To delete them, execute: Make clean.
• 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 ( SEED ) 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.

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 02:50, bfell92
There’s only one game mode that stars with the letter ‘e’ in cs: go. which of the options below is it?
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, DSUDLER5555
Write a program that prints the day number of the year, given the date in the form month-day-year. for example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. the program should check for a leap year. a year is a leap year if it is divisible by 4, but not divisible by 100. for example, 1992 and 2008 are divisible by 4, but not by 100. a year that is divisible by 100 is a leap year if it is also divisible by 400. for example, 1600 and 2000 are divisible by 400. however, 1800 is not a leap year because 1800 is not divisible by 400.
Answers: 3
image
Computers and Technology, 24.06.2019 05:50, 11232003
What all vehicles has tesla inc. created over the years
Answers: 3
image
Computers and Technology, 24.06.2019 10:00, alexapacheco012
What did i do wrong with this const discord = require('discord. js'); var bot = new discord. client(); const token = 'ntm3mjcxmtu1mjg3ote2ntq2.dyogew. dpfiwfpuifzuzvifop-csuxasnm' const prefix = "! " bot. registry. registergroup('simple', 'simple'); bot. registry. registerdefaults(); bot. registry. + '/commands'); bot. on('message', message => { if(message. content == 'hi! ') { message. channel. send ('@everyone sup, how is @everyone day going'); } if(message. content == 'h3lp') { message. channel. send ('dose not have any commands yet'); } bot. on('ready', function() { console. log("ready") }); bot. login(token);
Answers: 1
You know the right answer?
For this computer assignment, you are to write a C++ program to generate random integers in the rang...

Questions in other subjects:

Konu
Mathematics, 26.09.2019 02:20