Program in C++ Read in a group of numbers, A, on one line and another group, B,
ID: 650159 • Letter: P
Question
Program in C++
Read in a group of numbers, A, on one line and another group, B, on the next line of standard input. Using std::set (or std::map) print out if A is a subset of B or B is a subset of A.
Here is a sample run of an example solution:
./set_practice
Please enter the values for A:
1 2 3 4 5
Please enter the values for B:
1 2 3
B is a subset of A
./set_practice
Please enter the values for A:
1 2 3
Please enter the values for B:
1 2 3 4 5
A is a subset of B
./set_practice Please enter the values for A:
1 2 3 4 5
Please enter the values for B:
1 2 7
B is not a subset of A
HINT: Here is some sample code that will help you take in two sets of numbers using the getline() function, and then use stringstream to tokenize the associate string returned from getline() into integers you can use:
}
Explanation / Answer
if(setA.length()>setB.length())
{
while(setA!=NULL)
{
for(int i=0;i<strlen(setA);i++)
{
for(int j=0;j<strlensetB();j++)
{
if(setA[i][j]==setB[i][j] || setB[i][j]!=NULL))
cout<< " setB is subset"<<setB[i][j];
}
}
}
}
if(setA.length()<setB.length())
{
while(setB!=NULL)
{
for(int i=0;i<strlen(setB);i++)
{
for(int j=0;j<strlensetA();j++)
{
if(setA[i][j]==setB[i][j] || setA[i][j]!=NULL))
cout<< " setA is subset"<<setA[i][j];
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.