/* Filename: reverse.cpp Programmer: Br. David Carlson Date: March 28, 1998. Modified: April 23, 1999 to use an array-based stack. Modified: June 7, 1999 to use exceptions. Modified: June 26, 2000 to use modern headers. Last Modified: December 23, 2001 This program prompts the user to enter a sequence of numbers (floats) and then prints them in reverse order. (Change the CTRL z to CTRL d for Linux.) Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include "arrstack.h" int main(void) { ArrStackClass Stack; ItemType Number, Item; // Change CTRL z to CTRL d for Linux: cout << "Enter a number (CTRL z to end): "; cin >> Number; while (! cin.fail()) { try { Stack.Push(Number); } catch(int Num) { cout << "Warning: Push not done -- out of space." << endl; } // Change CTRL z to CTRL d for Linux: cout << "Enter another number (CTRL z to end): "; cin >> Number; } if (Stack.Empty()) cout << endl << endl << "Stack is empty" << endl; else { cout << endl << endl << "Numbers in reverse order are:" << endl; while (! Stack.Empty()) { Stack.Pop(Item); cout << Item << endl; } } return 0; }