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

  Create a console-based application named multiplication

a. Create a console-based application named Multiplication whose main() method asks the user to input and then calls a method named MultiplicationTable(), which displays the results of multiplying the integers by each of the number 2 through 10

  Webiste hi sir cis2003 is the qustion sheet rubalall is

hi sir cis2003 is the qustion sheet rubal.all is the privious work for this

  Briefly describe how parameter passing by value

Briefly describe how parameter passing by value and by reference are accomplished in memory. Write statement 1 to call Method A below. Write statement 2 to call Method B. Which method uses pass by value? Which method uses pass by reference?

  Create a script that presents a word guessing game

Create a script that presents a word guessing game. allow users to guess the word one letter at a time by entering a character in a form. start by assigning secret word to a variable.

  Blinky lights

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

  What is the full path the to location of the web application

what is the full path the to location of the web application directory for the cset-test web application and what is the full path to the main.jsp file for the cset-test web application?

  Html add textbox-a label and a button control to a page

This exercise, you add a TextBox, a Label, and a Button control to a page. When you request the page in the browser, these server controls are transformed into HTML, which is then sent to the client. looking at the final HTML for the page in the b..

  Create a class for the car information management

You should create a class for the car information management, and all the information should be saved and accessed to/from the class. You cannot use any variables for the information storing purpose in the Main method.

  Build a deployment package for an asp.net web site

You will build a deployment package for an ASP.NET Web site. You can use one of your already developed ASP.NET Web sites, or create a new site for this project

  Create or find appropriate images for the salary calculator

Create or find appropriate images for the Salary Calculator and New Employee links. Copy the images to the images folder created above.

  Add insert and edit menu options

Add Insert and Edit menu options - Insert will allow the user to insert a new account in a position of his choice

  Provide the basic syntax for declaring variables

Provide the basic syntax for declaring variables and conditional statements like, if, while, until and other loop controls in C Sharp (C#) dot net?

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