Operational Objectives: Create a project that computes the mean and median of a sequence of integers received via standard input. Deliverables: 3 files: stats.h, stats.cpp, main.cpp Note that these files constitute a self-contained project.
Given a finite collection of n numbers:
Note that to find the median of a collection of data, it is convenient to first sort the data, that is, put the data in increasing (or non-decreasing) order. Then the median is just the middle datum in the sorted sequence (or the average of the two middle data, if there are an even number). One of the more intuitive sort algorithms is called Insertion Sort, which operates on an array a[0..n-1] of elements. The idea is to "insert" the value of a[i] into the sub-array a[0..i-1] at the largest possible index that results in the expanded sub-array a[0..i] sorted. We insert at the highest possible index in order not to place the value ahead of any previously inserted elements with the same value. The subarray a[0..i-1] is assumed to be sorted at the beginning of each insertion step. The base case consists of a one-element array a[0..0], which is always sorted. Here is a "pseudocode" description of the algorithm:
for (i = 1; i < n; ++i)
t = a[i]; // remember the value in a[i]
starting at j = i
while j > 0 and t < a[j - 1]
copy a[j-1] to a[j]
j = j - 1
end while // now we have t >= a[j]
copy t into a[j]
end for
The inner loop copies all elements in a[0..i-1] up one index until the correct place for t is found. Then put t in that place.
The number of integers input by the user is not known in advance, except that it will not exceed 100. Numbers are input through standard input, either from keyboard or file re-direct. The program should read numbers until a non-digit or end-of-file is encountered or 100 numbers have been read. Once the input numbers have been read, the program should calculate the mean and median and then report these values to standard output. The source code should be structured as follows:
Implement separate functions with the following prototypes:
The source code should be organized as follows:
The Sort() function should implement the Insertion Sort algorithm