Question: Write a C++ program that does the following: Prompts the user for, and accepts a list of elements on a single line (separated by spaces).
Write a C++ program that does the following:
- Prompts the user for, and accepts a list of elements on a single line (separated by spaces). The elements are strings (with no embedded spaces). This is set A.
- Prompts the user for, and accepts a second list of elements on a single line (separated by spaces). The elements are strings (with no embedded spaces). This is set B. Sets A and B will contain no more than 25 elements each.
- Display each of the following.
- The cardinality and roster of the intersection of A and B
- The cardinality and roster of the union of A and B
- The cardinality and roster of the relative complement of A and B (i.e. A - B)
- The cardinality and roster of the relative complement of B and A (i.e. B - A)
- The cardinality and roster of the cross product of A and B
- The cardinality of the power set of the cross product of A and B (just the cardinality, not the roster.)
Do not use any C++ libraries to implement the intersection ,union, difference etc. operations. You must write your own routines for these. You can use the C++ library for strings.
This is the sample output:
Input the items in set A, separated by spaces. When you are done hit return.
discrete math CS251 pcc ****
The following is a list of the items in set A. A contains 5 items.
A = { discrete math CS251 pcc **** }
Input the items in set B, separated by spaces. When you are done hit return.
CS251 pcc &&&& qwerty
The following is a list of the items in set B. B contains 4 items.
B = { CS251 pcc &&&& qwerty }
A intersect B contains the following
{CS251 pcc }
The cardinality of the intersection is 2
A U B contains the following
{discrete math CS251 pcc **** &&&& qwerty }
The cardinality of the union is 7
A - B = { discrete math ****}
The cardinality is 3
B - A = { &&&& qwerty}
The cardinality is 2
The cardinality of A X B is 20
A X B contains {(discrete, CS251 ) (discrete, pcc ) (discrete, &&&& ) (discrete, qwerty ) }
(math, CS251 ) (math, pcc ) (math, &&&& ) (math, qwerty ) }
(CS251, CS251 ) (CS251, pcc ) (CS251, &&&& ) (CS251, qwerty ) }
(pcc, CS251 ) (pcc, pcc ) (pcc, &&&& ) (pcc, qwerty ) }
(****, CS251 ) (****, pcc ) (****, &&&& ) (****, qwerty ) }
The cardinality of the power set of the cross product is 1048576
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
