(Latest Revision: Thu Apr 12 10:26:56 PDT 2001 ) quasiPalAsg

quasiPalAsg



(Latest Revision: 04/06/98)

//////////////////////////////////////////////////
CS 2500 PROGRAMMING ASSIGNMENT #04
Information Hiding, Stacks, and Queues
The Quasi-Palindrome Problem
//////////////////////////////////////////////////

Please read chapters 6 and 7 of your textbook (Carrano) for
help in understanding this assignment.

Also, you are expected to read the class documents entitled:

programAssignmentRules,
sampleProgramSubmission-level-01,
sampleProgramSubmission-level-02,
sampleProgramSubmission-level-03,
howToMakeTestScript
sampleTestScript-level-01
sampleTestScript-level-02, and
sampleTestScript-level-03

before beginning to do this or any programming assignment.  You
will find the documents under "CourseDocuments" in the class
gopher directory.

THE ASSIGNMENT

FINISHED PROGRAM DUE:  Apr 28, 1998
(You will not turn in any preliminary levels for this assignment)

Write a program that uses a stack and queue to test a list of
up to 50 words, to see if it is "quasi-palindromic".  A list of
words is quasi-palindromic if it remains the same list when
written in reverse order (without reversing the words
themselves.)

EXAMPLES OF QUASI-PALINDROMIC LISTS:

list 1:
TOM DICK HARRY HUEY DEWEY
LOUIE DEWEY HUEY HARRY DICK TOM

list 2:
A
STICKY WICKET
IN A THICKET THICKET
A        IN
WICKET
STICKY       A 

EXAMPLES OF NON QUASI-PALINDROMIC LISTS:

list 3:
THE RAIN    IN    SPAIN FALLS    MAINLY   
ON THE   GROUND

list 4:
TOM DICK Harry
HUEY DEWEY LOUIE
DEWEY huey HARRY DICK
TOM

IMPLEMENTATION OF THE STACK AND QUEUE

You will be writing a main program that uses a stack and a
queue.

The files StackA.h and StackA.cpp in this directory implement
an array-based stack class.  StackP.h and StackP.cpp implement a
pointer-based stack.  Similarly, QueueA.h and QueueA.cpp
implement an array-based queue, while QueueP.h and QueueP.cpp
implement a pointer-based queue.  

Your program is required to work correctly using either of the
stack implementations named above, and either of the queue
implementations.  

You will need to test your program using all of these
implementations of stacks and queues, in order to make sure
that it works.  To facilitate switching from one implementation
to another, you should have "dummy variable" file names for the
implementations currently being used.  For example, to use both
array-based implementations, one could just do the commands:

cp StackA.h Stack.h
cp StackA.cpp Stack.cpp
cp QueueA.h Queue.h
cp QueueA.cpp Queue.cpp
g++ myProg.cpp Queue.cpp Stack.cpp
a.out < testfile_01

You could even write some shell scripts to do all of these
commands at once.

Of course, in order for this to work, the myProg.cpp file has
to include Stack.h and Queue.h and *not* StackA.h, StackP.h,
QueueA.h, or QueueP.h.

For this exercise, it's OK to leave alone the include
statements in the files StackA.cpp, StackP.cpp, QueueA.cpp, and
QueueP.cpp.  Everything will work alright if the originals of
all the *.h files are left intact in the working directory,
retaining their original names.

The stack and queue classes in this directory are identical to
the examples from chapters 6 and 7, except that lines like:

#include <string>
const int MAX_STACK = 50;
typedef string stackItemType;

have been inserted/changed in the *.h files so that the items
designated to be stored in the stack or queue are strings, and
so that the array-based implementations have a capacity of 50
elements.

The two stack classes both offer the same operations, each with
exactly the same parameters.  The situation is the same with
the queues.  You need to familiarize yourself with the
operations, then write a program that uses them to test for
quasi-palindromes.

THE STRING DATA STRUCTURE

Your program will need to do some basic operations on strings.
Check pages A31-A32 in the appendix for a review of C++ strings.

ACTIONS OF THE PROGRAM

The program will rely on redirection to get access to the input
file, like this:

a.out < testfile_4

This means that you must write the program as though the input
were being typed at the keyboard.

The program must go through the input list, getting each word,
pushing it onto a stack, and also inserting it into a queue.

There will be no count or sentinel value to tell your program
which string is the last.  Therefore, you need to figure out
how to write a loop rigged to stop on an "end of file"
condition.  We can discuss that problem in class if you like.

After all the words in the list have been read, the program
must enter a loop, in which it pops a word from the stack,
deletes a word from the queue, and compares the two words.  The
words will come off the stack in reverse order, and off the
queue in forward order.  Therefore the input list is a
quasi-palindrome if and only if no unequal string pairs have
been detected when the stack and queue become empty.

Your program should echo the input, and output a simple
message, clearly saying whether the input list is a
quasi-palindrome.

The other details of how you implement this program are left to
you.  However, it should be done according to the rules of good
programming you have learned, and the items printed should be
formatted attractively and clearly.

=================================================================
WHAT TO TURN IN

Turn in a working version of the main program, plus test script
via e-mail before midnight, April 28.

Your test script must show good data coverage.  Run a
reasonably complete set of tests using one implementation of
the stack and queue.  Then switch implementations and do one or
two more tests.

Do *not* turn in any implementation code for stacks or queues.
I will compile your program together with my copies of the
stack and queue code in this directory.  If your program worked
for you, it should work for me.

=================================================================