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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!