-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQueDr.cpp
More file actions
87 lines (70 loc) · 2.4 KB
/
QueDr.cpp
File metadata and controls
87 lines (70 loc) · 2.4 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
83
84
85
// Test driver
#include <iostream>
#include <fstream>
#include <string>
#include "Queue.h"
using namespace std;
int main() {
FullQueue error;
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;
Queue<char> queue(5);
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());
if(inFile.fail()) {
cerr << "File failed to open" << endl;
exit(1);
}
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") {
cout << "Processing: " << command << endl;
try {
if (command == "Enqueue") {
inFile >> item;
queue.Enqueue(item);
outFile << item << " is enqueued." << endl;
} else if (command == "Dequeue") {
item = queue.Dequeue();
outFile << item << " is dequeued. " << endl;
} else if (command == "IsEmpty")
if (queue.IsEmpty())
outFile << "Queue is empty." << endl;
else
outFile << "Queue is not empty." << endl;
else if (command == "IsFull")
if (queue.IsFull())
outFile << "Queue is full." << endl;
else outFile << "Queue is not full." << endl;
else
outFile << command << " not found" << endl;
}
catch (FullQueue) {
outFile << "FullQueue exception thrown." << endl;
}
catch (EmptyQueue) {
outFile << "EmtpyQueue exception thrown." << endl;
}
numCommands++;
cout << " Command number " << numCommands << " completed." << endl;
inFile >> command;
};
cout << "Testing completed." << endl;
inFile.close();
outFile.close();
return 0;
}