// testStack.C // // a little test program for our Stack class #include "Stack.h" #include "complex.h" void main() { // a default sized stack of ints Stack intStack; // a small stack of Complex Stack cStack(5); // push some ints onto the intStack for(int i = 0; !intStack.isFull(); i++) intStack.Push(i); // print out the intStack cout << "the integer stack: " << endl; cout << intStack << endl; // make some complex numbers and push them Complex c1 (1); Complex c2 (2, 2); Complex c3 (-3, -3); Complex c4 (4,4); // push them onto the complex stack cStack.Push(c1); cStack.Push(c2); cStack.Push(c3); cStack.Push(c4); // print out the complex stack cout << "The complex stack: " << endl; cout << cStack << endl; // look at the complex stack // note how the compiler knows that cStack.Top() // returns Complex and calls Complex operator<< cout << "Top(): top of complex stack is " << cStack.Top(); // pop the top Complex that was just printed cout << "Popping complex stack" << endl; cStack.Pop(); // Pop the stack, get the top element // and print it out cout << "just removed " << cStack.Pop_And_Top() << " from the stack" << endl; // print the remainder of the Complex stack // note how operator<< for stack will call // operator<< for Complex cout << "Stack of Complex:" << cStack << endl; }