Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an application that can apply set operations to a set of values. Generics will be used to specify the type of values on which

Create an application that can apply set operations to a set of values. Generics will be used to specify the type of values on which the application should apply the set operations.

The applicaton will follow the S.O.L.I.D. design principles.

Interfaces

The ISet interface represents a set of non-duplicating values. Specify a generic type for the interface ( ). In order to make sure values are non-duplicating, implementors must be able to test for equality among the type elements. This can be accomplished by ensuring that the type specified supports the IEquatable interface (a type parameter constraint). The IEquatable requires that the implementing type supports an Equals method to test for equality. The set represents a sequence by inheriting the IEnumerable interface.

Methods of the ISet interface include Add(T) to add an element of type T to the set, AddAll(IEnumerable) to add a sequence of values of type T to the set. Both Add and AddAll prevent duplicate values from being added to the set. The methods Add and AddAll do not return anything. The supported set methods are SetUnion, SetIntersect, and SetDifference. Each of these methods takes an ISet parameter and returns a new ISet object. The SetUnion method returns a new ISet object that contains all elements of the current set object and the parameter set object, eliminating any duplications. The SetIntersect method returns a new ISet object that contains only elements that are in both the current set and the parameter set objects. The SetDifference method returns a new ISet object that contains only elements that are in the current set object that are not in the parameter set object.

The ISetFactory represents a ISet instantiator that creates ISet objects. There are two methods supported in this interface: CreateSet with no parameters that creates and returns an ISet object with no elements and CreateSet that takes an IEnumerable parameter and returns an ISet object initialized with elements from that parameter. The CreateSet methods must include a type parameter ( ) to indicate the type of ISet to be created. The method type parameter will have the same type constraint as the ISet interface.

Classes

The Set class implements (supports) the ISet interface. A generic type ( ) is required and must be constrained as it is in the ISet interface. You can implement the storage for the set data using a List as a private class field. The class must support 2 constructors: The default constructor creates a Set with no elements. A second constructor creates a Set that is initialized with a sequence of values from an IEnumerable parameter. The constructor must ensure that duplicate values are not stored in the set.

The Set class must implement the Add, AddAll, SetUnion, SetIntersect, and SetDifference methods as described in the ISet interface. Each of the five methods should be overridable to allow for future extensions. The Set must also support the IEnumerable interface (defined in ISet) by implementing the IEnumerable.GetEnumerator and IEnumerable.GetEnumerator methods (that is, the generic and non-generic versions of the method). To implement these methods, simply call the backing List object's GetEnumerator method and return the enumerator returned by those methods. Note, to call the list's IEnumerable.GetEnumerator method, you must cast the list object to an IEnumerable (non-generic) type before calling GetEnumerator.

The Set class should not use the IEnumerable extension methods Union, Intersect, or Except.

Finally, the Set class must override the ToString method to return a string that contains a comma-separated list for the elements of the set in square brackets (e.g. [element1, element2, element3, ..., elementn]).

The SetFactory class implements (supports) the ISetFactory interface. It implements the two CreateSet methods by calling the appropriate Set class constructors and returning the newly instantiated object.

The Application

z

Program.cs

The Program.cs file must create the ConSet object, the ISetFactory object and then call the ConSet.Run method specifying the type of data for the set. E.g.

ConSet conset = new ConSet();

ISetFactory setfactory = new SetFactory();

conset.Run(setfactory);

conset.Run(setfactory);

Sample Execution of the Application

Please enter the first set of Int32 values:

1

2

3

Please enter the second set of Int32 values:

3

5

7

[1, 2, 3] UNION [3, 5, 7] = [1, 2, 3, 5, 7]

[1, 2, 3] INTERSECT [3, 5, 7] = [3]

[1, 2, 3] DIFFERENCE [3, 5, 7] = [1, 2]

Please enter the first set of Double values:

1.1

2.2

3.3

Please enter the second set of Double values:

3.3

5.5

7.7

[1.1, 2.2, 3.3] UNION [3.3, 5.5, 7.7] = [1.1, 2.2, 3.3, 5.5, 7.7]

[1.1, 2.2, 3.3] INTERSECT [3.3, 5.5, 7.7] = [3.3]

[1.1, 2.2, 3.3] DIFFERENCE [3.3, 5.5, 7.7] = [1.1, 2.2]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions