[Solved]41 Create New File Dev C Write Program Save Random Numbers File Header Comments Must Prese Q37155280
4.1 Create a new file (in Dev C++)
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 thefile when you are done with it.
Note there is no output to the screen, only a file. However, youmay want to consider writing to the screen first to make sure youare generating the numbers correctly…
To generate a random number between min and max, #include”getRandomInt.h”, and call getRandomInt(max, min). The attachedgetRandomInt.h file should be downloaded andplaced 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
Attached Files:
getRandomInt.h (916 B)
/* 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 <random> //for random functions#include <ctime> //for time functionsusing namespace std;// GLOBAL VARIABLE (needed to reset seed every time function is called)default_random_engine gen((unsigned int)time(0)); //seed random engineint 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<int> dis(min, max); //range return dis(gen);} //end getRandomInt
Expert Answer
Answer to 4.1 Create a new file (in Dev C++) Write a program to save random numbers to a file: Header comments must be present Use… . . .
OR

