home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 2.ddi / CLASSEXM.ZIP / REVERSE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  2.3 KB  |  87 lines

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