// Example 10.11. Test program for templated array class #include using namespace std; #include template void dump(const vector& vec); // display vector int main() { int n = 10; // vector size // use constructor with size and filler values vector a(n, 7); // use at() method a.at(0) = a.at(3) = 5; cout << "2nd element of a is " << a[1] << endl; cout << "Enter 3rd element: " ; cin >> a.at(2); cout << "Vector a: "; dump(a); // use copy constructor vector b = a; cout << endl << "Results of copy constructor: "; dump(b); // use default constructor vector c; // use overloaded assignment operator c = a; cout << endl << "Results of overloaded assignment operator: "; dump(c); // display size cout << "Capacity of a = " << a.size() << endl; // resize a.resize(15); cout << endl << "Vector a resized to 15:" << endl; dump(a); a.resize(5); cout << endl << "Vector a resized to 5: "; dump(a); return 0; } // // Function to display the elements of the vector on a line // Pre: vec is constant call-by-reference vector of type int. // Post: The vec is displayed. // template void dump(const vector& vec) { for (int j = 0; j < vec.size(); ++j) cout << vec.at(j) << ' '; cout << endl; }