Integerse

xiaoxiao2021-03-06  122

Program 4: The Infamous Integerse

Create a class called IntegerSet. Each object of the class IntegerSet can hold integers in the range of 0 through 100. A set is represented internally as an array of bool's. Array element a [i] is true ( "turned-on") if Integer i is in the set. Array Element a [K] IS false ("turned-off") if INTEGER K is not in the set. The default constructor should Initialize the set to the so called "Empty Set" IE SO All the Elements Would Have An Initial Value of False. There Arements of The Set, But for this Homework Stick To The Array Of Booleans Implementation.

Provide the Member Functions for the Common Set Operations:

void IntegerSet :: unionOf (const IntegerSet & set1, const IntegerSet & set2): set the values ​​of an IntegerSet to the set-theoretic union of two existing sets (ie an element of the IntegerSet object which the function is called on would be "turned on "(= = true) if the point element in Either of the passed in parameter sets is" turn-on ", Otherwise the element would be set to false.

void IntegerSet :: intersectionOf (const IntegerSet & set1, const IntegerSet & set2): set the values ​​of an IntegerSet to the set-theoretic intersection of two existing sets (ie an element of the IntegerSet object which the function is called on would be "turned on "(= = true) If the Same Element is" on "in Both of the passed in parameter sets, Otherwise the element would be set to false).

Bool Integerse :: ISEqualto (Const Integerset & Set): Returns A Boolean Indicating WHether The Sets Are Equal.

void IntegerSet :: (int num) insertElement:. allows a new integer num to be inserted into the set If num is not within the valid range of numbers for the set, the set should remain unchangedvoid IntegerSet :: deleteElement (int num): Removes An Integer Num from The Set (IE IT "Turns-Off" That Element in the array). if Num is not in the set (or out of the range) the set shop unchange

BOOL Integerse :: Isinset (Int Num): Returns True IF Num Is Contained with ITHERWISE IT RETURns FALSE

Void IntegerseEt :: PrintSet: Print The IntegerseEt in The Following Fashion:

{} // Would Represent an Empty Set {2, 14, 52} // Would Represent The Set Containing 2, 14, 52. Yes, The Commas Are Required.

.

Provide a second constructor That Will Receive TWO arguments. The first arguement is an array of tent.................

Your main program is going to test the IntegerSet class. It will prompt the user for numbers to be included within the set and then create IntegerSets with the user input. For set1 use the default constructor, and for set2 use the constructor that recieves the array . After creating the two sets, it should display the two sets, whether the sets are equal to each other, and then the intersection and union of the two sets (to display the intersection and union you will need to create two new IntegerSets). Then again prompt the user for numbers to remove from set1 and numbers to insert into set2, then again show the display the sets, their equality, and their intersections and unions. Allow the user to loop through this process more than once.Here is an Example of What your Program Would Would Look Like:

The Infamous Integer Set Program.

NOTE: WHEN Entering Numbers please seperate

Them with spaces.

ENTER SET 1: 1 2 19 88

ENTER SET 2: 19 5 12-10

Set 1 IS {1,2,19,88}

SET 2 IS {5, 12, 19}

Set 1 == SET 2: FALSE

INTERSECTION OF Both sets IS {19}

Union of Both sets is {1,2,5,12,19,88}

ENTER NUMBERS TO REMOVE FROM SET 1: 1 50

ENTER NUMBERS TO INSERT INTO SET 2: 223 2

Set 1 IS {2,19,88}

Set 2 IS {2,5,12,19}

Set 1 == SET 2: FALSE

INTERSECTION OF Both sets IS {2,19}

Union of Both sets IS {2,5,12,19,88}

To Try Another Couple Of Sets Press 'Y':

Your main should not error check the integers but should pass them to the IntegerSet where only integers within the 0-100 range will be accepted and included The main should only act as the user interface;. Prompt the user for the input, break the input Down and pass it to the sets, and output explainatory text and the sets.

You must separate you program into the different files; interface (class header), implementation (class function definitions), and program file (main to run it all) For handing in the program, also include a sample run of your program In.. the sample run try a wide variety of numbers (negative,> 100, ones already in the set when trying to add, and ones not in the set when trying to delete) to show that your program works in different situations.You may overload operators To Work with your class for extra credit. for example, to put it

Due: in one week.

Comments:. Comments are a way of documenting a program (explaining who did what and how) All programs for the rest of the course are required to have the following header documentation (filled out with your information) and inline documentation to explain any tricky pieces Of code.

// file name: actual name of file (like pROG4.CPP)

// author: your name

// email: name @ Someplace (if you have one)

// Assignment: #

// Description: Short description of the program (2-3 sentences)

#include

.......

The rest of the program

STYLE: I Will Start To Take Off Points for Poor Style in Your Code.

Think about making your code readable. Avoid line wrap (in almost all cases a line can be shorted so that it will not wrap around when it prints). If possible, print your program from a developement environment (VC , UltraEdit), because then I Will Give A Few Extra Points if you print from from an development, environment.

转载请注明原文地址:https://www.9cbs.com/read-100886.html

New Post(0)