Answer:
This program is written in C++. The explanation of code is given below in explanation section.
Explanation:
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
//function to check vector element is even or not
bool IsEven(int n) {
return (n % 2) == 0;
}
//function to check vector element is odd or not
bool IsOdd(int n)
{
if (n%2!=0)// detection of odd value
{
return 1;
}
}
bool IsVectorEven(vector<int> vect)// check even number in vector
{
auto countEven = count_if(vect.begin(), vect.end(), IsEven);//count total even numbers in vector
int size= vect.size();//count total number in vector/check vector size
if(countEven==size)//all counted even number to size of vector
{
cout<<"\nAll even";//display the message
//return 1;
}
else
{
cout<<"\nnot even or odd";//else display the message
// return 0;
}
}
bool IsVectorOdd(vector<int> vect)//check odd vector
{
auto countOdd = count_if(vect.begin(), vect.end(), IsOdd);// count total odd number in vector
int size= vect.size();// count total number in vector
if(countOdd==size)// if vector size is equal to vector counted odd number
{
cout<<"\nAll odd";// then vector has all odd number/elements
//return 1;
}
else
{
cout<<"\nnot even or odd";//else has odd and even numbers
//return 0;
}
}
int main()
{
vector<int> vec{ 4, 2, 4, 6, 8, 10};//declaration of a vector
IsVectorEven(vec);//check even number in vector
IsVectorOdd(vec);//check odd number in vector.
}