CS 165 - Programming Assignment #3

Abstract Data Types


The Assignment:
Build a Simple ADT for Sets of Integers (IntSet)
.
Purpose:
Ensure that you can implement and use an Abstract Data Type
Before Starting:
Re-read your instructor's notes on data abstraction.
Know how to compile and run C++ projects on your system.
Due Date:
Monday, July 24, 2000

Discussion of the Assignment

Design and implement a simple ADT called IntSet for sets of integers.  Each object of class IntSet can hold zero or more integers in the range 0 through 100. A set should be represented internally as an array of ones and zeros. Array element a[i] is 1 if integer i is in the set. Array element a[j] is 0 if integer j is not in the set. The default constructor should initialize a set to an empty set, i.e., a set whose array representation contains all zeros.

The ADT should support the following set of operations:

The class must be organized as two files, a header file, intset.h, containing the class definition and an implementation file, intset.cpp, containing the code for the functions of the class.  Order of values in a set is unimportant but the set should not contain duplicates.
 

Implementation hints

The following is a suggestion of how your intset.h could possibly look like.
#ifndef INTSET_H
#define INTSET_H

class IntSet {
public:
   IntSet() { emptySet(); } // default constructor
   IntSet( int ); // alternate (overloaded) constructor
   IntSet setUnion( const IntSet& ); 
   IntSet setIntersection( const IntSet& );
   bool isEmpty( void );
   int size( void );
   IntSet relativeComplement( const IntSet& ); 
   IntSet symmetricDifference( const IntSet& );
   void setPrint( void ) const;
   bool isEqualTo( const IntSet& ) const;
   // Auxiliary functions <- NOT necessary (see "Notes, comments, suggestions" below)
   void emptySet( void );
   void inputSet( void );
   void insertElement( int );
   void deleteElement( int );
private:
   int set[ 101 ];  // range of 0 - 100
   // Private member functions, if necessary
};
#endif


Testing your solution

Run the test program, settest1.cpp, to test your class. Make sure that all results are correct before submitting your solution. Feel free to write your own test programs to ensure your solution is OK.

Submitting your solution

For this specific assignment, you must enclose the following deliverables in a 9x12 manila envelope:
  1. Turn in a printed copy of your source code files, intset.h and intset.cc.
  2. Turn in a printed record of the execution of settest.cpp
  3. Submit the files intset.h and intset.cpp on a 3.5" floppy disk.


If you have improved the class implementation (bonus points), you should also submit the test driver program (driver.cpp, containing a main() function) that shows these improvements at work and a results.txt file containing the corresponding results.

If you haven't improved the design nor written another driver program, there is no need to submit my driver and results.

Don't forget to write your name in all the files you submit!!


Notes, comments, suggestions


Bonus items

There are several possible improvements to the proposed solution and I strongly reccomend you try some of them after you're sure the original solution works according to the specifications.

Here are some suggestions:

  1. Add another constructor that allows sets to be initialized with any number of elements (up to a reasonable limit).
  2. Find a better data structure to store the elements of each set. Remember the limitations of arrays and how much they impact the original solution.
  3. Overload meaningful operators so that set operations can be carried out using a simpler, more elegant syntax.
Each significant improvement on the original design might be rewarded with extra points, up to 15% of the assignment's grade. Needless to say, you will not earn any bonus points if your solution does not meet all the grading criteria for correctness, style, and design.

Other improvements (besides the three suggested) might also earn bonus points, subject to the same limitations stated previously (not more than 15%; no bonus points for solutions that are not 100% OK).

If you improve your solution in any way that you think might deserve bonus points, please make sure to report these improvements in your readme.txt file.


Back to CS 165 Home Page

Last updated: 17 July 2000 by Tim McGuire