(Numerical) a. Define an array with a maximum of 20 integer values, and fill the
ID: 3640206 • Letter: #
Question
(Numerical) a. Define an array with a maximum of 20 integer values, and fill the array with numbers input from the keyboard or assigned by the program. Then write a function split() that reads the array and places all zeros or positive numbers in an array named positive and all negative numbers in an array named negative. Finally, have your program call a function that displays the values in both the positive and negative arrays.b. Extend the program written for Exercise a to sort the positive and negative arrays into ascending order before they are displayed.
Explanation / Answer
#include #include #include using namespace std; int* split(int* theArray, int* positive, int* negative) { int negIndex = 0; int posIndex = 0; int sizes[2]; for(int i = 0; i < 20; ++i) { if(theArray[i] < 0) { negative[negIndex] = theArray[i]; ++negIndex; } else if(theArray[i] >= 0) { positive[posIndex] = theArray[i]; ++posIndex; } } //For printing purposes sizes[0] = posIndex; sizes[1] = negIndex; return sizes; } void printArray(int* positive, int* negative, int* sizes) { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.