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.
median()to the library
DoubleVectorOpsfrom Lab 10 that finds the median of a sequence of double values. That is, add the prototype to
DoubleVectorOps.hand also to
DoubleVectorOps.txtwith 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
To sort a vector
v, we simply write:
median()function should sort a copy of the scores vector rather than the actual scores.
grades.cppthat displays the average and the standard deviation of a list of numbers so that it also displays the median of the list.