Question: 7. Case Study Modification #2 Modify Program 9-19 (the United Cause case study program) so the arrptr array is sorted in descending order instead of
7. Case Study Modification #2 Modify Program 9-19 (the United Cause case study program) so the arrptr array is sorted in descending order instead of ascending order. also please add as much comments as possible so i can understand what you did
the c++
//system libraries #include
using namespace std; //user libraries
//global constants only
//Functions prototypes here void arrSele(int *, int); void showArr(const int [], int); void showAPt(int *, int); //Program execution start here int main(int argc, char** argv) { //Declare variables here int num_don;
cout << "Enter the number of donations: "; cin >> num_don;
int *donatio = new int[num_don];
int i = 0; while(i < num_don) { cout << "Enter the donation #" << (i + 1) << ": "; cin >> donatio[i];
i++; } cout << endl;
int *arrPtr = new int[num_don]; //declare dynamic array variable to get the number of donation //input
//process for (int count = 0; count < num_don; count++) arrPtr[count] = donatio[count];
arrSele(arrPtr, num_don);
cout << "The donations, sorted in ascending order, are: "; showAPt(arrPtr, num_don);
cout << "The donations, in their original order, are: "; showArr(donatio, num_don); //output
//Exit return 0; } //to sort the dynamic array //function definitions void arrSele(int *arr, int size) { int startS, minInde; int minElem;
for (startS = 0; startS < (size - 1); startS++) { minInde = startS; minElem = arr[startS]; for(int index = startS + 1; index < size; index++) { if ((arr[index]) < minElem) { minElem = arr[index]; minInde = index; } } arr[minInde] = arr[startS]; arr[startS] = minElem; } }
void showArr(const int arr[], int size) { for (int count = 0; count < size; count++) cout << arr[count] << " "; cout << endl; }
void showAPt(int *arr, int size) { for (int count = 0; count < size; count++) cout << arr[count] << " "; cout << endl; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
