Assignment #0

(Not to be turned in -- do on your own as you have time.)

1. Set up your compiler and verify that it compiles and links the following STL program, and run it.

#include <iostream> // You may need to use iostream.h
#include <vector>     // You may need to use vector.h
using namespace std;

int main()
    vector<int> vi;
    cout << vi[0] << " " << vi[1] << " " << vi[2] << endl;
    return 0;

2. Write a template function to search for a value of any type within an array.  Use the interface below and fill out the body of the function.  Test it with arrays of integers and with arrays of strings (the std::string class, not char*).  Turn in the program and its output.

// Find a value within an array between [*begin,*end).
// This will search *begin, *(begin+1), ..., *(end-1) for
// *value, using == for comparison.  It returns a pointer
// to the first match found, or the value in end if no
// match is found.
template <class T>
T *findit(T *begin, T*end, T const &value)
    //... fill in body of function ...

3. Use findit<int> to count the number of 8's in the following array and print out the result.

int numbers[] = {2,7,1,8,2,8,1,8,2,8};