Question: 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. Design the
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.
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.
Implement the class UIntSet with the class definition in file uintset.h and the class implementation in file uintset.cpp
Thoroughly test class UIntSet:
Debug your code with first with the command "make uintset.o" and then "make tests".
Starting testing by running test.x and comparing the results with those of LIB/area51/settest_i.x.
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.)
Turn in uintset.h, uintset.cpp, and log.txt using LIB/scripts/submit.sh and LIB/proj3/deliverables.sh, following the usual procedure.
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
Note that BitVector has a Dump method.
Note that BitVector has a Size method that returns the number of bits.
The global set operators (+,*,-) can be implemented using the corresponding member operators, like this:
{ UIntSet s(s1); s x= s2; // x = +,*, or - return s; } The global operator (==) require a loop of element tests.
The global operator (!=) should be implemented with a call to ==.
The gobal operator << requires a loop of element tests.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
