copyright Steve J. Hodges

CS19 Spring 2019

Assignment 4 (Integer Sets)

Directory Name


Resulting Executable



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

Class Definition and Main


Program Description

Create a class, named IntSet, that implements a set that will store integer values in the range of 0 through 1000, inclusive. (We are using a static const for this upper bound, so that the value can be modified, and your program re-compiled, to work with an alternate value.) 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—do not modify them without consulting with me first.

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 (this is recomended), return it to the provided code before you submit your assignment. Note that when I test your IntegerSet class, I may use another test routine. Make sure that your IntegerSet class conforms exactly to the specification.

Your default constructor must allow between zero and five elements to be inserted into the set initally.

Your member functions insertElement and deleteElement should work by adding (or removing) the specified element to the set. If insertion or deletion is attempted on an element that is out of range, do nothing.

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}

The member function equals should have an integer set as its parameter and return type bool. It should determine if two sets have exactly the same members.

The member function hasElement should have return type bool and determine if the parameter is an element of the set. (Illegal element values should also return false.)

The intersection and union functions should be called intersectionOf and unionOf. Both should take two integer set as their parametes and perform the requested operation setting the contents of the set on which the function was invoked to be exactly the result.

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

The function getMax returns the largest value that could be in the set (not that largest value that is in the set.) I coded this function for you.

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

Sample run with the provided main

[steveh@pengo IntSet]$ ./p4 
CS19 Program #4 Integer Set Class
Insert your name and email here
is3 (random): {11, 12, 22, 27, 42, 43, 58, 59, 60, 67, 69, 84, 87, 91, 94, 123, 124, 135, 167, 170, 172, 178, 198, 211, 226, 229, 276, 281, 305, 313, 315, 324, 327, 335, 336, 362, 364, 367, 368, 370, 373, 383, 386, 393, 399, 403, 413, 421, 426, 429, 434, 456, 492, 505, 526, 530, 537, 539, 540, 545, 567, 582, 584, 586, 649, 651, 676, 690, 729, 736, 739, 750, 754, 763, 777, 782, 784, 788, 793, 802, 808, 814, 846, 857, 862, 873, 886, 895, 915, 919, 925, 926, 929, 932, 956, 980, 996}
is3 (union): {1, 2, 4, 5}
is3 (intersection): {2, 5}
is1: {2, 4, 5}
is1 contains 5
is1 does not contain 7
[steveh@pengo IntSet]$ 

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-4 inside your home directory on Pengo. This directory should not contain any files not part of your project, and it should not contain any subdirectories or binaries. I will collect all of the files from this directory.