Project 3: Set manipulation
software
Due: 17 Oct 2003
Educational objectives: Experience implementing:
generic containers using templates, dynamic data structures using pointers, and
some set operations. Experience developing software that uses data structures
studied in class, and working in groups.
Statement of work: Implement a generic linked list.
Modify code for the hash table and vector classes that we have discussed in
class, if necessary. Use these data structures to develop a software package that
manipulates sets, as described below.
Group work: You will work in groups of around three
students each on this project.
Deliverables: Turn in a makefile and all
header (*.h) and cpp (*.cpp) files that are needed to build your software,
using the project3submit.sh script. Turn in hardcopies of your development log
in class Monday, 20 Oct. In addition, you will need to submit the following
documents: (i) a project design, in which you specify the public interfaces to
each of your classes, pseudocode for your software that manipulates sets, and a
work plan which mentions who will implement each feature, and when you expect
to complete each feature. This should be submitted in class Oct 6 th. (ii) A
progress report, which will be a one-page report in which you mention the
features that you have already implemented, which is due in class Oct 13.
Requirements:
- Create
a subdirectory called proj3.
- You
will need to have a makefile in this directory. In addition, all the
header and cpp files needed to build your software must be present here.
You may copy any file from the class code distribution and modify them.
- You
should implement a generic linked list class as discussed in class.
- You
should implement a generic set class with limited functionality, which
will use either a linked list or a vector to represent a set. You need to
only implement features that will be useful for the software you will
develop in this assignment. The important point to note about a set is
that while vectors and linked lists can contain duplicate copies of an
element, a set contains only one copy of an element. So if a user of the
set tries inserts an element, you should ensure that a duplicate copy is
not created.
- You
will develop a software that uses the classes mentioned above. The
software keeps track of sets of records. Each record consists of two
fields: (i) key, and (ii) data, each of which is a string
which may contain whitespace, but will not include a comma, newline, or
')'. Each set has a name associated with it, which is an alphanumeric
string (and contains no whitespace). The user is provided the ability to
(i) create a new set, which is initialized to the empty set, (ii) remove a
set, (iii) add a record to a set, (iv) delete a record from a set, (iv)
check if an record with a given key is present in a set, (v) display a
record, (vi) display all records, (vii) assign a set to be the union,
intersection, or difference of two sets, and (viii) quit the software. All
user input can be considered to be syntactically correct.
- The
software is run by the user typing one of the following on the command
line:
- sets
vector
- sets
linked list
- The
former causes a vector implementation of sets to be used, while the latter
causes a linked list implementation of sets to be used.
- The
software then repeats the following:
- It
presents a prompt of the following form: Sets>>
- It
accepts a command typed by the user (which is terminated by a newline).
Any leading whitespace (before the command) is ignored.
- It
performs an operation, as desired by the user's command. This operation
may include an output. All output should be on a new line, and should
terminate with a single newline character.
- The
complete set of commands accepted by your program are as follows.
- new
set <name>
- where
<name> is the name of a new set that is to be created. You
should store this in a hash table, where the hash value is based on the
name of the set. The corresponding bucket should contain a pointer to
the actual set. If a set with that name already exists, then you should
output the following: A set named <name> already exists. Set
not created.
- remove
set <name>
- where
<name> is the name of a set. If a set with that name
exists, then it should be deleted and the hash bucket cleared. Please be
sure to de-allocate all memory associated with this set. If a set with
that name does not exist, then you should output: No set named
<name> exists.
- quit
- This
causes the program to terminate after de-allocating all memory that was
allocated.
- add
(<key>, <data>) to <name>
- where
<key> and <data> define a record, and <name> is the
name of a set. You should add a record corresponding to the
(<key>, <data>) pair to the named set, if a record for this
key does not already exist. If a record for this key already exists,
then you should replace its current data with the new data provided. If
a set with that name does not exist, then you should output: No set
named <name> exists.
- delete
<key> from <name>
- Delete
the record associated with the key <key> from a set named
<name>. If a record with key <key> does not exit, then you
do nothing. If a set with named <name> does not exist, then you
should output: No set named <name> exists.
- is
<key> in <name>?
- Output
Yes if <key> is in a set named <name>. Otherwise
output No. If a set with that name does not exist, then you
should output: No set named <name> exists.
- lookup
<key> in <name>
- Output
the data associated with <key> in the set named <name>. The
output should start with a tab. If a set with that name does not exist,
then you should output: No set named <name> exists.
- display
<name>
- Display
each record in the set named <name> in the following form: Each
record should be output on a separate line, starting with a tab,
followed by (<key>,<data>), where <key> is the key and
<data> is the corresponding data. If a set with named <name>
does not exist, then you should output: No set named <name>
exists.
- union
<name1> <name2> into <name3>
- <name3>
becomes <name1> union <name2>, where <name1>,
<name2>, and <name3> are names of existing sets (that is,
you can assume that the user will input only names of existing sets).
- Note:
In Union and Intersection, when records with common keys are encountered
in <name1> and <name2>, the data present in <name1> is
used in the set <name3>.
- intersection
<name1> <name2> into <name3>
- <name3>
becomes <name1> intersection <name2>, where <name1>,
<name2>, and <name3> are names of existing sets.
- difference
<name1> <name2> into <name3>
- <name3>
becomes <name1> - <name2>, where <name1>,
<name2>, and <name3> are names of existing sets.
Sample session
Unix prompt> sets vector
Sets>> remove set set1
No set named set1 exists.
Sets>> new set set1
Sets>> add (Toyota,
Corrolla) to set1
Sets>> add (Ford,
Explorer) to set1
Sets>> new set set2
Sets>> add (Toyota,
Echo) to set2
Sets>> add (Toyota, Camry
Corrolla) to set1
Sets>> new set set3
Sets>> union set1 set2
into set3
Sets>> display set3
(Toyota, Camry Corrolla)
(Ford, Explorer)
Sets>> delete Toyota
from set3
Sets>> display set3
(Ford, Explorer)
Sets>> display set1
(Toyota, Camry Corrolla)
(Ford, Explorer)
Sets>> remove set SET1
No set named SET1 exists.
Sets>> remove set set1
Sets>> lookup Ford in
set3
Explorer
Sets>> is Ford in
set3?
Yes.
Sets>> is Explorer in
set3?
No.
Sets>> quit
Unix prompt>