copyright Steve J. Hodges   http://steveh.net/cs19/cs19-hw03.html

CS19 Spring 2018

Assignment 3 (Integer Sets)

Directory Name

19-3

executable Resulting from make (set in makefile)

p3

Files

IntSet.cpp, IntSet.h, main.cpp, Makefile

Class Definition and Main

intset-start-sp18.cpp


Program Description

Create a class, named IntSet, that implements a set that will store integer values in the range of 0 through some upper limit, inclusive. (Each object has an independent upperLimit member variable.)

You must use the code from the provided class definition and main function. Do not modify the provided code, except where indicated or to add comments, without consulting me and getting permission via email. Don't forget to add all the proper array and parameter checking. If you modify the main function or testing purposes while you are developing your program (doing additional testing is always recomended), return it to the provided code before you submit your assignment. Note that when I test your IntSet class, I may use another test routine. Make sure that your IntSet class conforms exactly to the specification.

Your default constructor accepts an optional initial value to set the upper (inclusive) limit of values allowed in the set. The minimum set upper limit is zero, so treat a parameter less than zero as zero in this function.

The copy constructor creates a new object that has the same set as the source object. (Use a deep copy, not a shallow copy!)

The destructor must clean up the array.

Your member functions insertElement and deleteElement should work by adding (or removing) the specified element to the set. If deletion is attempted on an element that is out of range, do nothing. If insertion is attempted on a value that is less than 0, print out a warning message. If insertion is attempted on a value that is larger than the upper limit, "resize" the array first so that you can safely add that element.

The toString member function should return a string containing standard set notation (comma seperated list inside curley braces)

example sets:
{1, 2, 4, 6, 34, 58}
{1}
{}

The test for equality operator ( member function operator== ) should have an integer set as its parameter and return type bool. It should determine if two sets have exactly the same members. Note that two sets with different upper limits may or may not be equal depending on their members.

The member function hasElement should have return type bool and determine if the parameter is an element of the set. Out of range elements will return return false.

The intersection and union functions are called intersectionOf and unionOf. Both should take two integer sets as their parameters and perform the requested operation by modifying the contents of the set on which the function was invoked. The prior contents of that set are not part of the result. If the two source sets have a different upper limit, the result should have the larger upper limit in the case of union and the smaller upper limit in the case of intersection.

I've coded some useful functions for you already. (including minOf, maxOf, and resize.)

// s1 becomes the union of s2 and s3
// s2 and s3 are unmodified
s1.unionOf(s2, s3);

See starter file for the required class definition and main function.

Sample Output

CS 19 Integer Sets
Insert your name and email here
is3 ("random"): {37, 57, 97, 157, 295, 385, 389, 516, 741, 754, 913, 964, 986, 1052, 1086}
is1: {2, 4, 5}
is2: {2}
is3 (union is1 is2): {2, 4, 5}
is3 (intersection is1 is2): {2}
is3 == is3
is1 != is2
is3 == is2
is1: {2, 5}
is3 != is1
is4: {1087}
is4: {2}
is1 contains 5
is1 does not contain 7

Try to insert -5

Warning: Discarded insert of -5, min value is 0.

What to turn in

For this assignment, you will be creating a project with several files. All of your project files, including your makefile, should be placed in a directory named 19-3 inside your home directory on Pengo. This directory should not contain any files not part of this assignment, and it should not contain any subdirectories. I will collect all of the files from this directory. Your makefile is required to have a "make clean" option that removes all files except for your source code and the makefile (so it should get rid of the program executable, the .o files and any emacs backup files, for example.)

Suggestions