-
Notifications
You must be signed in to change notification settings - Fork 0
/
stacktem.cpp
64 lines (62 loc) · 1.27 KB
/
stacktem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// stacktem.cpp -- testing the template stack class
#include <iostream>
#include <string>
#include <cctype>
#include "stacktp.h"
using std::cin;
using std::cout;
using std::endl;
int main()
{
Stack<std::string> st;
char ch;
std::string po;
cout << "Please enter A to add a purchase order. \n"
<< "P to process a PO, or Q to quit.\n";
int number = 0;
while (cin >> ch && std::toupper(ch) != 'Q') {
while (cin.get() != '\n') {
continue;
}
if (!std::isalpha(ch)) {
cout << '\a';
continue;
}
switch(ch)
{
case 'A':
case 'a': cout << "Enter a PO number to add: ";
cin >> po;
if (st.isfull()) {
cout << "stack alraedy full\n";
} else {
st.push(po);
number++;
}
cout << "Contents: "
for (int j = 0; j < number; j++) {
cout << st[j] << " ";
}
cout << endl;
break;
case 'P':
case 'p': if (st.isempty()) {
cout << "stack alraedy empty\n";
} else {
st.pop(po);
cout << "PO #" << po << " popped\n";
break;
}
cout << "Contents: "
for (int j = 0; j < number; j++) {
cout << st[j] << " ";
}
cout << endl;
break;
}
cout << "Please enter A to add a purchase order, \n"
<< "P to process a PO, or Q to quit.\n";
}
cout << "Bye\n";
return 0;
}