Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How to read elements of a set from user input and save it using a bit vector? int setA = 0; // a variable to
How to read elements of a set from user input and save it using a bit vector? int setA = 0; // a variable to save the bit vector of set A int userInput; // a variable to save the user input // put the following code in a loop to continually read user input and // construct the bit vector of set A until encountering an invalid number to stop (e.g. -1) setA |= (1
MAKE SURE TO NOT USE ARRAYS
Given subsets A and B of a universal set with 10 elements (0, 1, 2, 3, 4, 5, 6,7, 8,9), write a C++ or Java program that uses bit strings to find A U B, A n B, and A - B. Print to the screen set A, set B (be sure to print out the name of the sets), as well as the set operation results (be sure to print out the name of the operations). The program requires that elements of subsets A and B are from user input. You can make the assumption that user input numbers are within the domain of the set 0, 1, 2, ..., 9) and there is no improper input. Additional requirements and reminders: The use of STL, templates, and operator overloading is not permitted in any form. Remember: You must use a bit vector when representing a set. You may not use an array of Boolean variables. The elements of subset A and subset B must from user input. You may not hardcode the two subsets in your program. Name your file HW2.cpp or HW2.java Sample output: [ohshecs1 c2600]5 HNZ Welcome to HW 2: programming! Given subsets A and B of a universal set with 10 elements (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, we will use bit strings to find AUB, An B, and A B. Us ers will be asked to populate each set. For example, if the user enters 1, 2, 6, the bit st ring will display from left to right and display 0118001000 Please enter a number for set A Center -1 to stop):1 Please enter a number for set A Center-1 to stop) 2 Please enter a number for set A (enter -1 to stop): 6 Please enter a number for set A (enter -1 to stop): -1 Please enter a number for set B (enter -1 to stop) 2 Please enter a number for set B Center -1 to stop): 4 Please enter a number for set B (enter -1 to stop): 6 Please enter a number for set B (enter -1 to stop): 8 Please enter a number for set B (enter-1 to stop): -1 Set A: 0110001000 Set B: 0010101010 Union: 0110101010 Intersection: 0010001000 Difference 0100000000 Given subsets A and B of a universal set with 10 elements (0, 1, 2, 3, 4, 5, 6,7, 8,9), write a C++ or Java program that uses bit strings to find A U B, A n B, and A - B. Print to the screen set A, set B (be sure to print out the name of the sets), as well as the set operation results (be sure to print out the name of the operations). The program requires that elements of subsets A and B are from user input. You can make the assumption that user input numbers are within the domain of the set 0, 1, 2, ..., 9) and there is no improper input. Additional requirements and reminders: The use of STL, templates, and operator overloading is not permitted in any form. Remember: You must use a bit vector when representing a set. You may not use an array of Boolean variables. The elements of subset A and subset B must from user input. You may not hardcode the two subsets in your program. Name your file HW2.cpp or HW2.java Sample output: [ohshecs1 c2600]5 HNZ Welcome to HW 2: programming! Given subsets A and B of a universal set with 10 elements (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, we will use bit strings to find AUB, An B, and A B. Us ers will be asked to populate each set. For example, if the user enters 1, 2, 6, the bit st ring will display from left to right and display 0118001000 Please enter a number for set A Center -1 to stop):1 Please enter a number for set A Center-1 to stop) 2 Please enter a number for set A (enter -1 to stop): 6 Please enter a number for set A (enter -1 to stop): -1 Please enter a number for set B (enter -1 to stop) 2 Please enter a number for set B Center -1 to stop): 4 Please enter a number for set B (enter -1 to stop): 6 Please enter a number for set B (enter -1 to stop): 8 Please enter a number for set B (enter-1 to stop): -1 Set A: 0110001000 Set B: 0010101010 Union: 0110101010 Intersection: 0010001000 Difference 0100000000
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