Question
Use C++. Suppose that A points to an array of integers. In order to tell the end of the array, the last element of the
Use C++.
Suppose that A points to an array of integers. In order to tell the end of the array, the last element of the array if always +100000 (Assume that all the numbers in the array are smaller than +100000). create a function called int *countZeros(int *A), which searches in A for the occurrences of zeros. Each time you call the function, it returns a pointer to the next position of zero, if a zero appears next. Or it returns a nullptr. For the first call to countZeros, you need to pass A in. But for any subsequent calls you only need to pass nullprt in. As an example, suppose that A points to the following array:
subscript 0 1 2 3 4 5 6 7 8 9 10
element 0 -30 0 50 -40 60 0 40 30 0 100000
We can call the function countZeros as follows to see the number of zeros in the array.
int *pos;
int count = 0;
pos = countZeros(A);
while(pos !=nullptr) {
count++;
pos = countZeros(nullptr);
}
court << "There are " << count << " zeros in the array.";
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started