haas:fall2012:common:discrete-p06-20121108142000
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:
- Presents a menu to the user, enabling the selection of the following options (each option should be in a separate function):
- Build Set A (Standard Set Building Code)
- Build Set B (Standard Set Building Code) – if you code this right, you could do both builds with a single function.
- Display Set A
- Display Set B
- Display Set C (result set)
- Display All Sets – again, some optimization could occur so you have fewer than 4 display() functions.
- Set Union of A and B
- Set Intersection of A and B
- Set Difference of A and B
- Set Difference of B and A
- Clear Set A
- Clear Set B
- Clear Set C
- Clear All Sets
- Exit
- Each option (save for things like exit) will end up calling a function to perform the intended task.
- Put in code that checks for invalid selections from being made (same data type, just out of range) and notify the user of an invalid choice being made.
Assumptions
You may develop the program with the following assumptions in mind:
- Generally, the same assumptions that governed the first part of this program.
- You are aiming to put different actions in functions.
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:
- Codebase is documented. You must have comments sprinkled throughout your code.
- Code is uniformly and optimized for readability in its indentation. I will be evaluating indentation!
- Your code must compile and run, without warnings or issues, with the above requirements (I may ask for a specific set membership and actions to be taken).
- The displaying of the set MUST conform to that set notation (note the spacing, the commas, and the lack of a comma following the last element).
- You must use functions, passing and returning any necessary data as appropriate.
- Your working, compilable code should be added/commit/pushed to your repository located in the ~/src/discrete/submit/p06/ directory.
haas/fall2012/common/discrete-p06-20121108142000.txt · Last modified: 2012/11/08 07:51 by 127.0.0.1