Ask Question
10 September, 07:53

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)

+4
Answers (1)
  1. 10 September, 11:26
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers