Programming
Assignment #2
Data
Structures
Programming
Assignment Specifications:
Program #2 will focus our
attention on stacks, queues, and dynamic memory.
Your job on program #2 is to
implement a stack and a queue class. Keep these classes separate. Then either
via a main program or another class, implement the code that will test your
classes.
Write a simple application to
manage an adding machine program, where the stack is sued to push and pop
numbers and results. Your application should read in floating point numbers and
push them onto a stack and add them together whenever a plus sign is entered.
It should support operatons of: addition, subtraction, multiplication, and
division. When the = is requested from the user, the result should be displayed.
Design for a way for the user to cancel all entries (which will end up clearing
the stack).
Use your queue to manage the
input received. All data must be read a line at a time from standard-in, enqueue this data for future use.
The entire file must be read and stored in memory prior to processing. Then,
retrieve it from the queue – to determine what operations the user has
requested.
Data Structures
The stack and/or queue
abstractions must be implemented using linear linked lists of arrays.
All memory within the abstractions (nodes, arrays of characters, arrays of
integers) must be dynamically allocated (however, this doesn’t apply to
memory used for single characters). Every array in your linked lists must be
the same size.
Think of these abstractions as dynamic, which is why they are linked lists of arrays. It combines the advantages of an array with the
advantages of a linear linked list. What you do is create a linked list in
which each node contains N elements (where N should be reasonably small for
purposes of this assignment). For example, N might be 10. Each time you push,
you attempt to add the new element to the existing array node if there is space
available. Otherwise, you allocate a new node that can store another N (maybe
10) elements and link it to the existing list. When you pop, you perform the
reverse process. If a pop makes a node completely empty, you delete it. Now
your overhead is just a few extra bytes for each N elements. Consider passing
the size of the node in as an argument to the constructor.
Things you
should know...as part of your program:
1) VERY IMPORTANT Implement
a stack ADT to perform the push and pop operations as a class. Implement a
queue ADT to perform the enqueue and dequeue operations as a class. Do not try
to create an abstraction that is some mutation of a stack and queue -- instead
implement a stack and queue as separate classes.
2) Use modular design, separating the .h files from the .cpp files.
Remember, .h files should contain the class header and any necessary
prototypes. The .cpp files should contain function definitions. Never
"include" .cpp files!
3) Use the iostream.h library for all I/O; do not use stdio.h.
4) Make sure to define a constructor and destructor for your stack/queue
classes. Your destructor must deallocate all dynamically allocated
memory.
5) Each node and each array within the node must be
dynamically allocated to be of the appropriate size. Do not use
statically allocated arrays in your nodes!
6) Remember to pass by reference whenever possible.
On the due date, turn in:
1) A listing of your C++ program and the output. Your output should
show that you have thoroughly tested all boundary conditions of this
assignment.
2) Attach a cover page to these with a paper clip (do not
staple!). Turn in your design considerations with your program (it is worth 20%
of your grade). Also, don't forget to add comments and to work on your
program's readability; this is another 20%!
Instructions to email
Programs:
In the subject field of your
email indicate your last name, the assignment number, and the word "submission" (this way I will know that
the program is being turned in). When you mail the program, use the following
commands typed at the unix prompt. Do not use pine or attach your program.
Programs must be emailed using
the following syntax:
type: /bin/sh
type: shar prog2.c stack.c stack.h queue.c queue.h >prog2
next, type control-d
To email this archive, type the
following. The double quotes are essential!
mail -s
"Last Name - Prog #2 Submission" @cs.pdx.edu
<prog2
(teacher’s
email)