I need to write in C++ a complete boolean function that will take an integer array and it's maximum size as a parameter and return whether or not that array has any elements with a value of 0.
I'm not even sure where to start.
Thanks in advance.
Use std::find
#include <algorithm>
bool ContainsZero(int *arr, int size)
{
return std::find(arr, arr+size, 0) != (arr+size);
}
bool TestForZero(int* myArray, int maxSize)
{
for(int ii=0; ii<maxSize; ++ii)
if(myArray[ii] == 0)
return true;
return false;
}
This sounds an awful lot like a homework problem, so I'll just give you the concepts and let you learn.
You need to use a "for" loop, check the value of each item in the array, and return true if you find one, otherwise return false after the loop exits.