home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP10-8.ZIP / CLASSEXM.ZIP / REVERSE.CPP < prev    next >
C/C++ Source or Header  |  1990-09-26  |  3KB  |  95 lines

  1. //
  2. // This file contains proprietary information of Borland International.
  3. // Copying or reproduction without prior written approval is prohibited.
  4. //
  5. // Copyright (c) 1990
  6. // Borland International
  7. // 1800 Scotts Valley Dr.
  8. // Scotts Valley, CA 95066
  9. // (408) 438-8400
  10. //
  11.  
  12. // Contents ----------------------------------------------------------------
  13. //
  14. //      main
  15. //
  16. // Description
  17. //
  18. //      Contains a simple example program for class Stack.
  19. //
  20. // End ---------------------------------------------------------------------
  21.  
  22. // Interface Dependencies ---------------------------------------------------
  23.  
  24. // None
  25.  
  26. // End Interface Dependencies ------------------------------------------------
  27.  
  28. // Implementation Dependencies ----------------------------------------------
  29.  
  30. #ifndef __IOSTREAM_H
  31. #include <iostream.h>       // stream i/o
  32. #define __IOSTREAM_H
  33. #endif
  34.  
  35. #ifndef __STACK_H
  36. #include <stack.h>          // Stack class.
  37. #endif
  38.  
  39. #ifndef __STRNG_H
  40. #include <strng.h>          // String class.  Note that this is not <string.h>!
  41. #endif
  42.  
  43. // End Implementation Dependencies -------------------------------------------
  44.  
  45.  
  46. // Function //
  47.  
  48. int main()
  49.  
  50. // Summary -----------------------------------------------------------------
  51. //
  52. //      Illustrates a use of the Stack class.  Reads in strings until
  53. //      you enter the string "reverse," then prints out the strings
  54. //      in reverse order.  Returns the number of strings read in, not
  55. //      including "reverse."
  56. //
  57. //      Usage:  reverse
  58. //
  59. // End ---------------------------------------------------------------------
  60. {
  61.     Stack theStack;
  62.     String reverse("reverse");
  63.  
  64.     cout << "\nEnter some strings.  Reverse will collect the strings\n";
  65.     cout << "for you until you enter the string \"reverse.\"  Reverse\n";
  66.     cout << "will then print out the strings you have entered, but in\n";
  67.     cout << "reverse order.  Begin entering strings now.\n";
  68.     for(;;)
  69.     {
  70.         char inputString[255];
  71.         cin >> inputString;
  72.         String& newString = *( new String( inputString ) );
  73.         if ( newString != reverse )
  74.         {
  75.             theStack.push( newString );
  76.         }
  77.         else // "reverse" was entered.
  78.         {
  79.             break;
  80.         }
  81.     } // end for loop until "reverse" is entered.
  82.  
  83.     cout << "\nThe strings you entered (if any) are:\n";
  84.  
  85.     while( !(theStack.isEmpty()) )
  86.     {
  87.         String oldString = (String&)theStack.pop();
  88.         cout << oldString << "\n";
  89.     }
  90.     return 0;
  91. }
  92. // End Function main //
  93.  
  94.  
  95.