Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

getrandomint.h : /* FUNCTION: getRandomInt * TASK: This function will return a random integer * DATA IN: min (optional), max * DATA OUT: random integer

getrandomint.h :

/* FUNCTION: getRandomInt * TASK: This function will return a random integer * DATA IN: min (optional), max * DATA OUT: random integer between min and max */ // // source: https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution // If min argument is excluded, range will be 1 - max // If max < min, then swap min and max #include  //for random functions #include  //for time functions using namespace std; // GLOBAL VARIABLE (needed to reset seed every time function is called) default_random_engine gen((unsigned int)time(0)); //seed random engine int getRandomInt(int max, int min = 1) { // if max < min, then swap if (max < min) { int temp = min; min = max; max = temp; } //end if //set up random generator uniform_int_distribution dis(min, max); //range return dis(gen); } //end getRandomInt

Write a program to save random numbers to a file:

  • Header comments must be present
  • Use constants for minimum and maximum values
  • Each number should be in the range 1 - 100 (min: 1, max: 100)
  • Each row should have 10 - 30 numbers (min: 10, max: 30), separated by a single space
  • The file should have 20 - 40 rows (min: 20, max:40)
  • The file should be named "random_numbers.txt"
  • Use comments and good style practices

Make sure to open the file before writing to it, and close the file when you are done with it.

Note there is no output to the screen, only a file. However, you may want to consider writing to the screen first to make sure you are generating the numbers correctly...

To generate a random number between min and max, #include "getRandomInt.h", and call getRandomInt(max, min). The attached getRandomInt.h file should be downloaded and placed in the same folder as your CPP program.

EXAMPLE:

rows = getRandomInt(MAX_ROWS, MIN_ROWS);

SAMPLE RESULTS (partial):

86 27 63 73 61 88 12 64 49 18 98 43 48 56 15 57 58 75 79 45 16 91 91 39 56 38 78 68 21 97 46 83 91 70 5 39 9 32 18 43 10 53 94 15 96 79 26 11 15 35 1 82 91 33 43 49 77 93 4 45 78 24 13 25 87 13 34 68 15 94 70 54 76 96 83 26 63 74 42 9 100 25 48 33 95 41 20 90 89 57 21 96 19 11 24 30 98 36 54 9 100 98 57 41 14 52 48 94 16 64 51 13 87 25 94 21 13 95 18 10 16 97 23 67 41 24 55 19 39 91 46 4 43 3 50 89 59 96 22 61 81 88 60 85 13 48 28 21 6 3 84 72 69 6 70 55 26 48 92 34 99 33 10 65 51 97 19 28 43 60 56 72 20 91 19 80 26 90 9 34 49 3 22 72 58 100 4 63 46 34 22 83 2 77 55 64 24 49 71 87 11 82 35 66 36 45 44 63 40 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

please solve 2 4 and 2 6 with it's components

Answered: 1 week ago

Question

state what is meant by the term performance management

Answered: 1 week ago