Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C++ that reads in a group of numbers, A, on one line and anot

ID: 650030 • Letter: W

Question

Write a program in C++ that reads 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

Explanation / Answer

Hope this will helps you ... tried very much...

#include<stdio.h>

bool isSubset(int ar1[], int ar12[], int m, int n)
{
    int i = 0;
    int j = 0;
    for (i=0; i<n; i++)
    {
        for (j = 0; j<m; j++)
        {
           if(ar12[i] == ar1[j])
              break;
        }
       
     
        if (j == m)
           return 0;
    }
   
  
    return 1;
}

int main()
{
    int ar1[] = {11, 1, 13, 21, 3, 7};
    int ar12[] = {11, 3, 7, 1};

    int m = sizeof(ar1)/sizeof(ar1[0]);
    int n = sizeof(ar12)/sizeof(ar12[0]);

    if(isSubset(ar1, ar12, m, n))
      printf("ar12[] is subset of ar1[] ");
    else
      printf("ar12[] is not a subset of ar1[]");    

    getchar();
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote