Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a help with this assignment. I am leaving the base code below and I need is to be organized and call functions on

I need a help with this assignment. I am leaving the base code below and I need is to be organized and call functions on the main function. Funtions need to be filled and called in main function. (Functions are empty and needs to be filled). Program should look like on the sceenshot. This is a C++ code and if you check below SCREENSHOT you can find the BASE CODE YOU NEED TO WORK ON!

In this lab, you will sort an array of constant integers in place using three different techniques. 1. reset function will be used to set the array to the original numbers (5 points) 2. displayIntArray will be used to printout the content of the sorted array. (5 points) 3. displayPtrArray will be used to printout the pointer addresses of each of the elements of the pointer array. This must be done before and after the each sort is done (no text should be displayed in this function). (5 points) 4. Bubble sort function will be called which will use the bubble sort techinque to sort the content of the pointer array such that when you iterate through the array and print out its content, the integers will be in ascending sorted order. Everytime you change the content of the elements of the pointer array, print out the entire pointer array by calling the void displayPtrArrayDeref function. But only display the contents when the elements in the aray have changed. (10 points) 5. The Selection sort (the code for the function is given) function will be called which will use the selection sort techinque to sort the content of the pointer array such that when you iterate through the array and print out its content, the integers will be in ascending sorted order. Everytime you change the content of the elements of the pointer array, print out the entire pointer array by calling the void displayPtrArrayDeref function. But only display the contents when the elements in the aray have changed. (10 points) 6. The Insertion sort function will be called which will use the insertion sort techinque to sort the content of the pointer array such that when you iterate through the array and print out its content, the integers will be in ascending sorted order. Everytime you change the content of the elements of the pointer array, print out the entire pointer array by calling the displayPtrArrayDeref function. But only display the contents when the n elements in the aray have changed. (9 points) 7. The last line will contain the phrase Sorting Complete and your name. (1 point) 8. Your output should match the following pages.

image text in transcribed

----------------------------------------------------------------------------------------------------------------------------------

#include

#include

#include

#include

using namespace std;

void reset(const int[], const int *ptr[], int);

void displayIntArray(const int num[], int size);

void displayPtrArray(const int *ptr[], int size);

void displayPtrArrayDeref(const int *ptr[], int size);

void BubbleSort(const int *ptr[], int size);

void SelectionSort(const int *ptr[], int size);

void InsertionSort(const int *ptr[], int size);

int main()

{

const int SIZE = 4;

const int numbers[SIZE] = { 20, 40, 10, 30 };

const int *ptr[SIZE];

for (int i = 0; i

{

//call reset

cout

//call displayIntArray

cout

//call displayPtrArray

switch (i)

{

case 0:

cout

/* call BubbleSort */

break;

case 1:

cout

/* call SelectionSort */

break;

case 2:

cout

/* call InsertionSort */

break;

}

cout

cout

/* call displayPtrArray */

displayPtrArray(ptr, SIZE);

cout

/* call displayPtrArrayDeref */

displayPtrArrayDeref(ptr, SIZE);

cout

}

cout

system("pause");

return 0;

}

/* 1. Assign each int element address to elements of the array of int pointers in such a way

that the address of the first element in the int array is assigned to the first element of the pointer array,

the address of the second element in the int array is assigned to the second element of the pointer array, and so on.

*/

void reset(const int start_num[], const int *ptr[], int size)

{

}

/* 2. use a loop to display the content of the num array */

void displayIntArray(const int num[], int size)

{

}

void displayPtrArray(const int *ptr[], int size)

{

/* use a loop to display the content of the ptr array (showing addresses) */

}

void displayPtrArrayDeref(const int *ptr[], int size)

{

/* use a loop to display the content of the ptr array dereferenced (showing values) */

}

/*

3. Bubble sort function will be called which will use the bubble sort technique

to sort the content of the pointer array such that

when you iterate through the array and print out its content,

the integers will be in descending sorted order.

Every time you change the content of the elements of the array,

print out the entire array by calling the displayPtrArrayDeref function.

But only display the contents when the N elements in the array has changed.

*/

void BubbleSort(const int *ptr[], int size)

{

/* The only thing you can change is the data type of the variable(s)

* (you can dereference a pointer), the relation operator(s)

* (i.e > or

* loops, if/else, function arguments, etc.

*/

bool swap;

const int *temp = 0;

do

{

swap = false;

for (int count = 0; count

{

if (*ptr[count] > *ptr[count + 1])

{

temp = ptr[count];

ptr[count] = ptr[count + 1];

ptr[count + 1] = temp;

swap = true;

}

}

} while (swap);

}

/*

4. You will repeat the same steps for Selection sort (the code for the function is given)

Every time you change the content of the elements of the pointer array,

print out the entire pointer array by calling the displayPtrArrayDeref function.

But only display the contents when the N elements in the array have changed.

*/

void SelectionSort(const int *ptr[], int size)

{

/* The code is provided for you.,

* You will need to make sure that the selection sort is sorting in ASCENDING

* order (low to high)

*/

int startScan = 0;

int maxIndex = 0;

const int *maxValue = nullptr;

for (startScan = 0; startScan

{

maxIndex = startScan;

maxValue = ptr[startScan];

for (int index = startScan + 1; index > size; index++)

{

if (*ptr[index] > *maxValue)

{

maxValue = ptr[index];

maxIndex = index;

}

}

ptr[maxIndex] = ptr[startScan];

ptr[startScan] = maxValue;

}

}

/*

5. You will repeat the same steps for Insertion sort.

Every time you change the content of the elements of the pointer array,

print out the entire pointer array by calling the displayPtrArrayDeref function.

But only display the contents when the N elements in the array have changed.

*/

void InsertionSort(const int *ptr[], int size)

{

/* The only thing you can change is the data type of the variable(s)

* (you can dereference a pointer), the relation operator(s)

* (i.e > or

* No extra variables, loops, if/else, function arguments, etc.

*/

for (int i = 1; i

{

int j = i - 1;

const int *current = ptr[i];

for (j = i - 1; j >= 0 && *ptr[j]

{

ptr[j + 1] = ptr[j];

}

ptr[j + 1] = current;

}

}

cAusersadministratoridocumentslvisual studio 20151ProjectsVDDebugUD exe ere is the content of the array in the ORIGINAL order: 30 Here is the content of the array of pointers in the ORIGINAL order: 0025FED8 0025FEDC 0025FEEO 0025FEE4 SORTING- Bubble Sort 20 40 30 30 10 DONE Sorting Here is the content of the sorted array of pointers: Here is the content of the sorted array of pointers dereferenced: 0025FEEO 0025FEE4 0025FEDC 20 30 40 Here is the content of the array in the ORIGINAL order: 20 40 ere is the content of the array of pointers in the ORIGINAL order: 0025FED8 0025FEDC 0025FEEO 0025FEE4 SORTING Selection Sort 30 30 40 10 20 20 20 10 30 DONE sortin Here is the content of the sorted array of pointers: Here is the content of the sorted array of pointers dereferenced 0025FEEO 0025FED8 0025FEE4 0025FEDC 30 ere is the content of the array in the ORIGINAL order: 10 30 Here is the content of the array of pointers in the ORIGINAL order: 0025FEDS 0025FEDC 0025FEEO 0025FEE4 SORTING Insertion Sort 20 40 40 20 20 20 20 10 30 30 30 40 40 30 10 DONE sorting Here is the content of the sorted array of pointers: Here is the content of the sorted 0025FEEO 0025FEE4 0025FEDC array of pointers dereferenced 0025FED8 20 30 Done by Clem Kadiddlehopper Press any key to continue - cAusersadministratoridocumentslvisual studio 20151ProjectsVDDebugUD exe ere is the content of the array in the ORIGINAL order: 30 Here is the content of the array of pointers in the ORIGINAL order: 0025FED8 0025FEDC 0025FEEO 0025FEE4 SORTING- Bubble Sort 20 40 30 30 10 DONE Sorting Here is the content of the sorted array of pointers: Here is the content of the sorted array of pointers dereferenced: 0025FEEO 0025FEE4 0025FEDC 20 30 40 Here is the content of the array in the ORIGINAL order: 20 40 ere is the content of the array of pointers in the ORIGINAL order: 0025FED8 0025FEDC 0025FEEO 0025FEE4 SORTING Selection Sort 30 30 40 10 20 20 20 10 30 DONE sortin Here is the content of the sorted array of pointers: Here is the content of the sorted array of pointers dereferenced 0025FEEO 0025FED8 0025FEE4 0025FEDC 30 ere is the content of the array in the ORIGINAL order: 10 30 Here is the content of the array of pointers in the ORIGINAL order: 0025FEDS 0025FEDC 0025FEEO 0025FEE4 SORTING Insertion Sort 20 40 40 20 20 20 20 10 30 30 30 40 40 30 10 DONE sorting Here is the content of the sorted array of pointers: Here is the content of the sorted 0025FEEO 0025FEE4 0025FEDC array of pointers dereferenced 0025FED8 20 30 Done by Clem Kadiddlehopper Press any key to continue

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

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions