Determine whether two sets are equal

Assignment Help DOT NET Programming
Reference no: EM131181879

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 . . .

Reference no: EM131181879

Questions Cloud

Regulation and deregulation of transportation : How does the regulation and deregulation of transportation impact the supply chain?
What types of business risk essman might have overlooked : What types of business risk do you think Essman might have overlooked?- Would a Askoeteation assurance program be a good possibility for this company? Why or why not?
What type of queue is implemented at the router : What type of queue is implemented at the router - What is the delay for each class of traffic? Justify by calculations.
Compromise on wage or nonwage issues : What are some nonwage issues that might come up in bargaining? Which ones are the most important and why? Is it easier to compromise on wage or nonwage issues? Why?
Determine whether two sets are equal : 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 ..
How many units of new product should be purchased for resale : You are considering adding a new food product to your store for resale. You are certain that, in a month, minimum demand for the product will be 6 units, while maximum demand will be 8 units. You will pay $60/unit for this new product while you plan ..
Business sponsor and customer informed : As we learned in Week 7, your business sponsor and customer informed you that you have to deliver your project much sooner than anticipated. When you break the news to your team
Efficient market and an arbitrage-free market : (i) Explain the difference between an efficient market and an arbitrage-free market. Empirical investigations of stock market returns have revealed a fractal dimension of 1.4. (ii) Explain what this means about the distribution of returns.
Consider large distribution centre : Consider a large distribution centre (DC) that sees the arrival of, on average, 40 trucks per 8-hour workday (assume a Poisson distribution). The unloading of a truck at one of the unloading docks takes, on average 45 minutes (assume exponential dist..

Reviews

Write a Review

DOT NET Programming Questions & Answers

  Develop web services based application

Develop and test a Web services based application that meets the requirements applying SOA design principles.

  Design style elements in asp

Add drop down lists for modifying the different style elements for the label element that displays the time

  Create a shopping cart in asp

The users will use a browser to access the on-line store. The web server software for the production web server is Windows 2003 Server /IIS6.

  Inventory management system in c# application

Inventory management system in c# application

  Using .net resources to teach .net

This project will use the .NET framework to produce a set of materials to demonstrate the fundamental principles of .NET. Ideally it should demonstrate some of the principles of the framework e.g. interoperability.

  Prepare a marymount faculty site

Prepare a Marymount faculty site

  Blinky lights

Analysis proving that your code blinks the LEDs at the specified rates.

  Prepare a web application

Prepare a web application that will be used to keep track of patients registering in a hospital.

  Implementing the insurance management system

Implementing the Insurance Management System and implementation of Components as Web Services.

  Describe the characteristics of visual studio 2005

Describe the characteristics of Visual Studio 2005 Visual Studio.Net is a suite of products that includes 4 main languages. Name these languages and outline their use in industries

  What is a connectionstring

What is a ConnectionString. Give a suitable example to illustrate the various part of a ConnectionString

  Prepare a web application for internet service provider

Prepare a Web application and write the code also event planning document base. This web application allows the user to sign up for an Internet service provider for home connectivity.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd