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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started