Using the Stack ADT and Writing an Array-based Implementation
We want to
better understand the stack ADT, via an array-based implementation, and
how to use it.
An implementation of the stack ADT with arrays is here (StackA.h, StackA.cpp), fill in the code to
implement the functions and compile it using the -c flag.
Write a simple driver program to test your stack. (Description
below.)
THE DRIVER:
Write a simple driver program that processes arbitrary lists of
commands to perform operations on a stack.
The driver must:
create a stack variable, and
fetch, echo, interpret, execute, and tell the results of each command
in the input,
If we take a closer look at the job of the driver, we see it must
execute a "command loop." In each pass through the loop, the program
reads a one-line command from standard input, interprets the meaning of
the command, echos the command to the standard output, executes the
actions required by the command, and tells the results of the command.
(The print command mostly just prints and does little additional
"telling.")
The command loop must be written so that when it receives the stop
command it prints a goodbye message and then exits.
Note that when you print the contents of the stack this has the effect
of clearing the stack.
The driver reads all input from standard input, and writes all all
output to standard output. An example of some of the input:
empty
push 25
push 3
push 9
get top
pop
get top
print
empty
For which the output might be:
#######################################################
empty
The stack is empty.
#######################################################
push 25
25 has been added to the stack.
#######################################################
push 3
3 has been added to the stack.
#######################################################
push 9
9 has been added to the stack.
#######################################################
get top
The top of the stack is 9.
#######################################################
pop
The top item has been removed from the stack.
#######################################################
get top
The top of the stack is 3.
#######################################################
print
The stack contains ...
3
25
#######################################################
empty
The stack is empty.
#######################################################
Good-by!
Note: This is not intended to be a comprehensive example but merely to
give you an idea of how the driver program should function.
Turn in your programs
and script to the CS Homework Submission System at https://hopper.csustan.edu/cshomework/
Choose instructor: cs2500mm
Choose course: CS2500
Choose assignment: Lab7