CSE 202: Computer Science II, Winter 2018
Lab 6

Create a program that reads all real numbers from standard input and displays the mean, median, modes, and range of the sequence. Your program should not display anything if fewer than two numbers were read.

The mean is the sum of all the numbers divided by the size of the sequence.

The median is the value of the middle number when the sequence is sorted (in ascending order). If two numbers are in the middle of the sorted sequence, then the median is the sum of those two numbers divided by 2.

The mode is the number that occurs the most in the sequence. For this program, if there is no mode, then do not display a mode; if there is more than one mode, then display all of the modes.

The range is the difference between the largest and smallest values in the sequence.

In your program, store the numbers as type double and do not use arrays. You are encouraged to use vector, map, and the functions found in <algorithm> to complete this lab.

Example of a working program
1 2 2 3 4 7 9 9 Mean: 4.625 Median: 3.5 Modes: 2 9 Range: 8

Program source to find the modes of a number sequence

Solution