Write a program which reads a list of numbers into an array, splits the list int
ID: 3659279 • Letter: W
Question
Write a program which reads a list of numbers into an array, splits the list into a list of even numbers and a list of odd numbers, each in their separate arrays, and then outputs the arrays of even and odd numbers. The program should use the command new to allocate arrays of exactly the correct size. The program should have a procedure count() for counting the number of even elements and the number of odd elements of an array, a procedure split() for splitting the list into even and odd lists, and a procedure print_array() for printing an array of numbers. 1. A function/procedure prototype should be written for each procedure and placed BEFORE the main function. 2. All procedures should be written AFTER the main function. 3. Prompt the user for the number of elements that will be in the list. 4. Allocate an array with a size equals the number of elements specified by the user. 5. Read into the array the elements of the list. Look at the code in your notes for examples of how this is done. 6. Write a procedure count() which counts the number of even elements and the number of odd elements of an array. The procedure should take four parameters: the array, the number of elements in the array, the number of even elements and the number of odd elements. The procedure sets the number of even and odd elements but does not return any value. 7. In the main function, write the call for the procedure count() to set the number of even elements and the number of odd elements of the array. 8. Allocate an array with its size equal to the number of even elements. 9. Allocate an array with its size equal to the number of odd elements. 10. Write a procedure split() which takes as input 3 arrays, A, B and C, and stores the even elements of A in B and the odd elements of A in C. Use better array names than A, B and C. The size of array B should be exactly the number of even elements in array A. The size of array C should be exactly the number of odd elements in array A. As you copy elements from A to B or C, count the number of elements copied to each array. When the procedure completes, check that the number copied equals exactly the array size. If it does not, print an error message and exit. The procedure should take six parameters: array A, the size of array A, array B, the size of array B, array C, and the size of array C. The procedure modifies arrays B and C but does not return any value. 11. Write a procedure print_array() which prints the elements of an array. The procedure should take two parameters: the array and the array length. The procedure does not modify or return any values. 12. In the function main, write the call for the procedure split(), passing the input array and the arrays whose sizes equal the number of even and odd elements. 13. In the function main, print the phraseExplanation / Answer
#include #include using namespace std; int b[100],c[100];int p=0,q=0; void count(int a[]) { int i; while(a[i]!=NULL) i++; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.