Question
Write a C++ program (or Java program) called hw1_3.cpp ( or hw1_3.java) that reads a number of elements in a set and then read the
Write a C++ program (or Java program) called hw1_3.cpp (or hw1_3.java) that reads a number of elements in a set and then read the elements of the set. After that, your program should display all possible binary numbers and corresponding subsets one by one. For the program, you can assume that the number of elements in a set is less than or equal to 10.
Sample Run 1: Assume that the user typed the following input. Note that there are three elements in the set with the elements A, B, and C.
3
A B C
This is the correct output.
000:EMPTY
001:C
010:B
011:B C
100:A
101:A C
110:A B
111:A B C
The first line shows that the binary number is 000. Note that the first bit 0 is for the element A, the second bit 0 for the element B, and the last bit 0 for the element C. Since all three bits are 0, the binary number 000 means the empty set.
The next line indicates that the binary number is 001 and it corresponds to the subset {C} because only the last bit is 1. Similarly, the last line indicates that the binary number is 111 and it corresponds to the subset {A, B, C} because all bits are 1.
Sample Run 2: Assume that the user typed the following input.
2
CST238 CST370
This is the correct output.
00:EMPTY
01:CST370
10:CST238
11:CST238 CST370
Sample Run 3: Assume that the user typed the following input.
0
This is the correct output of your program.
0:EMPTY
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started