C#代写:CS3160 Set

练习C#的基本语法,实现关于Set的操作。

Purpose

The purpose of this assignment is to create a C# class representing sets of integers in the range 0 to 50 inclusive.
You should work in your groups (2 members). If your partner is not present in class each will need to complete the assignment on your own by the due date/time.

Always bring to class

  1. Deitel’s book.
  2. This assignment grade sheet for this lab already printed out.
  3. USB Flash drive(s) or other storage media.
  4. Your laptop with Microsoft Visual Studio 2015.

Mandatory Instructions

Begin by creating a solution folder on the ZIP disk, USB flash drive, or your laptop’s HD. The folder’s name should be one or two last names followed by Lab1 (e.g. Smith-Lab1 or Smith-Jones-Lab1) if both group members are working on the solution.

You will create a file IntegerSet.cs that will be compiled into IntegerSet.dll. Begin by creating a makefile that you will use for this assignment. The application created by the makefile should be called Lab1.exe. Also implement the “clean” target so that you can type “make clean” for the current directory. Use the command-line compiler csc for this assignment. Do not use Visual Studio GUI!

Define the IntegerSet class in the file IntegerSet.cs. Use the same namespace (Set) that is used for the main program. Remember to make your class public. Hint: Because the only integers allowed are those in the range 0 to 50 inclusive, you don’t really need the overhead of linked lists to implement the set. Use a bool array of length 51 to represent the set. If the value of position i is true, that means that i is in the set. (Example: If arr[5] is true, that means that 5 is in the set.) These are the public member functions of IntegerSet:

  • Constructor with no arguments: Create an empty set
  • Constructor with integer array argument: The elements to be put into the set are those that are found in the array values. Suggestion: Use the foreach statement to go through each element of the array and add it to the set. If any value is invalid (less than zero or greater than 50), just print a message and keep going. Don’t terminate the program because of an invalid integer.
  • EmptySet: This member function accepts no arguments and removes all elements from the set.
  • InsertElements: Accepts an integer array as an argument and adds each integer element to the set. If any integer is invalid, just print a message. Don’t terminate the program because of this error condition.
  • InsertElement: Adds one integer element to the set. If the integer is invalid, just print a message. Don’t terminate the program because of this error condition.
  • DeleteElement: Removes one integer element from the set. If the integer argument is invalid, just print a message. Don’t terminate the program because of this error condition.
  • InputSet: Allow elements to be added to the set. Read integers from the console, one at a time and add them to the set. Stop the input when the enter key is pressed. For invalid integers, just print an error message and keep going.
  • Union: Calculate the union of the set with another set. An IntegerSet is the argument to the function, and the function returns an IntegerSet.
  • Intersection: Calculate the intersection of the set with another set.
  • Equals: Override Equals to determine if the set is equal to another set (i.e. contains the same elements). This function requires the override keyword and returns a bool value.
  • GetHashCode: This function must be overridden whenever Equals is overridden.
  • ToString: Override the ToString method to return a string representing the set, using the format { 12 15 30 }. If the set is empty, return “{ empty }”.

You might find it convenient to define one or more private functions for use in your function implementations. Make sure to document your code and to use meaningful variable names.

When you have fully debugged your code, upload your compressed solution folder to Canvas (both group members should upload the solution). Your folder should contain only three files (App.cs, IntegerSet.cs, makefile) for this assignment.
Sample output for this program is provided below

A is: { 3 4 11 21 29 }
B is: { 1 2 3 4 }

Union of A and B is: { 1 2 3 4 11 21 29 }

Intersection of A and B is: { 3 4 }

Set A is not equal to set B

Copying a to b...
Set A is equal to set B

Inserting 33 into set A...
Set A is now: { 3 4 11 21 29 33 }

Deleting 33 from set A...
Set A is now: { 3 4 11 21 29 }

Enter set E: 
Enter an element (Enter to end): 5
Enter an element (Enter to end): 6
Enter an element (Enter to end): 7
Enter an element (Enter to end): 6
Enter an element (Enter to end): 5
Enter an element (Enter to end):

Set e is: { 5 6 7 }
Emptying set e...
Set e is: { empty }

Code Documentation

Each of your source files should contain a documentation header with description, author name, class information. Each function should have a documentation header with minimally function name, description, parameters, return value. Use proper program style at all times which means indentation, alignment, and whitespace. Utilize self-documenting code which means use mnemonic, i.e., meaningful variable/function/namespace/class names, etc.

What to turn in?

Submit compressed (.zip) solution folder via Canvas.
In your solution folder make sure that all necessary files to compile/link/execute your projects are provided.
Here are some files that may be required

  1. All required C# source files (.cs)
  2. makefile (if the solution requires it)
  3. The entire Visual Studio 2015 solution folder (if the solution requires it)