Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

// 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 #include using namespace std;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

What is IUPAC system? Name organic compounds using IUPAC system.

Answered: 1 week ago

Question

What happens when carbonate and hydrogen react with carbonate?

Answered: 1 week ago