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
See lecture notes Chapter 4. Classes Part 1, Chapter 5. Pointers, Chapter 6. Classes Part 2, and Chapter 8. BitVectors.
Design the class UIntSet
Implement the class UIntSet with the class definition in file uintset.h and the class implementation in file uintset.cpp
Thoroughly test class UIntSet, starting out with the supplied test harness in file hw4/test.cpp using command line compile
Write a makefile that builds test.x with the "in lieu of makefile" include statement commented out or removed
Test the executable again, and refine your work to withstand testing.
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.
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 |
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.
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.
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 }.
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 }
UIntSet should pass testing with the supplied hw4/test.cpp with no compile or runtime errors and no compiler warnings when the warning flags -W, -Wall, -Wextra are set.
Building and running the supplied hw4/test.cpp should result in output identical to the supplied executable area51/settest_?.x [? = i or s] .
Hints
{ UIntSet s(s1); s x= s2; // x = +,*, or - return s; }