Question: Need help with this C++ assignment... I have the following program and need the changes below... //Program shows donations made to a charity by employees

Need help with this C++ assignment... I have the following program and need the changes below...

//Program shows donations made to a charity by employees of a company. //It displays the donations in order from lowest to highest and in //the original order they were rec'd.

#include using namespace std;

//Function prototypes void arrSelectSort(int *[], int); void showArray(const int [], int); void showArrPtr(int *[], int);

int main() {

const int NUM_DONATIONS = 15;

//An array containing donation amounts. int donations[NUM_DONATIONS] = { 5, 100, 5, 25, 10, 5, 25, 5, 5, 100, 10, 15, 10, 5, 10};

//An array of pointers to int. int *arrPtr[NUM_DONATIONS]={nullptr, nullptr, nullptr,nullptr,nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,};

//Each element of arrPtr is a pointer to int. Make each elements point //to an element in the donations array. for(int count = 0; count < NUM_DONATIONS; count++) arrPtr[count] = &donations[count];

//Sort the elements of the array of pointers. arrSelectSort(arrPtr, NUM_DONATIONS);

//Display the donations using the array of pointers. It will display //in sorted order. cout << "The donations, sorted in ascending order are: "; showArrPtr(arrPtr, NUM_DONATIONS); cout << " ";

//Display the donations in their original order. cout << "The donations, in their original order are: "; showArray(donations, NUM_DONATIONS); return 0; } //Definition of function arrSelectSort which performs ascending order //selection sort on arr, which is an array of pointers. Each elements of //array points to an element of a second array. After the sort, arr will //point to the elements of the second array in ascending order.

void arrSelectSort(int *arr[], int size) { int startScan, minIndex; int *minElem; for (startScan = 0; startScan < (size - 1); startScan++) { minIndex = startScan; minElem = arr[startScan]; for(int index = startScan + 1; index < size; index++) { if (*(arr[index]) < *minElem) { minElem = arr[index]; minIndex = index; } } arr[minIndex] = arr[startScan]; arr[startScan] = minElem; } } //Definition of function showArray. //This function displays the contents of arr. size is no. of elements. void showArray(const int arr[], int size) { for (int count = 0; count < size; count++) cout << arr[count] << " "; cout << endl; }

//Definition of showArrPtr which displays contents of array pointed to //by arr. size is no. of elements. void showArrPtr(int *arr[], int size) { for (int count = 0; count < size; count++) cout << *(arr[count]) << " " ; cout << endl; }

Homework IXA Your program uses a selection sort in order to sort the array of pointers. Your assignment is to rewrite the selection sort in your program so that it is a Bubble Sort which sorts the array of pointers. Call this new function, which will replace arrSelectionSort(int *[ ], by the name: arrBubbleSort(int *[ ], int). But otherwise, do not change anything in the rest of the program.

Homework IXB Using your program, once again, make changes to it so that it is able to handle strings and so is able to sort the words of a Poem in alphabetical order. What you will do is to replace the array:

int donations[NUM_DONATIONS] = { 5, 100, 5, 25, 10, 5, 25, 5, 5, 100, 10, 15, 10, 5, 10 }; With the array:

string donations[NUM_DONATIONS] = { "The", "Woods", "Are", "Lovely", "Dark", "And", "Deep", "But", "I", "Have", "Promises", "To", "Keep", "Robert", "Frost" };

Then you will make whatever additional changes are necessary to that program so that it is able to do this sort of pointers to strings, instead of pointers to int. You may use either the selection sort in program 9-19, or the Bubble Sort that you wrote for Homework IXA.

Make one more change to the output of the program. Where the original program printed the two lines: The donations, sorted in ascending order are: The donations, in their original order are:

Replace these lines with the words: The words, sorted in ascending order are: The words, in their original order are:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!