Question: #include using namespace std; int searchList( int[], int, int); // function prototype const int SIZE = 16; int main() { int nums[SIZE] = {34,19,19,18,17,13,12,12,12,11,9,5,3,2,2,0}; int

#include using namespace std;

int searchList( int[], int, int); // function prototype const int SIZE = 16;

int main() { int nums[SIZE] = {34,19,19,18,17,13,12,12,12,11,9,5,3,2,2,0}; int found; int num; do{ cout << "Enter an integer to search for (-9999 to exit):" << endl; cin >> num; if(num!=-9999){ found = searchList(nums, SIZE, num); if (found == -1) cout << "The letter " << num << " was not found in the list" << endl; else cout << "The first instance of the integer " << num <<" is in the " << found + 1 << " position of the list" << endl;} }while(num!=-9999); return 0;

}

//******************************************************************* // searchList // // task: This searches an array for a particular value // data in: List of values in an array, the number of // elements in the array, and the value searched for // in the array // data returned: Position in the array of the value or -1 if value // not found // //*******************************************************************

int searchList( int List[], int numElems, int value) { for (int count = 0;count < numElems; count++) { if (List[count] == value) // each array entry is checked to see if it contains // the desired value. return count; // if the desired value is found, the array subscript // count is returned to indicate the location in the array } return -1; // if the value is not found, -1 is returned }

Add code to output the number of lookups (i.e. search comparisons) the program

performs. Show the number of lookups for the following sample test data: 19, 13, 2, 55.

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!