CS 105 (C++)
Assignment 7: Centipede
In this assignment, you will implement a queue class template, to be
used in a simple centipede-style interactive display. In addition
to the use of a template, this project will require the implementation
of copy control as well as dynamic memory management.
To allow you to focus on this week's C++ topics rather than on the
complexities of data structures, this project is designed around a
queue which has a fixed size. From its
first creation and throughout its entire existence, the queue will
QUEUE_SIZE (specified below) elements.
You will use the existing file
a7_main.cpp (download here) to handle interaction and
display, and you will complete your
implementation entirely within the file
a7_main.cpp should not be modified; doing so
may cause your
code to work incorrectly during grading.
Your implementation must meet the following requirements:
Note: This assignment's
Queue.h must properly use preprocessor directives to
prevent multiple inclusion.
- Each method of class template
Queue must be defined
outside of the class declaration, but still within
(Because of the way templates are compiled, both the declaration and
the definition of the template must be in the same file.)
Queue.h must use a preprocessor directive to define
- Your Queue class template must include the following members
Type refers to the parameterized type of the
- A private pointer to
Type, which will point to a
dynamically allocated array of
Type which is used for the
queue's internal storage. (This will be the only private member
and the only data member.)
- A default constructor, which allocates the array with size
- A copy constructor.
- A destructor.
- An assignment operator.
- An access function called
pushAndPop, which takes
a reference to a new item of type
Type to be pushed onto
one end of the queue, and returns an item of type
that has been popped off the other end of the queue. (Note that
the queue size is not changed by this operation.)
- As an exercise in programming to specifications, the
class template should contain exactly the members
specified, and no others.
- As always, proper handling of dynamic memory will be extremely
important because of the potential for damaging and hard-to-find
bugs. (In this assignment, the memory management is simpler than
in previous assignments, but must still be completed with great care.)
a7_main.cpp file makes use of the
ncurses library for display, which requires the option
(that's the letter
l, not the number
g++ during compilation, as shown here:
g++ a7_main.cpp -lncurses -o a7
The following is a list of specific assignment requirements, along
with the grade value for each (out of a total of 10 points for the
- Proper Function
Queue functions properly as used by
- Required Elements
(5 points: -1 for each missing element)
- Preprocessor directives used to prevent multiple inclusion
Queue member functions defined outside of the
class declaration, but within Queue.h, as described in Section I.
QUEUE_SIZE defined as described in Section I.
- Each member of Queue must be implemented as described in
- No members beyond those specified in Section I can be included.
- Absolute Dealbreakers
If any of these requirements are not met, you will lose all points
Proper Function portion of your grade.
- Your work must be submitted in the file
- This file (when combined with the given
must compile on a department UNIX machine with the
g++ a7_main.cpp -lncurses -o a7
- Provisional Dealbreakers
- Due to the importance of proper handling of dynamic memory, you
will lose all points from the Proper Function portion of your grade if
a valgrind evaluation of your work shows any memory leaks or errors other than memory which is "still reachable".
(Due to this assignment's implementation, there will be some memory
listed as "still reachable" in valgrind's leak summary output.
This is completely acceptable, and will not affect your grade.)
- Note: In recognition
of the difficulty of this task, you may resubmit your work at any time
before the end of the course for regrading on this portion of your
- Valgrind evaluation is performed as follows:
- Prepare your executable for valgrind by compiling with
debugging information on and optimization off. Use the following
command for this (Note that "
O0" is a capital letter "o"
followed by the number zero.):
g++ -g -O0 a7_main.cpp -lncurses -o a7
- Run valgrind by prepending the following to your normal
command (including all normal arguments):
- On-Time Submission
For full on-time submission credit, your
code must be submitted using
turnin by the due date and time,
using the following command on a department UNIX machine:
turnin --submit dlessin a7 Queue.h
- Late Submission
Late work can be submitted by email any time before the end of the
course, but the following score multipliers will be applied to the
- 1 day late: 90%
- 2 days late: 80%
- 3 days late: 70%
- 4 days late: 60%
- 5 or more days late: 50%
This work is licensed under a Creative
Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.