stacker.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // stacker.cpp -- testing the Stack class
  2. #include <iostream>
  3. #include <cctype> // or ctype.h
  4. #include "stack.h"
  5. int main()
  6. {
  7. using namespace std;
  8. Stack st; // create an empty stack
  9. char ch;
  10. unsigned long po;
  11. cout << "Please enter A to add a purchase order,\n"
  12. << "P to process a PO, or Q to quit.\n";
  13. while (cin >> ch && toupper(ch) != 'Q')
  14. {
  15. while (cin.get() != '\n')
  16. continue;
  17. if (!isalpha(ch))
  18. {
  19. cout << '\a';
  20. continue;
  21. }
  22. switch(ch)
  23. {
  24. case 'A':
  25. case 'a': cout << "Enter a PO number to add: ";
  26. cin >> po;
  27. if (st.isfull())
  28. cout << "stack already full\n";
  29. else
  30. st.push(po);
  31. break;
  32. case 'P':
  33. case 'p': if (st.isempty())
  34. cout << "stack already empty\n";
  35. else {
  36. st.pop(po);
  37. cout << "PO #" << po << " popped\n";
  38. }
  39. break;
  40. }
  41. cout << "Please enter A to add a purchase order,\n"
  42. << "P to process a PO, or Q to quit.\n";
  43. }
  44. cout << "Bye\n";
  45. return 0;
  46. }