Chapter 13 begins with C-style arrays and sorting and
searching arrays. It turns then to the Standard Template Library's
vector
container which wraps a dynamic array inside a class
template and builds in some very powerful and useful operations. This lab
exercise investigates this vector
container in detail.
Here are:
median()
to the library
DoubleVectorOps
from Lab 10 that finds the
median of a sequence of double values. That is, add the prototype to
DoubleVectorOps.h
and also to DoubleVectorOps.txt
with appropriate documentation; and add the definition to
DoubleVectorOps.cpp
. See Project 10.1
in the projects that go with Lab 10 for an algorithm for
computing the median. Note:
The instructions in Project 10.1 tell you to use the sort()
algorithm from the standard template library to sort the vector of doubles
— sort()
is defined in the <algorithm>
library so to use it in the definition of median()
,
you must #include <algorithm>
in DoubleVectorOps.cpp
.
To sort a vector v
, we simply write:
sort(v.begin(), v.end());
Note: Your median()
function should sort a copy of the scores vector
rather than the actual scores.
grades.cpp
that displays the
average and the standard deviation of a list of numbers so that it also
displays the median of the list.