Ask Question

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)

+3
Answers (1)
  1. 22 October, 09:10
    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?
Find 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 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