In this lab, we practice using array and function, and implement a simple data analysis tool. You are asked to write a program that first initializes an array with 20 random integers in the range of 1 and 100, displays all numbers, analyzes these numbers to report the minimum, maximum, mean and median of the numbers. You are required to design five functions, and follow the steps (and submit intermediate outcomes for some of the steps) as detailed below.
The C++ library (a collection of useful functions) has a random number generator which produces numbers that appear to be completely random. The function rand() returns a random interger between 0 and RAND_MAX (a constant defined by the library, usually is also the
largest valid int
value). You can repeatedly call this function to get different random
numbers. In order to get random integers between \tt{min} and \tt{max}, you can
use the following function:
#include <cstdlib> /* return a random integer in the specfied value range @param min: the lower range of the random number @param max: the upper range of the random number @return: a random integer in the specified value range */ int GenerateRandomInteger (int min, int max) { int r = rand(); double r_01 = (double)r / (double)RAND_MAX; //scale the number to be a value between 0 and 1 return (r_01*(max-min)+min); // scale the value between 0 and 1 to [min,max], and return the value }
You are required to follow the following steps, and submit your program at some of the steps as required below:
cp lab8.cpp lab8_s1.cpp submit1600 lab8_s1.cppAnd then continue to next steps using lab8.cpp.
int
values. After testing this step,
use the following commands to submit this step's outcome:
cp lab8.cpp lab8_s2.cpp submit1600 lab8_s2.cppAnd then continue to next steps using lab8.cpp.
int
values. Call the function
from main() and display the value returned by the function. After testing this step, use the following commands to submit this step's outcome:
cp lab8.cpp lab8_s3.cpp submit1600 lab8_s3.cppAnd then continue to next steps using lab8.cpp.
int
values, and call
this function from main() which displays the value returned by the function. You don't need to submit anything for this step.
int
, and call this function from
main(), and display the value returned. After testing this step, submit the current code using:
cp lab8.cpp lab8_s4.cpp submit1600 lab8_s4.cppAnd then continue to next steps using lab8.cpp.
int
, and call this function
from main(), and display the value returned. After testing this step, you are done and can submit your completed project using
submit1600 lab8.cppHint: To find the median, you can first sort the array, and then report the element stored in the middle index as the median:
#include//need this header for using sort function //suppose values is the name of your array variable sort(values.begin(),values.end()); double median= values[values.size()/2];
Please finish and submit this project by April 19th, Friday.