Ask Question

gWrite a function with two input parameters that are both vector of ints. The function returns true if the 2nd vector contains at least one of each value within the 1st vector, otherwise returns false. For example, if the 1st vector contains the values [6 3 8 3] and the 2nd vector contains the values [3 8 8 1 6], the function should return true since the values 6, 3, and 8 all show up at least once in the 2nd vector. However, if the 2nd vector contains only [3 8 8 1], the function should return false since the value 6 does not show up in the 2nd vector.

+1
Answers (1)
  1. 28 May, 06:51
    0
    Solution and Explanation:

    #include

    #include

    using namespace std;

    bool contains_all (vector v1, vector v2) {

    for (int i = 0; i < v1. size (); + +i) {

    bool found = false;

    for (int j = 0; j < v2. size (); + +j) {

    if (v1[i] = = v2[j])

    found = true;

    }

    if (! found)

    return false;

    }

    return true;

    }

    int main () {

    vector v1 = {6, 3, 8, 3}, v2 = {3, 8, 8, 1, 6}, v3 = {3, 8, 8, 1};

    cout << contains_all (v1, v2) << endl;

    cout << contains_all (v1, v3) << endl;

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “gWrite a function with two input parameters that are both vector of ints. The function returns true if the 2nd vector contains at least one ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers