Lab 5 - STL Algorithms
Due: Wednesday at 5:00pm
This lab is worth 10 points.
This lab will use the STL algorithms on the vector class in order to learn
how to use the STL algorithms. You will need the following headers in your
lab5.cpp file:
#include <vector>
#include <algorithm>
using namespace std;
This will give you access to the algorithms and the vector class. The vector
class contains the standard iterator functions begin()
and
end()
. For example, the following code snippet from page 565
of the book will sort a vector:
int ints[] = {555, 33, 444, 22, 222, 777, 1, 66};
vector<int> v(ints, ints + 5); // Use only the first 5 elements of ints
sort(v.begin(), v.end());
Create a main program that does the following sequentially (no menus needed):
- Fills in a vector with 10 integers using a variation on the above code.
- Displays the vector to the screen (see pages 565-566 for code).
- Prompts the user for one integer and searches for that integer. Displays
"found" if found and "not found" if not found.
- Sorts the vector and displays it to the screen.
- Prompts the user for one integer and uses binary search to find the
integer. Again displays "found" if found and "not found" if not found.
- Reverses the vector and displays it to the screen.
- Calls unique and displays the results to the screen.
- Calls random_shuffle and displays the results to the screen.
Email me your completed program.