Ask Question
2 November, 10:14

Your program must define and call the following two functions. IsVectorEven returns true if all integers in the array are even and false otherwise. Is Vector Odd returns true if all integers in the array are odd and false otherwise. bool IsVectorEven (vector Vec) bool IsVectorOdd (vector myVec)

+2
Answers (1)
  1. 2 November, 11:11
    0
    Consider the C+ + program below

    Explanation:

    #include

    #include

    using namespace std;

    bool IsVectorEven (vector myVec) {

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

    if (myVec[i] % 2 = = 1) {

    return false;

    }

    }

    return true;

    }

    bool IsVectorOdd (vector myVec) {

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

    if (myVec[i] % 2 = = 0) {

    return false;

    }

    }

    return true;

    }

    int main () {

    vector vec;

    int n, num;

    cin >> n;

    for (int i = 0; i < n; + +i) {

    cin >> num;

    vec. push_back (num);

    }

    if (IsVectorEven (vec)) {

    cout << "all even" << endl;

    }

    else if (IsVectorOdd (vec)) {

    cout << "all odd" << endl;

    } else {

    cout << "not even or odd" << endl;

    }

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Your program must define and call the following two functions. IsVectorEven returns true if all integers in the array are even and false ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers