/****************************************************** ** Name: ** Filename: IntegerSetDrv.cpp ** Project #: Deitel & Deitel 7.10 ** Project Description: Create a class called IntegerSet. Each object of class IntegerSet can hold integers in the range 0 through 100. A set is represented internally as an array of ones and zeros. Array element a[i] is 1 if integer i is in the set. Array element a[j] is 0 if integer j is not in the set. The default constructor initializes a set to the so-called "empty set," i.e., a set whose array representation contains all zeros. Provide member functions for the common set operations. For example, provide a unionOfIntegerSets member function that creates a third set which is the set-theoretic union of two existing sets(i.e., an element of the third set's array is set to 1 if that element is 1 in either or both of the existing sets, and an element of the third set's array is set to 0 if that element is 0 in each of the existing sets). Provide and intersectionOfIntegerSets member function that creates a third set which is the set-theoretic intersection of two existing sets(i.e., an element of the third set's array is set to 0 if that element is 0 in either or both of the existing sets, and an element of the third set's array is set to 1 if that element is 1 in each of the existing sets). Provide an insertElement member function that inserts a new integer k into a set (by setting a[k] to 1). Provide a deleteElement member function that deletes integer m (by setting a[m] to 0). Provide a setPrint member function that prints a set as a list of numbers separated by spaces. Print only those elements that are present in the set (i.e., their position in the array has a value of 1). Print --- for an empty set. Provide an isEqualTo member function that determines if two sets are equal. Provide an additional constructor to take five integer arguments which can be used to intialize a set object. If you want to provide fewer than five elements in the set, use the default arguments of -1 for the others. Now write a driver program to test your IntegerSet class. Instantiate several IntegerSet objects. Test that all your member functions work properly. ** Output: Print Contents Of All Four Sets Print An InEquality of Sets b & c Print A Union Of Sets a & b Print An Intersection Of Sets a & b Print The Assignment Of Set d = b Print The Equality Of Sets d & b Print Set c Print The Deleted Set c ** Input: None ** Algorithm: Make Default Constructor:IntegerSet() Make Alternate Constructor: IntegerSet(int, int = -1, int = -1, int = -1, int = -1) Make 3 Sets using Default Constructor Make 1 Set using Alternate Constructor Intialize One Set Using Multiple of 3 Intialize One Set Using Multiple of 5 Show All 4 Sets Perform InEquality Of Sets Perform Union Of Sets Perform Intersection Of Sets Perform Assignment Of Set Perform Equality Of Sets Perform Delete Of Set End Program ******************************************************/ // Include files #include // Used For cin, cout #include #include "IntegerSet.h" using namespace std; // Global Type Declarations // Function Prototypes void instruct (void); void pause (); //Global Variables - should not be used without good reason. int main () { // Declaration section IntegerSet a, b, c, d(2, 4, 6); int i; // Executable section instruct (); //Multiple Of 3 i=0; while ( i <= 100 ){ b.insertElement(i); i+= 3; } //Multiple Of 5 i=0; while ( i <= 100 ){ c.insertElement(i); i+= 5; } //Comment Of All 4 Sets cout << "\n"; a.setPrint(); cout << "\n\n"; b.setPrint(); cout << "\n\n\n"; c.setPrint(); cout << "\n\n\n"; d.setPrint(); //Inequality Of Sets cout << " \n\nb.isEqualTo(c): "; if ( b.isEqualTo(c) ) cout << "True\n"; else cout << "False\n"; pause (); //Union Of Sets a = b.unionOfIntegerSets(c); cout << "\na = b.unionOfIntegerSets(c)\n"; a.setPrint(); //Intersection Of Sets a = b.intersectionOfIntegerSets(c); cout << "\n\na = b.intersectionOfIntegerSets(c)\n"; a.setPrint(); pause (); //Assignment Of Sets d = b; cout << "\n\nd = b:\n"; d.setPrint(); pause (); //Equality Of Sets cout << "\n\nd.isEqualTo(b): "; if ( d.isEqualTo(b) ) cout << "True\n"; else cout << "False\n"; //Delete Elements cout << "\n\n"; c.setPrint(); cout << "\n\nc.deleteElement()\n"; i = 0; while( i <= 100 ){ c.deleteElement(i); i += 5; } c.setPrint(); pause (); return 0; } void instruct (void) { // Declaration section cout << "This program will perform a test of the IntegerSet" << " class.\n" << "____________________________________________________" << "_______\n" << endl; pause(); // Executable section } void pause () { // Declaration section // Executable section cout << "\nPress any key to continue..."; getch(); cout << "\r"; cout << " "; cout << "\r"; } /* Program Output This program will perform a test of the IntegerSet class. ___________________________________________________________ --- 0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 2 4 6 b.isEqualTo(c): False a = b.unionOfIntegerSets(c) 0 3 5 6 9 10 12 15 18 20 21 24 25 27 30 33 35 36 39 40 42 45 48 50 51 54 55 57 60 63 65 66 69 70 72 75 78 80 81 84 85 87 90 93 95 96 99 100 a = b.intersectionOfIntegerSets(c) 0 15 30 45 60 75 90 d = b: 0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 d.isEqualTo(b): True 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 c.deleteElement() --- Press any key to continue... */