CS 367 - Introduction to Data Structures - Section 3
Programming Assignment Zero: Bags
Due Thursday, Setember 18, 1997 by 2:30pm
Contents
Motivation
This assignment concerns the implementation of a few member functions of
the Bag abstract datatype discussed in class. The assignment is not meant
to be particularly difficult or time consuming. It is meant to:
- Familiarize yourself with the separation of specification from implementation
- Gain some experience using emacs, g++ , and make
- Apply what we learned in class about bags, preconditions, and
postconditions
- Acquaint (or reacquaint) yourself with certain features of C++ such
as:
- modification vs. constant member functions
- operator overloading
- friend functions
Requirements
You have three requirements for this assignment:
- Write isEmpty and isFull functions that match the specifications
given in bag.h. This should allow the test program to compile and avoid undesired
calls to grab and insert.
- Add checks to grab and insert to prevent an unwise user from getting
unpredictable results by neglecting to meet the preconditions.
- Implement the equality operator (==) for bags. We define two bags to
be equal if they have the same contents - each item present in one bag is
present in the same quantity in the other bag. This operator must meet the
specification given in bag.h. (It is currently incorrectly implemented to
automatically return false, just so that the program compiles upon
completion of part 1.) Make sure that you include comments describing how
the function works.
Grading
The program will be graded on an 100 point scale, weighted as follows:
- 25% for error-free program compilation
- 20% for correctly functioning isEmpty and isFull functions (part 1)
- 20% for correctly checking preconditions within grab and insert (part 2)
- 35% for correctly functioning == operator (part 3)
I cannot stress enough the importance of documentation - poorly
documented programs may be graded harshly. For more information on grading
policy, click
here.
Files
There are four files you will need to do the assignment, found in
~cs367-3/public/Assignments/Zero/Files:
-
bag.h - the header file with the Bag class specification
-
bag.C - the implementation of the Bag member functions
-
main.C - the main function for testing Bag
-
Makefile - the makefile for making compilation easier and
better organized. (For more info on make, click here.)
You can copy the files by viewing the documents in Netscape and then
using the Save As option from the File menu. Alternatively, you can simply
copy them to the directory of your choice. For example to copy them to the
directory ~foo/cs367 you can type:
cp ~cs367-3/public/Assignments/Zero/Files/* ~foo/cs367
The code provided is based on that in Main & Savitch, particularly
Section 3.1 and part of Section 5.3. You need only modify bag.C.
How to get started
- If you have absolutely no experience compiling or editing in Unix
then please read this
primer.
If you are still confused as to how to begin, contact the TA,
Marc Dreyfuss.
- Copy the files to a directory of your choosing (recommended: a
directory designated solely for this assignment).
- Try to compile the file by typing make.
- Modify the necessary files using an editor (recommended: emacs).
- Continue to compile by using make.
- When the compilation is successful, type baggage to run the demo
program. (Read the comments at the top of main.C for more on how the
baggage program works.)
- Use it to test whether you have met the requirements discussed
above.
Keep editing, compiling, and testing (the so-called edit-compile-debug
cycle) until you have met all the requirements. When finished, submit the file
electronically. Don't forget to add comments wherever necessary.
Submitting
What we need once you are done:
Copy your modifed version of the file bag.C to the directory
~cs367-3/Submissions/Zero/<login> where <login> is your login
name.
For example if your login name is foo, then from the directory where your
modified bag.C file is located, type:
cp bag.C ~cs367-3/Submissions/Zero/foo
This is a paperless assignment. You need only turn in the program
electronically.
Solution
A solution will be made available after we have "closed the door" to
accepting more assignments. (This should be the same time as the due date -
see the late policy below.) A compiled executable derived from the soliton
is available for you to try out. The solution executable is located in
~cs367-3/public/Solution/Zero and is called baggage.
The instructor's solution to Programming Assignment Zero is now on-line.
Late Policy
This is not a difficult assignment. Late assignments will not be
accepted. If you feel you truly have a justifiable excuse for turning in
the assignment late, you must clear it with me at least one day in
advance. (I do not plan on clearing any such requests.)