This repository was archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.cpp
More file actions
150 lines (122 loc) · 4.87 KB
/
Copy pathdriver.cpp
File metadata and controls
150 lines (122 loc) · 4.87 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*----------------------------------------------------------------------------+
| Author: Jerome Richards |
| |
| Assignment: Project 7 |
| File: driver.cpp |
| |
| Instructor: Dr. Roger deBry |
| Class: CNS-1350 Section X01 |
| |
| Date Written: February 27, 2005 |
| |
| Description: |
| |
| Test the use of the CStack with Exceptions |
+----------------------------------------------------------------------------*/
#include <iostream>
#include <iomanip>
#include <cassert>
#include <time.h>
#include <memory>
#include <exception>
#include "stack.h"
#include "stackrep.h"
using namespace std;
const int TRUE = 1;
const int FALSE = 0;
void dispPrologue();
/*----------------------------------------------------------------------------+
| Purpose: Test the CStack class |
| |
| Parameters: argc an int representing the number of parameters |
| |
| argv an array of character parameters |
| |
| Returns: 0 representing successful execution |
| |
| Pre-conditions: none |
| Post-conditions: none |
+----------------------------------------------------------------------------*/
int main( int argc, char* argv[] )
{
CStack* theStack = NULL;
dispPrologue();
cout << "Creating the stack with no parameters (default size is 5)\n\n";
theStack = new CStack;
assert( theStack != NULL );
cout << " The current stack size is: " << theStack->stackSize() << "\n";
cout << " The amount of free space is: " << theStack->freeSpace() << "\n\n";
cin.exceptions( ios_base::failbit | ios_base::badbit );
int tmpInt = -1;
while( tmpInt != 0 )
{
cout << "Enter an integer value (zero to stop): ";
try
{
cin >> tmpInt;
if( tmpInt != 0 )
theStack->push( tmpInt );
}
catch( ios_base::failure & e )
{
cout << "\nPlease enter an integer." << "\n";
cin.clear();
cin.ignore( 1000, '\n' );
}
}
cout << "\n\nRemoving data from the stack...\n";
bool lExit = FALSE;
while( ! lExit )
{
try
{
cout << theStack->top() << "\n";
}
catch (CEmptyStackException& err )
{
cout << "\n" << err.what();
}
try
{
theStack->pop();
}
catch (CEmptyStackException& err )
{
cout << "\n" << err.what();
lExit = TRUE;
}
}
cout << "\n\nAttempting to move past top of stack...\n";
try
{
theStack->pop();
}
catch (CEmptyStackException& err )
{
cout << "\n" << err.what() << "\n\n";
}
assert( theStack != NULL );
delete theStack;
theStack = NULL;
cout << "Program terminated normally. ";
system( "pause" );
return 0;
}
/*----------------------------------------------------------------------------+
| Purpose: Display file prologue |
| Parameters: none |
| Returns: nothing |
| |
| Pre-conditions: none |
| Post-conditions: none |
+----------------------------------------------------------------------------*/
void dispPrologue()
{
system( "cls" );
cout << " Name: Jerome Richards\n";
cout << " Course: CNS-1350 Section X01\n";
cout << "Instructor: Dr. Roger deBry\n";
cout << " Program: Project Seven\n";
cout << " File: Stack Exceptions (stack.exe)\n";
cout << "\n\n";
}