CISC1600: Computer Science I Lab 10

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.

Random number generator:

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
}

Requirements:

You are required to follow the following steps, and submit your program at some of the steps as required below:

  1. Call the GenerateRandomIteger from the main function to generate and display 20 random integers in the range of 1 and 100. Note that you don't need to store the integers in a array for this step. Use the following command to submit this step's outcome:
    cp lab8.cpp lab8_s1.cpp
    submit1600 lab8_s1.cpp
    
    And then continue to next steps using lab8.cpp.

  2. First modify the code to store the random numbers into an array, design and implement a function that displays each element in an array of 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.cpp
    
    And then continue to next steps using lab8.cpp.

  3. Design and implement a function that calculates the maximum value stored in an array of 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.cpp
    
    And then continue to next steps using lab8.cpp.

  4. Design and implement a function that calculates the minimum value stored in an array of 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.

  5. Design and implement a third function that calculates the mean of values stored in an array of 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.cpp
    
    And then continue to next steps using lab8.cpp.

  6. Design and implement a function that returns the median of values stored in a array of 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.cpp
    
    Hint: 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];
    

Deadline:

Please finish and submit this project by April 19th, Friday.