asked 43.3k views
5 votes
Write a C++ function definition named containsNumber. The function should take three parameters: a one-dimensional integer array, the number of entries in the array, and an integer value. The function should search the array for the integer value and return a boolean value of true if the value is found and false otherwise. Below is a example call to the function:

valueFound = containsNumber(table, nbrOfEntries, value);

You may assume that all parameters passed to the function are valid, that the nbrOfEntries amount is always greater than or equal to one, and that a specific integer value occurs at most once in the table.

Remember to only write the function definition for the containsNumber function. Do not write a complete C++ program.

asked
User Nechelle
by
7.2k points

1 Answer

1 vote

Answer:

The following is a function definition for the contains Number function that can be used to search a one-dimensional integer array for a specific integer value:

bool containsNumber(int table [ ], int nbrOfEntries, int value)

{

for (int i = 0; i < nbrOfEntries; i++)

{

if (table[i] == value)

return true;

}

return false;

}

This function takes three parameters: a one-dimensional integer array, the number of entries in the array, and an integer value.

It then searches the array for the integer value and returns a boolean value of true if the value is found and false otherwise.

The function iterates through the array using a for loop and checks each value in the array against the specified integer value.

If a match is found, the function returns true, otherwise it returns false.

No related questions found