Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

vector container in STL: 1) Write a template function that returns true if the v

ID: 3682908 • Letter: V

Question

vector container in STL:
1) Write a template function that returns true if the values stored in a vector<T> are in ascending order and false otherwise, wher operator < is assumed to be defined for the type T. You can only iterator to implement this function.
2) Write a template function that returns the range of values stored in a vector<T>, that is, the difference between the largest value and the smallest value, where operator < is assumed to be defined for the type T. You can only iterator to implement this function.
<algorithm> and <numeric> libraries
1) Write a template function EraseAll which
receives a vector<EltType> vec and an EltType elt
postcondition: all elements in vec which are equal to elt have been erased.
algorithm: uses STL library functions whenever possible.
2) Write a function DiffFromAverage which
receives a list<double> lst
action: computes the average of the elements
outputs the difference between the largest element and the average
outputs the difference between the smallest element and the average
algorithm: does not contain a loop; instead uses STL library functions.

Explanation / Answer

template void EraseAll(vector & vec, EltType elt) { vector::iterator itr; while (itr = find(vec.begin(), vec.end(), elt) { if (itr != vec.end()) vec.erase(itr); } cout