From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog2/Stack/Tst_test.cpp | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Bachelor/Prog2/Stack/Tst_test.cpp (limited to 'Bachelor/Prog2/Stack/Tst_test.cpp') diff --git a/Bachelor/Prog2/Stack/Tst_test.cpp b/Bachelor/Prog2/Stack/Tst_test.cpp new file mode 100644 index 0000000..5e9e9f8 --- /dev/null +++ b/Bachelor/Prog2/Stack/Tst_test.cpp @@ -0,0 +1,50 @@ +// 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; +} \ No newline at end of file -- cgit v1.2.3