stacktem.cpp 1.4 KB

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