Ask DOT NET Expert

Create the program in C#

Create class IntegerSet. Each IntegerSet object can hold integers in the range 0-100. The set is represented by an array of bools. Array element a[i] is true if integer i is in the set. Array element a[j] is false if integer j is not in the set. The parameterless constructor initializes the array to the "empty set" (i.e., a set whose array representation contains all false values).

Provide the following methods:

a) Method Union creates a third set that is the set-theoretic union of two existing sets (i.e., an element of the third set's array is set to true if that element is true in either or both of the existing sets-otherwise, the element of the third set is set to false).

b) Method Intersection 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 false if that element is false in either or both of the existing sets-otherwise, the element of the third set is set to true).

c) Method InsertElement inserts a new integer k into a set (by setting a[k] to true).

d) Method DeleteElement deletes integer m (by setting a[m] to false).

e) Method ToString returns a string containing a set as a list of numbers separated by spaces. Include only those elements that are present in the set. Use --- to represent an empty set.

f) Method IsEqualTo determines whether two sets are equal.

Test your class IntegerSet by using the main method below:
static void Main(string[] args)
{
// initialize two sets
Console.WriteLine("Input Set A");
IntegerSet set1 = InputSet();
Console.WriteLine("nInput Set B");
IntegerSet set2 = InputSet();
IntegerSet union = set1.Union(set2);
IntegerSet intersection = set1.Intersection(set2);
// prepare output
Console.WriteLine("nSet A contains elements:");
Console.WriteLine(set1.ToString());
Console.WriteLine("nSet B contains elements:");
Console.WriteLine(set2.ToString());
Console.WriteLine(
"nUnion of Set A and Set B contains elements:");
Console.WriteLine(union.ToString());
Console.WriteLine(
"nIntersection of Set A and Set B contains elements:");
Console.WriteLine(intersection.ToString());
// test whether two sets are equal
if (set1.IsEqualTo(set2))
Console.WriteLine("nSet A is equal to set B");
else
Console.WriteLine("nSet A is not equal to set B");
// test insert and delete
Console.WriteLine("nInserting 77 into set A...");
set1.InsertElement(77);
Console.WriteLine("nSet A now contains elements:");
Console.WriteLine(set1.ToString());
Console.WriteLine("nDeleting 77 from set A...");
set1.DeleteElement(77);
Console.WriteLine("nSet A now contains elements:");
Console.WriteLine(set1.ToString());
// test constructor
int[] intArray = { 25, 67, 2, 9, 99, 105, 45, -5, 100, 1 };
IntegerSet set3 = new IntegerSet(intArray);
Console.WriteLine("nNew Set contains elements:");
Console.WriteLine(set3.ToString());
} // end Main
// creates a new set by reading numbers from the user
private static IntegerSet InputSet()
{
IntegerSet temp = new IntegerSet();
Console.Write("Enter number (-1 to end): ");
int number = Convert.ToInt32(Console.ReadLine());
while (number != -1)
{
temp.InsertElement(number);
Console.Write("Enter number (-1 to end): ");
number = Convert.ToInt32(Console.ReadLine());
} // end while
return temp;
}
}
Output
Input Set A
Enter number (-1 to end): 2
Enter number (-1 to end): 7
Enter number (-1 to end): 4
Enter number (-1 to end): 3
Enter number (-1 to end): 1
Enter number (-1 to end): -1
Input Set B
Enter number (-1 to end): 4
Enter number (-1 to end): 1
Enter number (-1 to end): 3
Enter number (-1 to end): 8
Enter number (-1 to end): 9
Enter number (-1 to end): 7
Enter number (-1 to end): -1
Set A contains elements:
{ 1 2 3 4 7 }
Set B contains elements:
{ 1 3 4 7 8 9 }
Union of Set A and Set B contains elements:
{ 1 2 3 4 7 8 9 }
Intersection of Set A and Set B contains elements:
{ 1 3 4 7 }
Set A is not equal to set B
Inserting 77 into set A...
Set A now contains elements:
{ 1 2 3 4 7 77 }
Deleting 77 from set A...
Set A now contains elements:
{ 1 2 3 4 7 }
New Set contains elements:
{ 1 2 9 25 45 67 99 100 }
Press any key to continue . . .

DOT NET, Programming

  • Category:- DOT NET
  • Reference No.:- M91937985
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in DOT NET

Assignment specificationthis assignment is split into two

ASSIGNMENT SPECIFICATION This assignment is split into two documents. 1. Assignment Specification. This document contains the specification for what you will be required to do. 2. Assignment Addendum. This document conta ...

Scenariouser modelling inc would like to organize a series

Scenario User Modelling Inc. would like to organize a series of conferences focusing on research topics in the area of user adaptive systems and personalization. They need to organize annual conferences for researchers a ...

Casewe sell pdfs from our site and pdfs can be ordered from

Case We sell pdf''s from our site and pdfs can be ordered from the site by selecting a book, putting it in a shopping cart, then signing in with a password or as a guest, and then checking out. For some reason, when a pu ...

Summarythis assessment requires you to develop a simple

Summary This assessment requires you to develop a simple text editor with a basic offline user login. It is a windows application that will allow new uses to be added, existing users to login, and to create/save/edit tex ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As