Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ program, Sorting Orders Write a program that uses two identical arrays of ei

ID: 3566782 • Letter: C

Question

C++ program, Sorting Orders

Write a program that uses two identical arrays of eight 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.

Please ALSO keep in mind the addition below! Especially the written description! Thanks!

Part 1: Please create the pseudocode and then code, debug and create the requisite submission files for Programming Challange #10 of your textbook on page 493. You can initialize the arrays in main when you declare them. You can pick the 20 numbers. You must use functions in this program - declare and initialize the arrays in main and then pass them to the two different sort functions and to the display function. No functions, no points. This exercise is designed to show you (visually) the difference between the two sorts. This part is 15/20 points

Part 2: A written description that describes to me HOW the sorts are working. I want you to put it into written words - you can reference the results in your program. Your description should be at least 8 sentences long. ("On the first pass through, the following numbers were swapped because.....") If you have completed this exercise, you should be able to give me a mini-lecture on how it worked. This part is 5/20 points.

Explanation / Answer

#include <iostream>

using namespace std;

void bubble_sort(int array[]) {

int n=8;

for (int c = 0 ; c < ( n - 1 ); c++)

{

for (int d = 0 ; d < n - c - 1; d++)

{

if (array[d] > array[d+1]) /* For decreasing order use < */

{

int swap = array[d];

array[d] = array[d+1];

array[d+1] = swap;

}

}

for(int i=0;i<8;i++)

cout<<array[i]<<" ";

cout<<endl;

}

}

void selection_sort(int num[])

{

int numel = 8;

int j, min, minidx, grade;

for(int i=0;i<numel-1;i++)

{

min = num[i]; // assume minimum is the first array element

minidx = i; // index of minimum element

for(j = i + 1; j < numel; j++)

{

if (num[j] < min) // if we

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote