// Program Debugging // Name:YUXUAN HU. // Explain here what the program is atte
ID: 3683759 • Letter: #
Question
// Program Debugging // Name:YUXUAN HU. // Explain here what the program is attempting to do... #include using namespace std; void SortThem(int [], double); void ShowArray(int [], double); int main() { const double SIZE = 6; double values[6] = (5, 7, 2, 8, 9, 1); int x = ShowArray(valueS, SIZE); SortThem(values, SIZE); ShowArray(values, SIZE); system("pause"); return 0; } // Explain briefly what the function is attempting to do... void sortThem(int array[], double elems) { int startScan, minIndex, minValue; for (startScan = 0; startScan < (elems - 1); startScan++) { minIndex = startScan; minValue = array[startScan]; for(int index = startScan + 1; index < elems; index++) { if (array[index] < minValue) { minValue = array[index]; minIndex = index; } } array[minIndex] = array[startScan]; array[startScan] = minValue; } // Explain briefly what the function is attempting to do... void showArray(int array[], double elems) { for (count = 0, count < elems, count++); cout << array(count) << " " << endl; cout << endl; return 0; }
Explanation / Answer
// There were many errors in the code. I fixed them completely
#include <iostream>
using namespace std;
void SortThem(int [], int);
void ShowArray(int [], int);
int main() {
const int SIZE = 6;
int values[6] = {5, 7, 2, 8, 9, 1};
int x;
ShowArray(values, SIZE);
SortThem(values, SIZE);
ShowArray(values, SIZE);
//system("pause");
return 0;
}
// Explain briefly what the function is attempting to do...
// This function is sorting the array passed in it by insertion sort
void SortThem(int array[], int elems) {
int startScan, minIndex, minValue;
for (startScan = 0; startScan < (elems - 1); startScan++) {
minIndex = startScan;
minValue = array[startScan];
for(int index = startScan + 1; index < elems; index++) {
if (array[index] < minValue) {
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
}
}
// Explain briefly what the function is attempting to do...
// this function is print the elements of the array
void ShowArray(int array[], int elems) {
for (int count = 0; count < elems; count++) cout << array[count] << " " << endl;
cout << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.