Project 3: 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, log.txt

Assessment Rubric

build:
    settest.x                             [0..9]:   x
    fuintset.x                            [0..9]:   x
test:
    fuintset.x union.com                  [0..4]:   x
    fuintset.x intersection.com           [0..4]:   x
    fuintset.x difference.com             [0..4]:   x
    settest.x                             [0..8]:   x
code:
    constructor                           [0..2]:   x 
    copy constructor                      [0..2]:   x  
    destructor                            [0..2]:   x 
    assignment operator                   [0..2]:   x
engineering etc:  
   requirements                         [-20..2]:   x  # note negative points awarded during assessment
   coding standard                      [-20..2]:   x  # note negative points awarded during assessment
dated submission deduction           [2 pts per]: ( x) # note negative points awarded during assessment
                                                   --
total                                    [0..50]:  xx

Background

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

Procedural Requirements:

  1. Copy all of the files in LIB/proj3 into your cop3330/proj3 directory. You should see these files:

    fbitvect.cpp    # demo/test harness for fsu::BitVector
    fuintset.cpp    # demo/test harness for UintSet
    test.cpp        # test for UIntSet
    makefile        # builds project
    bv.com1         # com file for fbitvect.x
    ui.com1         # com file for fuintset.x
    ui.com2         # com file for fuintset.x
    ui.com3         # com file for fuintset.x
    deliverables.sh # submission configuration file
    

    This file should document all work done by date and time, including all testing and test results.

  2. Begin a log file named log.txt. This should be an ascii text file in cop3330/proj3 with the following header:

    log.txt # log file for UIntSet project
    <date file created>
    <your name>
    <your CS username>
    

    This file should document all work done by date and time, including all testing and test results.

  3. 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.

  4. 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.

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

  6. Thoroughly test class UIntSet:

    1. Debug your code with first with the command "make uintset.o" and then "make tests".
    2. Starting testing by running test.x and comparing the results with those of LIB/area51/settest_i.x.
    3. Once "passing" test1, devise further tests by supplying command files fo fuintset.x. Again, you can compare results with those of LIB/area51/fuintset_i.x. (Some example command files are supplied.)
    4. Turn in uintset.h, uintset.cpp, and log.txt using LIB/scripts/submit.sh and LIB/proj3/deliverables.sh, following the usual procedure.

      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 proj3/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 proj3/test.cpp should result in output identical to the supplied executable area51/settest_?.x [? = i or s] .

    Hints