Question: in C++ use Sort function: void sort(double x[], int n) { // Declare objects. int m; double hold; // Implement selection sort algorithm for (int

in C++

use Sort function:

void sort(double x[], int n)

{

// Declare objects.

int m;

double hold;

// Implement selection sort algorithm

for (int k = 0; k <= n-2; ++k)

{

// Find position of smallest value in

// array beginning at k

m=k;

for (int j = k + 1; j <= n - 1; ++j)

{

if (x[j] < x[m])

m = j;

}

// Exchange smallest value w/value at k

hold = x[m];

x[m] = x[k];

x[k] = hold;

}

// void return

return;

}

Write a main function that create an array of integers called grades with contents {100, 95, 87, 92, 79}. Then it prompts the user to enter a number and searches the array for that number. If the number is in the array, it prints out to the user the position it found it at. If the number is not in the array, it prints out that it did not find it.

For example, if the user enters 7, the program will print out "Sorry, 7 was not found". If the user enters 95, the program will print out "Success. Found 95 at position 1 of 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!