Question: IN C++ For this assignment, write a program that will generate three groups of random numbers in the range of 70-100 and, for each group,
IN C++ For this assignment, write a program that will generate three groups of random numbers in the range of 70-100 and, for each group, count how many values fall into particular ranges.
Random Number Generation
rather than asking the user for input, the random number generator will be used to determine the numbers in the groups.
This assignment will use:
- #include
- srand
- rand
Please refer back to Program 4 for reminders about how to work with random numbers. http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm4.htm
Basic Program Logic
Use a value of 5 to seed the random number generator.
For the first group, using a for loop, generate and display a series of 15 random numbers between 70 and 100. The values should be neatly displayed on a single line. For each random number that is generated, determine what range the number falls into and increment a counter for that specific range. Use the following ranges for this program:
100 99 - 90 89 - 80 79 - 70
After the 15 random numbers have been generated and displayed, display the counts for each range. Each count should be displayed on a separate line with a descriptive label. The last digit of each count should be lined up.
For the second group, repeat the basic process that was used for the first group. However, rather than using a for loop, use a while loop.
For the third group, repeat the basic process that was used for the first and second groups. However, use a do while loop.
Symbolic Constants
The program MUST use at least three symbolic constants:
- an integer that represents the number of random values to be generated in each group. Use 15.
- an integer that represents the highest random value to generate. Use 100.
- an integer that represents the smallest random value to generate. Use 70.
Program Requirements
-
Make sure to seed the random number generator by calling the srand function. This MUST be done in main before calling the rand function. The file that is handed in for grading must use srand(5);.
-
Make and use meaningful variable names.
-
Make sure to actually use the symbolic constants that are created.
-
Be sure to #include
-
The program MUST be fully documented according to the documentation standards on the course website. Include line documentation. There is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does.
-
Hand in a copy of the source code (CPP file) using Blackboard.
Output
Using srand(5); on Windows PC
Group 1 93 88 80 91 78 97 96 80 76 98 100 88 87 93 93 100 count: 1 90s count: 7 80s count: 5 70s count: 2 Group 2 99 98 89 99 92 94 88 77 71 90 80 82 88 84 70 100 count: 0 90s count: 6 80s count: 6 70s count: 3 Group 3 99 72 100 91 100 84 76 88 80 98 98 98 81 85 88 100 count: 2 90s count: 5 80s count: 6 70s count: 2
Using srand(5); on a Mac
Group 1 95 71 89 78 80 92 75 79 91 84 75 82 77 76 78 100 count: 0 90s count: 3 80s count: 4 70s count: 8 Group 2 82 81 98 91 76 94 85 77 97 94 93 90 99 86 77 100 count: 0 90s count: 8 80s count: 4 70s count: 3 Group 3 96 75 74 81 74 94 78 96 77 79 78 95 76 85 92 100 count: 0 90s count: 5 80s count: 2 70s count: 8
Using srand(5); on CodeChef
Group 1 91 83 97 80 82 84 82 100 100 85 87 81 83 80 78 100 count: 2 90s count: 2 80s count: 10 70s count: 1 Group 2 71 93 70 96 90 93 97 90 87 93 73 78 70 77 74 100 count: 0 90s count: 7 80s count: 1 70s count: 7 Group 3 91 98 85 85 77 98 99 87 97 96 72 84 76 83 94 100 count: 0 90s count: 7 80s count: 5 70s count: 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
