Implement sets represented by characteristic vectors using a C++ class. Keep all class members that are not accessed "from the outside" private. You must have at least 1 private class member. In your main class create 3 instances of your set named R, S and T, which initially do not contain any elements. The universal set for your set will correspond to the different values of the same suit in a deck of cards, i.e. there are 13 different values. You must use arrays or vectors for your implementation. it is ok to use if else statements to determine which set is referred to, or use of maps from the STL.

Once the program is started, it will print out the promt "sets> " (> is followed by a whitespace):

./a.out
sets>

You will implement the commands "assign", "clear", "union", intersection", "difference", "print" and "quit":

assign

Assign takes 1 argument indicating the set name followed by 13 boolean values (represented by 0 or 1) separated by white spaces. Fill the set referenced with the corresponding values. If a set already had different values, simply override them. Then repeat the prompt.

sets> assign R 0 1 0 1 1 1 0 0 1 0 1 0 0
sets> assign S 1 0 0 0 0 0 1 0 1 0 1 1 1
sets> assign T 1 1 1 1 0 0 0 0 1 0 1 1 0
sets>

clear

Clear takes a single argument indicating the set name. Remove all elements of the set. Then repeat the prompt.

sets> clear S
sets>

union

Union takes two arguments indicating the set names. Create the set union of the two sets without modifying the original sets. Print out the result separating the individual elements via hyphens. Then repeat the prompt.

sets> union R S
1-­‐1-­‐0-­‐1-­‐1-­‐1-­‐1-­‐0-­‐1-­‐0-­‐1-­‐1-­‐1
sets> union R T
1-­‐1-­‐1-­‐1-­‐1-­‐1-­‐0-­‐0-­‐1-­‐0-­‐1-­‐1-­‐0
sets> union S T
1-­‐1-­‐1-­‐1-­‐0-­‐0-­‐1-­‐0-­‐1-­‐0-­‐1-­‐1-­‐1
sets>

intersection

Intersection takes two arguments indicating the set names. Create the set intersection of the two sets without modifying the original sets. Print out the result separating the individual elements via hyphens. Then repeat the prompt.

sets> intersection S R
0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐1-­‐0-­‐1-­‐0-­‐0
sets> intersection T S
1-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐1-­‐0-­‐1-­‐1-­‐0
sets> intersection R T
0-­‐1-­‐0-­‐1-­‐0-­‐0-­‐0-­‐0-­‐1-­‐0-­‐1-­‐0-­‐0
sets>

difference

Difference takes two arguments indicating the set names. Create the set difference of the two sets without modifying the original sets. Print out the result separating the individual elements via hyphens. Then repeat the prompt.

sets> difference R S
0-­‐1-­‐0-­‐1-­‐1-­‐1-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0sets> difference S R
1-­‐0-­‐0-­‐0-­‐0-­‐0-­‐1-­‐0-­‐0-­‐0-­‐0-­‐1-­‐1
sets> difference T R
1-­‐0-­‐1-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐0-­‐1-­‐0
sets>

print

Print takes a single argument indicating the set name. Print out all the elements of the set indicated separated by hyphens. Then repeat the prompt.

sets> print S
1-­‐0-­‐0-­‐0-­‐0-­‐0-­‐1-­‐0-­‐1-­‐0-­‐1-­‐1-­‐1
sets> print R
0-­‐1-­‐0-­‐1-­‐1-­‐1-­‐0-­‐0-­‐1-­‐0-­‐1-­‐0-­‐0
sets> print T
1-­‐1-­‐1-­‐1-­‐0-­‐0-­‐0-­‐0-­‐1-­‐0-­‐1-­‐1-­‐0sets>

quit

Exit the program

sets> quit

Error Handling

If the command received from the user input is not supported, print out an error message starting with "Error!".

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.