home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX1502.CPP
- //--------------------------------------------------------------
- // client code to exercise templates ASTACK and ASTACKITR
- // The Microsoft Visual C++ compiler does not support templates.
- // This program does not compile under Microsoft Visual C++.
- //--------------------------------------------------------------
-
- // files in this example:
- // %F,15,EX15021.H%EX15021.H definition of templates ASTACK and ASTACKITR
- // %F,15,EX15022.H%EX15022.H definition of String class
- // %F,15,EX15021.CPP%EX15021.CPP member functions of ASTACK
- // EX1502.CPP this file
-
- //--------------------------------------------------------------
- #include <iostream.h>
-
- #include "EX15021.h" // definition of Stack and StackIter
- #include "EX15021.cpp" // members of Stack StackIter
- #include "EX15022.h" // definition of String class
-
- //--------------------------------------------------------------
- // main() user interactive pops and pushed items on a stack
- //--------------------------------------------------------------
- void main()
- { AStack<String> MyStack; // declare a stack
- char buffer[80]; // used to input Stings
- char response = ' '; // user commands:
- cout << "P(U)SH" << endl; // U or u --> push item
- cout << "P(O)P" << endl; // O or o --> pop item
- cout << "P(R)INT" << endl; // R or r --> print stack
- cout << " (Q)uit" << endl; // Q or q --> quit
- cout << endl;
- do
- { cout << "Enter a command: ( U O R or Q ): ";
- cin >> response;
- switch (response)
- { case 'u': // push - read string and push
- case 'U': { cout << "Enter a word: ";
- cin >> buffer;
- String word(buffer);
- MyStack.Push( word);
- break; }
- case 'o': // pop - pop string and print
- case 'O': { String word = MyStack.Pop();
- cout << word << endl;
- break; }
- case 'r': // print - iterate and print
- case 'R': { AStackItr<String> next( MyStack);
- for (int i = MyStack.NumElem(); i > 0; i--)
- { String word = next();
- cout << word << endl; }
- cout << "*END*" << endl;
- break; }
- case 'q': response = 'Q'; // quit
- case 'Q': break;
- default : cout << response << " ? ";
- break;
- }
- } while ( response != 'Q' );
- }
- //--------------------------------------------------------------
-