Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help doing this. No arrays please. C++ #include Next, initialize the random number generator. This is done by calling the srand function and

I need help doing this. No arrays please.

C++

#include 

Next, initialize the random number generator. This is done by calling the srand function and passing in an integer value (known as a seed value). This should only be done ONE time and it MUST be done before actually getting a random number. A value of 1 (or any integer literal) will generate the same sequence of "random" numbers every time the program is executed. This can be useful for debugging:

srand(1);

To get a different series of random numbers each time the program is run, the actual time that the program is run can be passed as the seed value for the random number generator:

srand(time(0));

If the time function is used, make sure to include the ctime library as well.

Finally, generate a random number by calling the rand function:

num = rand();

The above line of C++ code will generate a "random" integer between 0 and RAND_MAX and saves the value in an integer variable named num. RAND_MAX is a pre-defined constant that is equal to the maximum possible random number. It is implementation dependent but is guaranteed to be at least 32,767.

Modulus division can be used to restrict the "random" integer to a smaller range:

num = rand() % 8;

will produce a value between 0 and 7. To change the range to 1 through 8, simply add 1:

num = rand() % 8 + 1;

To get random values that are within a specified range that starts at a value other than 0 or 1:

num = minimum_value + (rand() % (maximum_value - minimum_value + 1));

So, to get values within the range 3 - 17:

num = 3 + (rand() % (17 - 3 + 1));

Logic:

Seed the random number generator with a value of 24.

Generate a random number between 2 and 10. This will be the number of values in the first group. Display the number of values in the group with an appropriate label.

In a for loop that executes exactly "number of values in the first group" number of times, generate a random number between 1 and 50, display the random number, and perform the calculations that are necessary to calculate the statistics.

After the for loop has finished executing, display the four statistics with appropriate labels. Any value with a decimal point should be displayed with exactly 2 digits after the decimal point. All of the statistical values should be displayed with the last digits lining up.

Now, generate a random number between 2 and 10. This will be the number of values in the second group. Display the number of values in the group with an appropriate label.

Using a while loop that executes exactly "number of values in the second group" number of times, generate a random number between 1 and 50, display the random number, and perform the calculations that are necessary to calculate the statistics.

After the while loop has finished executing, display the four statistics with appropriate labels. Any value with a decimal point should be displayed with exactly 2 digits after the decimal point. All of the statistical values should be displayed with the last digits lining up.

Finally, generate a random number between 2 and 10. This will be the number of values in the third group. Display the number of values in the group with an appropriate label.

Using a do while loop that executes exactly "number of values in the third group" number of times, generate a random number between 1 and 50, display the random number, and perform the calculations that are necessary to calculate the statistics.

After the do while loop has finished executing, display the four statistics with appropriate labels. Any value with a decimal point should be displayed with exactly 2 digits after the decimal point. All of the statistical values should be displayed with the last digits lining up.

Symbolic Constants

This program MUST use at least 3 symbolic constants.

Two of the constants should be for the minimum and maximum values for the size of the groups of numbers. The minimum group size is 2. The maximum group size is 10.

The other constant is for the maximum value for the numbers to be processed. The maximum value is 50.

More symbolic constants may be added to the code if necessary.

Output

Run using srand(24)

The for loop will generate 10 numbers. The numbers are 38 45 1 30 35 29 18 13 31 4 Smallest: 1 Largest: 45 Sum: 244 Average: 24.40 The while loop will generate 9 numbers. The numbers are 38 28 12 2 35 39 17 17 37 Smallest: 2 Largest: 39 Sum: 225 Average: 25.00 The do while loop will generate 4 numbers. The numbers are 14 18 32 41 Smallest: 14 Largest: 41 Sum: 105 Average: 26.25

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

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

4. Why does happiness resist easy change?

Answered: 1 week ago

Question

Design a health and safety policy.

Answered: 1 week ago