Question
This is a C++ programming problem. // Fig. 8.13: fig08_13.cpp // Selection sort with pass-by-reference. This program puts values into an // array, sorts them
This is a C++ programming problem.
// Fig. 8.13: fig08_13.cpp // Selection sort with pass-by-reference. This program puts values into an // array, sorts them into ascending order and prints the resulting array. #include
void selectionSort( int * const, const int ); // prototype void swap( int * const, int * const ); // prototype
int main() { const int arraySize = 10; int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
cout
for ( int i = 0; i
selectionSort( a, arraySize ); // sort the array
cout
for ( int j = 0; j
cout
// function to sort an array void selectionSort( int * const array, const int size ) { int smallest; // index of smallest element
// loop over size - 1 elements for ( int i = 0; i
// loop to find index of smallest element for ( int index = i + 1; index
if ( array[ index ]
swap( &array[ i ], &array[ smallest ] ); } // end if } // end function selectionSort
// swap values at memory locations to which // element1Ptr and element2Ptr point void swap( int * const element1Ptr, int * const element2Ptr ) { int hold = *element1Ptr; *element1Ptr = *element2Ptr; *element2Ptr = hold; } // end function swap
The objective of this homework is to give you experience usingfunction templates with C You will use the provided code in file: fig08 13.cpp as a starting point. The file is located in the Source Code folder on Learn For this assignment, you will write a function template selectionsort based on the code in figure 8.13 Write a driver program that inputs, sorts, and outputs an int array and a float array. Execute your test program and copy the outputs to a text file to demonstrate proper execution. What to submit Please submit a copy of your source code file and a text file(s) that includes execution output that demonstrates proper operation
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