Question: Code in C++ The program will generate a series of random numbers that will all fall within a user specified upper limit and zero. The
Code in C++
The program will generate a series of random numbers that will all fall within a user specified upper limit and zero. The program will count the number of times each number occurs in the randomized input data.
You will NOT need to store the randomized input data or perform any analysis on this data.
You will want to create vector or use an array to store these counts. Remember each random input value can be used as an index to your array or vector so you can update the count directly. For example,
int randomsample = randnumber(); // random number 0 to 100
v[randomsample] += 1;
would update the count for the number associated with randomsample.
The user will enter from the keyboard the number of random numbers to be generated (at least 10000 samples).
The user will also be able to specify the upper limit of these random values. Please allow a maximum upper limit of 100 for these random values.
Please create functions to complete the bulleted list below. Each bulleted item could become a function. You need at least 5 to 7 functions. The more functions the better. You are free to create these functions with any name and number of parameters. All statistics are in terms of the frequency array or vector and not the data samples.
-
Generate a random number based on a specified start and end number. This function should be able to generate random integer numbers for any range up to RAND_MAX
-
Create a frequency count vector or fill an array with counts of random numbers from a range of values from 0 to the user specified limit (no more than 100). You will need to generate the user supplied sample count number of values.
-
For a range of 0 to 100 you will have to use an array or vector of a size equal to 101.
-
You are required to call the random number function above.
-
No need to save or store the random samples.
-
-
Print array statistics including sum, mean, max, and min for the frequency array or vector.
-
You are strongly encouraged to write functions for sum, mean, max, and min. They are all very simple functions.
-
Print the array or vector in a formatted manner. You can (if you want to) combine this with the barchart display below.
-
Display a horizontal barchart scaled to fit the page. If the count goes over 60 to 70 (the approximate width of the terminal) then you should scale it to fit (make one * represent two occurences, five occurrences, etc. instead of just the one of each number in the series). You should use an asterisk * to represent the bar portion of the bar graph.
-
To scale the barchart you will need the maximum value stored in the frequency vector or array and the screen size.
The scaling factor equals (max_value/max_bar_size).
Max_bar_size is usually 60 or lower.
For sample below, the scale equals 956/60 = 16 stars per
The ciel() function might be helpful.
See Sample Output below:
Enter End Range:
10
Enter number of Samples:
10000
Index Value Bar
0 907 *********************************************************
1 911 *********************************************************
2 867 *******************************************************
3 915 **********************************************************
4 947 ************************************************************
5 873 *******************************************************
6 896 ********************************************************
7 925 **********************************************************
8 956 ************************************************************
9 890 ********************************************************
10 913 **********************************************************
Scale: 16 per *
Range: 0 to 10
Sample Count: 10000
Min Value: 867
Max Value: 956
Sum Value: 10000
Mean Value: 909.091
Remember functions can call other functions!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
