In this program you will create dynamic one dimensional and dynamic two-dimensional arrays. Use the example from 9-19 in Starting Out with C++ from Control Structures to Objects (8th Edition) and follow the instructions:
a) Type up the example and make sure that it works as it does in the text. (You don’t have to type up the comments, but you must include the functions.)
b) Modify the example so that:
i. The user can enter ANY number of donations
ii. The user enters the values of the donations
The code MUST perform in the same way that it did in the example – i.e. given any number of donations, and the values of those donations, the code should output the original values and their sorted values
1) Remove the constant (‘NUM_DONATIONS’) that determines the size of the array. Replace it with a variable (like ‘number’) that will receive the number of donations from the user.
2) Prompt the user for the number of donations they have. Store the value entered in ‘number’.
3) Remove the ‘donations’ array and its initial values. You will be replacing this with a dynamic dimensional array. To do this, use the following steps:
a) Declare a pointer, ‘dp’
b) Use this pointer to create a dynamic array of values (see example 9-14, line 22). You will need to use the ‘number’ to determine the size of the new array.
4) Prompt the user to enter their donation values. Enter the values into the dynamic array using a for loop.
5) Remove the array of pointers to an int. You will be replacing this with a dynamic 1 dimensional array of pointers! To do this, use the following steps:
a) Declare another pointer, ‘parr’. However, this pointer needs to be a pointer to a pointer.
b) Use this pointer to create a dynamic array of pointers
6) Delete the dynamic arrays that both pointers are accessing
Sample output for question 1:
How many donations were made? 3
Enter the 3 donations now: 150 25 50
The donations, in their original order are:
150 25 50
The donations, sorted in ascending order are:
25 50 150
Do you want to run this program again?
Press y/Y for yes or n/N for no: n
Press any key to continue . . .
1) You can keep the names of constants even if they are in all caps; just remove the const keyword.
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
// This program shows the donations made to the United Cause
// by the employees of CK Graphics, Inc. It displays
// the donations in order from lowest to highest
// and in the original order they were received.
using namespace std;
#define nullptr NULL
// Function prototypes
void arrSelectSort(int *, int);
void showArray(const int , int);
void showArrPtr(int *, int);
// Creating the integer for number of inputs
cout << "How many donations were made? ";
cin >> number; // Load the number from keyboard
//Creating the dynamic array of values
int *pt = nullptr; //Create the dp pointer
pt = new int[number]; //Allocate the dynamic array in memory and set dp to point to it
//Prompting for entering the numbers from kezboard
for (int count = 0; count < number; count++)
//cout << "Donation " << count + 1 << ": ";
cin >> pt[count];
//Creating the dynamic array of pointers
int **parr; //Create pointer to pointer to value
parr = new int*[number]; //Allocate the dynamic array of pointers in memory...
This is only a preview of the solution. Please use the purchase button to see the entire solution