Homework 4: UIntSet

Sets as Application of BitVector

Educational Objectives. After successfully completing this assignment, the student should be able to accomplish the following:

Operational Objectives: Define and implement the class UIntSet and deliver the code in two files uintset.h and uintset.cpp along with a makefile for the supplied test harness.

Deliverables: uintset.h, uintset.cpp, makefile

Background

See lecture notes Chapter 4. Classes Part 1, Chapter 5. Pointers, Chapter 6. Classes Part 2, and Chapter 8. BitVectors.

Procedural Requirements:

  1. Familiarize yourself with the BitVector code in your library: LIB/cpp/bitvect.h and LIB/cpp/bitvect.cpp. Both the API and implementation are discussed in the class notes.

  2. Design the class UIntSet. Note that this is a client of fsu::BitVector and therefore must use the BitVector API. You are not implementing BitVector and cannot access the protected areas in BitVector.

  3. Implement the class UIntSet with the class definition in file uintset.h and the class implementation in file uintset.cpp

  4. Thoroughly test class UIntSet, starting out with the supplied test harness in file hw4/test.cpp using command line compile

  5. Write a makefile that builds test.x with the "in lieu of makefile" include statement commented out or removed

  6. Test the executable again, and refine your work to withstand testing.

  7. Turn in uintset.h, uintset.cpp, and makefile using the hw4submit.sh submit script.

    Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit projects. If you do not receive the second confirmation with the contents of your project, there has been a malfunction.

Technical Requirements and Specifications

  1. The class should implement the following diagram:

    Class Name:
      UIntSet
    Services : 
      void        Insert   ( unsigned long n )        // inserts n into set
      void        Remove   ( unsigned long n )        // removes n from set
      void        Clear    ()                         // makes set empty
      bool        Member   ( unsigned long n ) const  // returns true iff n is in set
    
      bool        Empty    () const;   // true iff set is empty
      size_t      Size     () const;   // returns number of elements in set
      size_t      Range    () const;   // returns upper bound of range/universe [0,ub)
    
      UIntSet& operator =  (const UIntSet& s);  // set = s (assignment operator)
      UIntSet& operator += (const UIntSet& s);  // set = set union s
      UIntSet& operator *= (const UIntSet& s);  // set = set intersection s
      UIntSet& operator -= (const UIntSet& s);  // set = set difference s
    
    Developer Services : 
      void        Dump     ( std::ostream& os ) const;
      // used in development & testing; displays underlying bitvector state
    
    Properties : 
      Constructable: objects can be declared as ordinary variables, max size may be specified
      Assignable:    objects can be assigned one to another
      Passable:      objects can be passed by value to and returned as values from functions  
    
    Private variables:
      fsu::BitVector bv_;    // bit vector representing set
    
    Global operators: 
      UIntSet operator +  (const UIntSet& s1, const UIntSet& s2);  // returns s1 union s2
      UIntSet operator *  (const UIntSet& s1, const UIntSet& s2);  // returns s1 intersection s2 
      UIntSet operator -  (const UIntSet& s1, const UIntSet& s2);  // returns s1 difference s2
      bool    operator == (const UIntSet& s1, const UIntSet& s2);  // true iff s1 and s2 are equal as sets   
      bool    operator != (const UIntSet& s1, const UIntSet& s2);  // true iff s1 and s2 are not equal
      std::ostream& operator << (std::ostream& os, const UIntSet& s); // output operator
    

  2. The class should be a proper type, to include default and 1-argument constructor, copy constructor, assignment operator, and destructor. The constructor argument sets the maximum size of unsigned integers that can belong to the set. Default maximum element size is 64.

  3. The output operator operator<< should be overloaded for the type UIntSet. Output should be "{ 0 6 12 18 }" for the set containing elements 0, 6, 12, 18.

  4. The Dump method is intended for use by the development and testing teams. Dump(os) should display the current state of the underlying BitVector object. The display would be

    10000010000010000010000000000000
    01234567890123456789012345678901
    

    for the set { 0 6 12 18 }.

  5. Global binary operators operator+, operator*, operator- should be overloaded for the type UIntSet. The syntax and semantics of these operators are as follows:

    UIntSet(200) s1, s2, s3; // three empty sets with range [0,1,2,...,200)
    s2.Insert(2); s2.Insert(3); s2.Insert(4);
    s3.Insert(2); s3.Insert(4); s3.Insert(6);
    std::cout << s2;  // prints { 2 3 4 }
    s1 = s2 + s3; // s1 is the set union of s2 and s3
    std::cout << s1;  // prints { 2 3 4 6 }
    s1 = s2 * s3; // s1 is the set intersection of s2 and s3
    std::cout << s1;  // prints { 2 4 }
    s1 = s2 - s3; // s1 is the set difference of s2 and s3
    std::cout << s1;  // prints { 3 }
    

  6. UIntSet should pass testing with the supplied hw4/test.cpp with no compile or runtime errors and no compiler warnings when the warning flags -Wall, -Wextra are set.

  7. Building and running the supplied hw4/test.cpp should result in output identical to the supplied executable area51/settest_?.x [? = i or s] .

Hints