Question: Create a C++ program using dynamic arrays Requirements: create a 1D dynamic array of *ints (must use pointers) create a 2D dynamic array of *ints

Create a C++ program using dynamic arrays

Requirements:

create a 1D dynamic array of *ints (must use pointers) create a 2D dynamic array of *ints [?][2] (must use pointers) dynamically allocate space for the arrays

main() { 1.ask user how many elements in 1D array 2.ask user how many elements in 2D array 3. populate 1D array 4. populate 2D array 5. print 1D array 6. print 2D array 7. delete 1D array 8. delete 2D array

Extra Credit. ask for nxn. if user types 3 it will be 3x3 if 4 it will be 4x4

invalid input forced to 1 row }

int *array1D = NULL; int numElements; = 0; cin >> numElements;

Functions

// dynamically creates an int and prompts the user for the value // and it returns the pointer to this dynamic int.

int* createInt() // returns a pointer { return _______; }

void populate1DArray(1D array) { for loop createInt(); numberOfElements; }

void populate2DArray(2D array) { for loop rows for loop columns createInt(); } D =new *int[numElements]; / make sure numElements is at least 1

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!