 Computers & Technology
22 October, 08:52

# 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)

0
1. 22 October, 09:54
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;

}