(Latest Revision: 02/11/2003)
The Strange Queue: Implementing a Data Structure
RATIONALE:
One aim of this exercise is to impress upon you that abstract data structures
need not be implemented in a way that conforms at all to preconceived notions.
Often programmers need to find new and creative ways to implement the data
structures they want to use.
This exercise is also a reasonable way to warm up your programming skills
while you are reviewing material in the text about program design, stacks, and
queues.
THE ASSIGNMENT:
Implement a queue of letters in an unusual way: using just a single unsigned
long int to contain the queue elements. In other words one integer
variable will be used as a queue that can store several letters.
WHY WOULD I EVER WANT TO DO THAT?:
Well, it's not really the point here to write a program for a real scenario.
However, situations do come up once in a while where a program is required to
employ a very large number of data structures. Suppose that some day you must
write a program that performs a very complex simulation. It could be that the
program would need thousands or millions of queues. In a situation like that
it might be a good design choice to implement many of the queues using as
little memory as possible. In that case, a queue that uses just one 32-bit
integer for storage might be just what you need.
WHAT I GIVE YOU:
I am giving you a main program called
driver.cpp
,
a header file called
QueueInt.h
,
a header file called
QueueException.h
,
and a form for a QueueInt.cpp file called
QueueInt.form.cpp
.
Make copies of those files and look them over carefully. By reading
QueueInt.h, you will learn the specifications for the queue operations that I
want you to implement. The file driver.cpp is just that: a driver program you
can use to test your implementation of the queue.
WHAT YOU GIVE ME:
After you understand QueueInt.h, make a copy of QueueInt.form.cpp and name it
QueueInt.cpp. Fill it in with your name, user name, and implementations of
all the functions in QueueInt.h. Look at pages 346-347 in your textbook for
an idea of the format you need to use. Keep in mind, however, that the
source code you must create will be radically different from the code you see
in the book.
Create a comprehensive test plan for making sure that all the functions you
have implemented work according to specifications. E-mail me a copy of the
completed QueueInt.cpp file plus a script showing that you used the driver to
run all your tests successfully. You may look at my directions on
how to make a script
.
You may also check out these sample scripts:
top-level run
,
level-two run
, and
level-three run
.
ADDITIONAL SPECIFICATIONS:
Before you do any assignment for me, you need to read the
programming assignment rules
.
This document contains my general rules regarding form, and style. The
document also describes my grading criteria. (Note: on this assignment you
are not required to write any function header comments -- I have provided you
with all of them.)
Together, the files QueueInt.h and QueueInt.cpp must implement a queue class.
You are not allowed to change anything in QueueInt.h or in driver.cpp. In
fact when I test your version of the QueueInt.cpp file, I will just compile it
together with my (original) copies of driver.cpp and QueueInt.h. Therefore,
you must write QueueInt.cpp so it works correctly in conjunction with the
original QueueInt.h and driver.cpp. You must implement the queue operations
exactly as they are specified in the header comments in QueueInt.h.
The queue class must use the private variable "data" defined in QueueInt.h for
storage of all queue elements. The variable "data" is a single unsigned long
int. The element set for the queue class must be the set of lower case
letters ('a' through 'z'). When your program is compiled on the Sun Ultra's
using the ng++ compiler, a member of your queue class must have a capacity of
at least six lower case letters. You can achieve this easily if you take
advantage of the fact that you only need 26 different "codes" for queue
elements.
COMPILER COMMAND:
You may use the command:
ng++ -o driver QueueInt.cpp driver.cpp
to compile this program. For this to work, the files QueueInt.h,
QueueException.h, QueueInt.cpp, and driver.cpp should all be in your current
working directory. Assuming there are no syntax errors, the command will create an executable program named
driver
in your current working directory.
HELP:
Figuring out the details of this implementation can be tricky.
Come to class to get helpful information.
WHAT TO TURN IN:
You will be sending me two e-mail messages. Please follow
these rules:
- Always send me e-mail as plain text in the main message body: never
send me attachments or specially formatted or encoded documents.
- I will tell you what subject line to use with each message, and I
need you to use exactly the subject lines I give you. (I get
hundreds of e-mail messages at a time and your subject line allows me
to sort messages.)
Send the following two items to me by e-mail before midnight on the due date:
- A copy of your QueueInt.cpp file. Use this subject line:
CS3100,prog1,QueueInt.cpp
- A copy of your script file. Use this subject line:
CS3100,prog1,script
Note that there are no spaces in the subject lines given. It is important
that you do not insert any spaces. My e-mail address is:
john@ishi.csustan.edu
.
DUE DATES:
For due dates, see
the class schedule.