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

CS19 Fall 2017

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.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.) If you don't remember the basics of sets and set operations, you may find the set entry at Wikipedia helpful. The required member functions are described below.

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 limit of values allowed in the set. The minimum set upper limit is zero, so treat a parameter less than zero as zero.

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 an out of range element, print a one line warning that includes the legal range of elements for that set and the value that was attempted and take no other action.

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 assignment operator ( member function operator= ) will replace the destination's set (and limit) with a copy of the source set. Make sure to handle memory properly (as you should with every function where applicable) and this includes checking for self-assignment.

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 intersectionWith and unionWith. Both should take one integer set as their parameter and perform the requested operation by modifying the contents of a returned object. If the two source sets have a different upper limit, the result should have the larger limit.

// s1 becomes the union of s2 and s3
// s2 and s3 are unmodified
s1 = s2.unionWith(s3);

See starter file (intset-start.cpp) for the required class definition and main function.

Sample Output

CS 19 Integer Sets
Insert your name and email here
insertElement: 1086 out of range 0 - 1000.
is3 ("random"): {27, 335, 362, 383, 386, 421, 492, 649, 690, 777, 793, 886, 915}
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

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