Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm struggling really bad please help #include using std::cin; using std::cout; using std::cerr; using std::endl; #include using std::bad_alloc; #include #define int_array 1 #define pointer2int_array 2

I'm struggling really bad please help

#include using std::cin; using std::cout; using std::cerr; using std::endl;

#include using std::bad_alloc;

#include

#define int_array 1 #define pointer2int_array 2

// Prototype declarations

int getSize();

void* getArray( int &howMuch, int typeOf );

void populateArray( int num_of, int* ptr );

/* prototypes for swap function your sort function a function called printSortedArray which will print the sorted pointer array */

/////////////////////////// -- main -- ///////////////////////////////////////////////////////

int main() {

int SIZE = getSize();

int* dataArray = ( int*) getArray(SIZE, int_array ); int** pointerArray = ( int**)getArray(SIZE, pointer2int_array );

/* TODO add code here, call the appropriate functions */ // using a for loop, print the dataArray here

delete [] dataArray; delete [] pointerArray;

cout

return ( 0 );

}

//////////////////////////////// -- end main -- ////////////////////////////////////////////////

/*************************************************************************************************** * * Function Name: getSize * * Purpose: requests an integer from user * * Input Parameters: none * * Output parameters: none * * Return Value: retuns the user entered integer howMuch * ***************************************************************************************************/

int getSize() { int howMuch; cout > howMuch; return howMuch;

}

/*************************************************************************************************** * * Function Name: getArray * * Purpose: dynamically allocates either an array of ints or an aaray of * int pointers * * Input Parameters: an int howMuch - the size of array to allocate * an int typeOf indicating the type of array to allocate * * Output parameters: none * * Return Value: returns a pointer to an int array or an array of int pointers * ***************************************************************************************************/

void* getArray( int &howMuch, int typeOf ) {

try { switch ( typeOf ) { case int_array: { int* p = new int [ howMuch ]; return( p ); }

case pointer2int_array: { int** p = new int* [ howMuch ]; return( p ); } default: { cerr

} } catch ( bad_alloc &memoryAllocationException ) { cerr

}

/*************************************************************************************************** * * Function Name : * * Purpose : * * Input Parameters : * * Output parameters : * * Return Value : * ***************************************************************************************************/

void populateArray( int num_of, int* ptr ) {

}

image text in transcribed

PROBLEM STATEMENT: Write a program that will initialize an array, sort the array into ascending order, print the ascending, and original lists. CODE: The program must not change the original array or create any other integer arrays. The solution requires an array of pointers to the array of integers. The pointers will be ordered according to the sequence of the values to which they refer. This array can then be processed from low to high or high to low for the ascending and descending lists respectively. Use any sort method form cs 121 that you learned: selection, insertion or bubble sort start with/use the provided cs 132lab2_driver.cpp - (must be used) Complete the implementation for the given functions. Create the appropriate functions Make sure to complete the function comment headings. Run the program for the following: 26,14,57,33,41,60,19 The program will sort the array into ascending order. It will print the ascending and original lists. Run the program a second time for the following: 14 57 19 60 41 26 33 -34, -666, 666

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions