CS12, Extra Credit Program
Assigned: February 22nd, 2002
Due: Monday, March 18thth, 2002, 8am
This is an extra credit program. Depending on the work you put into it, it could be worth up to half a letter grade. Exceptional programs may earn more. This is your opportunity to make up points lost on earlier assignments or on the tests.
Topics
Most everything we covered
this quarter
A set is a collection in
which no element is repeated.
For example, {5, 2, 8} is a
set, but {5, 2, 8, 2, 1} is not, because the number 2 is repeated.
Elements do not have to be
numbers. For example
{“hello”, “world”} is a set of strings. The order of elements does not matter
in a set. A set may be empty.
Operations on a set include,
among others, checking if a number is an element of the set, adding an element
to a set (if it is not already in
it), combining two sets (union), and finding the common elements of two sets
(intersection).
In this assignment, you will
write a class that implements a set of strings.
Consider using the following
implementation (this is a recommendation, but not a requirement. Other implementations are possible;
creative thinking is encouraged). Store
the set elements in an array. If the set contains n elements, they reside in the first n spaces of the array. A private variable keeps track
of the number of elements in the set. New elements are added to the next cell
in the array. An element is not added if it is already in the set.
In this implementation, it is
possible for the set to be full (when all array cells contain set elements).
All attempts to add elements to the set should verify that there is room in the
set.
Since you are implementing a
set of strings, the array will be an array of pointers to char. You may use the string methods in string.h if you
need them. Please do not use string objects.
·
Download the header file
set.h.
· Create an implementation file set.cc. Write the implementation code for as many of the methods and functions in set.h as you wish. The more you implement, the more credit you will receive. Comment out in set.h the methods that you choose not to implement.
·
Wherever possible, use
other methods of the class in your code to avoid duplicating code. The methods
isElement() and isFull() are particularly useful in avoiding rewriting loops
everywhere.
·
If you feel so inclined,
add other methods that you think will enhance the class. Be sure to document
them if you wish to receive credit.
· As you write your implementation code, test the use of your class with a main() which will be in a file called main.cc. Add to this main rather than replacing code. Your main() is the one that will be used to test the program. If a method is not called from main(), it is as if it was not written.
·
The files set.h, set.cc
and main.cc.
·
A makefile that will
compile set.cc and main.cc when the user types “make set”
This is an extra credit
program. Extra credit is earned,
not deserved. Grading is relative,
not absolute. This means that the
people who do more will get more.
As you get ready to turn in
your program, please keep in mind the following points:
Yes, this is harsh. And it would be a shame if you put in a
lot of work and end up with no credit.
With this in mind, you would do good to follow these suggestions:
1.
Put your name in the
program files before you start coding.
2.
Document as you go along
3.
Whenever you complete a
method, test it.
4.
Take an incremental
approach to turnin. When you have
something, anything, however trivial, that compiles and runs – turn it
in.