Advertisement
Evinreeder

Main

Apr 30th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. //---------------------------------------------------------------------------------------------------
  2. // Stack/Queue Test Program
  3. // CS 215 - Spring 2017
  4. //---------------------------------------------------------------------------------------------------
  5. // Author: Amberlyn Schjoll
  6. // Section: 011
  7. // Date: 4/27/17
  8. //---------------------------------------------------------------------------------------------------
  9. // A menu driven program to test the enQ and deQ functions of a queue, and the push and pop functions
  10. // of a stack.
  11. //---------------------------------------------------------------------------------------------------
  12.  
  13. #include <iostream>
  14. #include <limits>
  15. #include <iomanip>
  16.  
  17. #include "stack.h"
  18. #include "queue.h"
  19. // we dont need to include node.h bc it is already included by stack.h and queue.h
  20.  
  21. using namespace std;
  22.  
  23. // TO DO: include the local stack and queue header files
  24.  
  25. //---------------------------------------------------------------------------------------------------
  26. // testPush
  27. //---------------------------------------------------------------------------------------------------
  28. // Given a stack; asks the user for a key and invokes push(). Prints the stack.
  29. void testPush(stack & s) {
  30. int key;
  31. cout << "Enter key: ";
  32. cin >> key;
  33. push(s, key);
  34. printStack(s);
  35.  
  36. } // testPush()
  37.  
  38. //---------------------------------------------------------------------------------------------------
  39. // testPop
  40. //---------------------------------------------------------------------------------------------------
  41. // Given a stack, pops the top, prints the item popped, and prints the stack
  42. void testPop(stack & s) {
  43. int key = pop(s);
  44. cout << "Popped: " << key << endl;
  45. printStack(s);
  46. } // testPop()
  47.  
  48. //---------------------------------------------------------------------------------------------------
  49. // testEnQ
  50. //---------------------------------------------------------------------------------------------------
  51. // Given a Q, asks the user to enter a key and enQ's it, then prints the Q
  52. void testEnQ(queue & q) {
  53. int key;
  54. cout << "Enter key: ";
  55. cin >> key;
  56. enQ(q, key);
  57. printQ(q);
  58. } // testEnQ()
  59.  
  60. //---------------------------------------------------------------------------------------------------
  61. // testDeQ
  62. //---------------------------------------------------------------------------------------------------
  63. // Given a Q, deQ's the next item and prints it, and prints the Q
  64. void testDeQ(queue & q) {
  65. int key = deQ(q);
  66. cout << "Dequeued: " << key << endl;
  67. printQ(q);
  68. } // testDeQ()
  69.  
  70. //---------------------------------------------------------------------------------------------------
  71. // askOption
  72. //---------------------------------------------------------------------------------------------------
  73. int askOption() {
  74. int option = 6;
  75.  
  76. cout << "Test Menu: \n";
  77. cout << "1. Push \n";
  78. cout << "2. Pop \n";
  79. cout << "3. EnQ \n";
  80. cout << "4. DeQ \n";
  81. cout << "5. Print stack and queue\n";
  82. cout << "6. Exit\n";
  83. cout << "Enter option: ";
  84. cin >> option;
  85.  
  86. return option;
  87. } // askOption()
  88.  
  89. //---------------------------------------------------------------------------------------------------
  90. // main
  91. //---------------------------------------------------------------------------------------------------
  92. void main() {
  93. stack s;
  94. queue q;
  95. int option = 1;
  96.  
  97. initStack(s);
  98. initQ(q);
  99.  
  100. while (option != 6) {
  101. option = askOption();
  102. system("cls");
  103.  
  104. switch (option) {
  105. case 1: testPush(s); break;
  106. case 2: testPop(s); break;
  107. case 3: testEnQ(q); break;
  108. case 4: testDeQ(q); break;
  109. case 5: printStack(s); printQ(q); break;
  110. case 6: cout << "Exiting test program\n"; break;
  111. default: cout << "Invalid option!\n";
  112. }
  113. system("pause");
  114. system("cls");
  115.  
  116. }
  117. } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement