Table of Contents

Set Program: Part 2

Overview

We will now further extend our set program to do a few of the basic set operations- set union, intersection, and difference.

Criteria

Write a program that does the following:

Assumptions

You may develop the program with the following assumptions in mind:

Example Output

You resulting program should operate in a manner similar to the following (output doesn't have to exactly match):

lab46:~/src/discrete/p06$ ./setprog
Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 2

[Set B] Enter a unique value (-1 to quit): 1
[Set B] Enter a unique value (-1 to quit): 2
[Set B] Enter a unique value (-1 to quit): 4
[Set B] Enter a unique value (-1 to quit): 8
[Set B] Enter a unique value (-1 to quit): -1

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 4

B = { 1, 2, 4, 8 }

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 5

C = { }

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 1

[Set A] Enter a unique value (-1 to quit): 4
[Set A] Enter a unique value (-1 to quit): 8
[Set A] Enter a unique value (-1 to quit): 16
[Set A] Enter a unique value (-1 to quit): 4
Duplicate Value Detected! Discarding...
[Set A] Enter a unique value (-1 to quit): 32
[Set A] Enter a unique value (-1 to quit): -1

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 3

A = { 4, 8, 16, 32 }

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 7

UNION of A and B, result in C

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 5

C = { 1, 2, 4, 8, 16, 32 }

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 13

Set C cleared.

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 5

C = { }

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 8

Set Intersection of A and B, result in C.

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 5

C = { 4, 8 }

Set Menu
--------
 1. Build Set A
 2. Build Set B
 3. Display Set A
 4. Display Set B
 5. Display Set C
 6. Display All Sets
 7. Set Union of A and B
 8. Set Intersection of A and B
 9. Set Difference of A and B
10. Set Difference of B and A
11. Clear Set A
12. Clear Set B
13. Clear Set C
14. Clear All Sets
 0. Exit

Make a selection (0-15): 0
lab46:~/src/discrete/p06$ 

Submission

Please be sure your program also meets the following criteria: