Comp 110L

Lab Project #10

Due: 11/16/2009

 

 

Write a program that determines whether two sets of integers are equal (contain the same elements), disjoint (have no elements in common), overlapping (have some but not all elements in common, but each has some elements not in the other), or whether one is a proper subset of the other (all its elements are in the other, but the other also has additional elements).  To solve this problem read in each set and store the values into an array (one array for each set).  Note that the set {1, 2, 2, 3, 1} is considered to be the same as the set {1, 2, 3} (duplicate values are ignored).  Then check the two sets, A and B, to see whether:

·         A = B (e.g., if A = {1, 3, 5} and B = {5, 3, 1} they are identical – order doesn’t matter)

·         A ∩ B = Φ (e.g., if A = {1, 2, 3} and B = {4, 5, 6} they are disjoint)

·         A is a proper subset of B (e.g., if A = {2, 3} and B = {1, 2, 3) A is a proper subset of B)

·         B is a proper subset of A (e.g., if A = {1, 2, 3} and B = {3, 1} B is a proper subset of A)

·         A and B are overlapping (none of the above situations is true)

 

Let the user input the values for the two sets.  You may assume that the maximum number of values in each set is 10.  Print out each set after it is read in and print each set again after the duplicate values are removed.  After you determine the relationship between the sets print an appropriate message describing it (e.g., “Set A is a proper subset of Set B”).  You should have at least one subprogram (method) in you solution to check whether a given integer is in a given array.  You may want to have additional methods as well, like one to check whether one set is a subset of another.

 

For this problem be sure to do the following:

 

1.            Plan your solution by writing down the algorithm to solve the problem before you write the code.  Express the algorithm design in one of the following three forms:

·         A flow chart

·         A block diagram

·         Pseudo Code

2.            Make sure your program is self-documenting including an appropriate comment header block. 

3.            Test the program by running an appropriate number of test cases (i.e., you should be sure to test all of the possible set relationships).