-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStackDr.cpp
More file actions
84 lines (68 loc) · 2.29 KB
/
StackDr.cpp
File metadata and controls
84 lines (68 loc) · 2.29 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Test driver
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <cstring>
#include "Stack.h"
using namespace std;
int main() {
ifstream inFile; // file containing operations
ofstream outFile; // file containing output
string inFileName; // input file external name
string outFileName; // output file external name
string outputLabel;
string command; // operation to be executed
char item;
Stack<char> stack;
int numCommands;
// Prompt for file names, read file names, and prepare files
cout << "Enter name of input command file; press return." << endl;
cin >> inFileName;
inFile.open(inFileName.c_str());
cout << "Enter name of output file; press return." << endl;
cin >> outFileName;
outFile.open(outFileName.c_str());
cout << "Enter name of test run; press return." << endl;
cin >> outputLabel;
outFile << outputLabel << endl;
inFile >> command;
numCommands = 0;
while (command != "Quit") {
try {
if (command == "Push") {
inFile >> item;
stack.Push(item);
} else if (command == "Pop")
stack.Pop();
else if (command == "Top") {
item = stack.Top();
outFile << "Top element is " << item << endl;
} else if (command == "IsEmpty")
if (stack.IsEmpty())
outFile << "Stack is empty." << endl;
else
outFile << "Stack is not empty." << endl;
else if (command == "IsFull")
if (stack.IsFull())
outFile << "Stack is full." << endl;
else outFile << "Stack is not full." << endl;
else
outFile << command << " not found" << endl;
}
catch (FullStack error) {
outFile << "FullStack exception thrown." << endl;
}
catch (EmptyStack) {
outFile << "EmptyStack exception thrown." << endl;
}
numCommands++;
cout << " Command number " << numCommands << " completed."
<< endl;
inFile >> command;
};
cout << "Testing completed." << endl;
inFile.close();
outFile.close();
return 0;
}