Question: Write a C++ program to list all elements in the Cartesian product of these two sets. You will ask user to enter the elements of

Write a C++ program to list all elements in the Cartesian product of these two sets. You will ask user to enter the elements of each set (A and B), then display the Cartesian product of A and B. Turn in the C++ source code (not project file or solution file), with three test cases. Note: set A and B can hold string elements, double, and/or character datatype. It is your choice. Following is an example of A holds integer and B holds characters.

Example of program output:

This program lists all elements in the Cartesian product of sets A and B.

For example: Let A = {1, 2, 3}

Let B = {a, b}

The Cartesian product is:

A X B = { (1, a), (1, b), (2, a), (2, b), (3, a), (3, b) }

Enter integers for set A (no more than 30 numbers, -1 to stop)

1: 1

2: 2

3: 3

4: -1

Enter characters for set B (no more than 30 characters, '.' to stop)

1: a

2: b

3: . set A = { 1, 2, 3 }

set B = { a, b }

The Cartesian product of A and B is

A X B = {

( 1, a ), ( 1, b ), ( 2, a ), ( 2, b ), ( 3, a ), ( 3, b ) } Again (y/n): y

Enter integers for set A (no more than 30 numbers, -1 to stop)

1: 2

2: 4

3: 6

4: 8

5: -1

Enter characters for set B (no more than 30 characters, '.' to stop)

1: x

2: y

3: z

4: .

set A = { 2, 4, 6, 8 }

set B = { x, y, z }

The Cartesian product of A and B is A X B = {

( 2, x ), ( 2, y ), ( 2, z ), ( 4, x ), ( 4, y ), ( 4, z ), ( 6, x ), ( 6, y ), ( 6, z ), ( 8, x ), ( 8, y ), ( 8, z ) } Again (y/n): n

Press any key to continue . . .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!