Question: For the search array I have this as my code: int searchArray(int A[], int size, int target){ for(int i = 0; i < size; i++){

For the search array I have this as my code:

int searchArray(int A[], int size, int target){ for(int i = 0; i < size; i++){ if(A[i] == target){ return i; } return -1; } }

in the int main i have

cout<<"What value would you like to search for?"<>target; int element = searchArray(A, size, target); if(element == (-1)){ cout<<"The value does not exist."<

When I run the code it will only find what is in the A[0]. If i try to find what is in the others it says they do not exist. I try to search for numbers in other positions that I know are there but it will still say that it does not exist. If you could please help me that would be greatly appreciated.

For this assignment, you should use the "printArray" and "userFill" functions developed in class (which allow a user to easily fill and array from the console and print the array out) and also write 2 new functions: searchArray and sortArray.

Here are the prototypes and description of each function:

void sortArray(int array[], int size)

This takes an array and it's size and sorts the array. Nothing is returned since arrays are passed by reference automatically.

int searchArray(int array, int size, int target)

This takes an array, it's size, and a value (target) to be searched for in the array. If target is found, it's position (between 0 and size-1) is returned, if target is not found, -1 is returned.

Further Notes

You should also have a main function that allows the user to fill an array, prints the sorted array and allows the user to search for a value and returns the result.

You may choose the search and sort algorithms used, but you can't use bogoSort.

Be sure to include comments in your code, in particular you should describe the search and sort algorithms used.

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!