CSCI 240 | Fall 2025 |
For this assignment, write a C++ program that will calculate a set of statistics for an unknown number of small randomly sized sets of random numbers.
The statistics that will be calculated:
The cpp file that is submitted for grading must be named assign5.cpp.
As with assignment 4, the random number generator will be used to determine the size of the sets and the values in the sets.
This assignment will use:
If a reminder is needed about how to use the random number generator and how to limit the values that are produced, refer back to assignment 4:
Ask the user to enter the seed value for the random number generator and use it with the srand() instruction.
In a loop that executes as long as the user wants to display a set of values and calculate the statistics:
Generate a random number between 2 and 15. This will be the number of values in the current set.
In a loop that executes exactly "number of values in the current set" number of times:
generate a random number between 1 and 100
display the random number
calculate what is need for the statistics (sum, sum of squares, etc...)
Calculate the average and standard deviation for the current set of values.
Display the statistics for the current set of values. The statistics should be displayed on separate lines of output with the labels shown in the output. The last digit of each value should be lined up. The average and standard deviation should be displayed with exactly 2 digits after the decimal point.
Ask the user if they would like to generate a new set of values and calculate a new set of statistics. The answer should be read into a string variable. An answer of "Y" or "y" indicates the user wants a new set of values.
The standard deviation is calculated as follows:
where
For example, if a set contains 4 numbers:
7 3 4 5
then
Σ( x2 ) is equal to (7 * 7) + (3 * 3) + (4 * 4) + (5 * 5)
(Σ x)2 is equal to (7 + 3 + 4 + 5) * (7 + 3 + 4 + 5)
n is equal to 4
Make and use meaningful variable names.
Use the sqrt()
function when calculating the standard
deviation. Don't forget to #include <cmath>.
Hand in a copy of the source code (the CPP file) on the autograder and Blackboard.
The display of random numbers in a set should start with exactly two newline characters.
The individual random numbers should be displayed in a field of 5 characters.
The labels for the statistics should all be preceded by exactly 2 spaces.
The statistics are displayed in fields of exactly 17, 25, 26, 30, 26, and 15 characters.
Seed Value? 5 The random numbers are: 94 56 50 61 31 28 50 73 41 15 22 34 77 27 Number of Values: 14 Smallest: 15 Largest: 94 Sum: 659 Average: 47.07 Standard Deviation: 23.12 Again (Y/N)? y The random numbers are: 64 8 51 32 18 93 94 12 37 50 53 Number of Values: 11 Smallest: 8 Largest: 94 Sum: 512 Average: 46.55 Standard Deviation: 29.30 Again (Y/N)? Y The random numbers are: 23 32 52 Number of Values: 3 Smallest: 23 Largest: 52 Sum: 107 Average: 35.67 Standard Deviation: 14.84 Again (Y/N)? y The random numbers are: 60 11 54 16 23 Number of Values: 5 Smallest: 11 Largest: 60 Sum: 164 Average: 32.80 Standard Deviation: 22.60 Again (Y/N)? n
Seed Value? 5 The random numbers are: 46 25 97 57 14 21 50 75 58 Number of Values: 9 Smallest: 14 Largest: 97 Sum: 443 Average: 49.22 Standard Deviation: 26.74 Again (Y/N)? Y The random numbers are: 32 73 11 Number of Values: 3 Smallest: 11 Largest: 73 Sum: 116 Average: 38.67 Standard Deviation: 31.53 Again (Y/N)? y The random numbers are: 22 95 46 54 61 22 5 52 98 Number of Values: 9 Smallest: 5 Largest: 98 Sum: 455 Average: 50.56 Standard Deviation: 31.77 Again (Y/N)? y The random numbers are: 72 96 50 87 35 98 90 14 36 10 Number of Values: 10 Smallest: 10 Largest: 98 Sum: 588 Average: 58.80 Standard Deviation: 34.02 Again (Y/N)? n
Seed Value? 5 The random numbers are: 66 11 73 Number of Values: 3 Smallest: 11 Largest: 73 Sum: 150 Average: 50.00 Standard Deviation: 33.96 Again (Y/N)? Y The random numbers are: 33 21 Number of Values: 2 Smallest: 21 Largest: 33 Sum: 54 Average: 27.00 Standard Deviation: 8.49 Again (Y/N)? y The random numbers are: 74 82 27 Number of Values: 3 Smallest: 27 Largest: 82 Sum: 183 Average: 61.00 Standard Deviation: 29.72 Again (Y/N)? Y The random numbers are: 61 99 11 21 21 27 29 87 15 6 Number of Values: 10 Smallest: 6 Largest: 99 Sum: 377 Average: 37.70 Standard Deviation: 32.85 Again (Y/N)? n