// Test driver for Stack template. // Function main uses a function template to manipulate objects of type Stack< T >. // Modification: use non-type parameter 'elements' in Stack-template #include using std::cout; using std::cin; using std::endl; #include using std::string; #include "tstack1.h" // Function template to manipulate Stack< T > template< class T, int elements > void testStack( Stack< T, elements > &theStack, // reference to the Stack< T > T value, // initial value to be pushed T increment, // increment for subsequent values const char *stackName ) // name of the Stack < T > object { cout << "\nPushing elements onto " << stackName << '\n'; while ( theStack.push( value ) ) { // success true returned cout << value << ' '; value += increment; } cout << "\nStack is full. Cannot push " << value << "\n\nPopping elements from " << stackName << '\n'; while ( theStack.pop( value ) ) // success true returned cout << value << ' '; cout << "\nStack is empty. Cannot pop\n"; } int main() { Stack< double, 5 > doubleStack; Stack< int, 10 > intStack; Stack< string, 5 > stringStack; testStack( doubleStack, 1.1, 1.1, "doubleStack" ); testStack( intStack, 1, 1, "intStack" ); testStack( stringStack, string("Eins"), string("UndEins"), "stringStack" ); return 0; }