1. Engineering
  2. Computer Science
  3. write a program that uses two identical arrays of eight...

Question: write a program that uses two identical arrays of eight...

Question details

Write a program that uses two identical arrays of eight randomly ordered integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using an ascending order selection sort, modified to print out the array contents after each pass of the sort.

This is the top portion of the code. There are at least 25 lines below this part.

const int SIZE = 8;

// Function prototypes
void bubbleSort(int [], int);  
void selectionSort(int [], int);
void showNums(int[], int);

int main()
{
    // Two identical arrays
    int array1[SIZE] = { 705, 98, 221, 400, 50, 62, 120, 80 };
    int array2[SIZE] = { 705, 98, 221, 400, 50, 62, 120, 80 };

    // Call function to sort the first array using bubble sort
    bubbleSort(array1, SIZE);

    // Call function to sort the second array using selection sort
    selectionSort(array2, SIZE);
    
    return 0;
}

/*************************************************************
*                       showNums                            *
* Called by: main and both sorts                            *
* Passed   : The array of numbers and the number of numbers *
*            to be sorted                                   *
* Purpose : Displays the current order of the numbers in   *
*            the array.                                     *
*************************************************************/
void showNums(int array[], int numElts)
{
    for (int pos = 0; pos < numElts; pos++)
        cout << setw(5) << array[pos];
    cout << endl;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution