Question: c++ Create a program that does the following Create an array of 30 numbers. Fill the array with the numbers 40 through 69, For example,
c++
Create a program that does the following
- Create an array of 30 numbers.
- Fill the array with the numbers 40 through 69,
- For example, the zero elements of the array should contain 40 while the one element should contain 41.
- Print the array out to the screen.
- Then create a second array of size 20.
- Fill this array with random numbers.
- Hint, you can use the random number code from here to help: C++ Random Numbers
- Find the SUM of all 20 of these numbers.
- Then print the SUM of the numbers followed by the list of random numbers to a text file called "numbers.txt."
- --------------------------------------------------------------------------------------------------------------------------------------------------------
-
C++ Random Numbers
- Step 1 :
- #include
- #include
- #include
- Step 2:
- above "using namespace std" type the following lines. Outside main()
- unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
- std::default_random_engine rd(seed1);
- std::mt19937 mt(rd());
- above "using namespace std" type the following lines. Outside main()
- Step 3:
- prototype one of the two following functions
- int makeRandomInt(int, int);
- OR
- double makeRandomDouble(int, int);
- int makeRandomInt(int, int);
- prototype one of the two following functions
- Step 4a:
- Create the following function if you want random Ints:
- int makeRandomInt(int MIN, int MAX)
- {
- std::uniform_int_distribution
dist(MIN, MAX); - return dist(mt);
- }
- Create the following function if you want random Ints:
- Step 4b
- Create the following function if you want random Ints:
- double makeRandomDouble(int MIN, int MAX)
- {
- std::uniform_real_distribution
dist(MIN, MAX); - return dist(mt);
- }
- Create the following function if you want random Ints:
- Step 5
- Use the function in the main
- x = makeRandomInt(1,10);
- or
- x = makeRandomDouble(1,10);
- Where 1 is the min and 10 is the max.
- x = makeRandomInt(1,10);
- Use the function in the main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
