Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

for C++ Write a program in a new file called split.cpp which reads a list of numbers into an array, splits the list into a

for C++

Write a program in a new file called split.cpp 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 and how many zeros were encountered in the input array. The program should use the command new to allocate arrays of exactly the correct size.

The program should have a function count() for counting the number of even elements, the number of odd elements, and the number of zeros, a function split() for splitting the list into even and odd lists, and a function print_list() for printing an array of numbers.

In the main procedure, prompt for the number of elements of the input list.

Allocate an array, using a pointer variable, whose size equals the number of elements

specified by the user.

Read into the array the elements of the list.

Write a function count() which counts the number of even elements, the number of odd elements, and the number of zeros of an input array. The function must take four input parameters, the input array, the number of elements in the input array, the number of even elements (int), the number of odd elements(int). The function returns the number of zeros found in the input array (int). The function sets the number of even and odd elements.

In the main procedure, call the function count() to get the number of even elements, the number of odd elements, and the number of zeros in the array.

In the main procedure, allocate an array, using a pointer variable, whose size equals the number of even elements.

In the main procedure, allocate an array, using a pointer variable, whose size equals the number of odd elements.

Write a function 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 A.

As you copy elements from A to B or C, count the number of elements copied to each array. When the function completes, check that the number copied equals exactly the array size. If it does not, print an error message and exit.

The function 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. Determine where to use const in your definitions.

The function modifies arrays B and C but does not return any value.

Write a function print_list() which prints the elements of an array passed into the function. The function should take two parameters, the array and the array length. The function does not modify or return any values.

In the main procedure, call the function split(), passing the input array and the arrays whose sizes equal the number of even and odd elements.

In the main procedure, print the phrase Even elements: . Print the array of even elements using the function print_list().

In the main procedure, print the phrase Odd elements: . Print the array of odd elements using the function print_list().

In the main procedure, free the three dynamically allocated arrays. (Points will be deducted if you do not free the arrays).

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

2. Describe how technology can impact intercultural interaction.

Answered: 1 week ago

Question

7. Define cultural space.

Answered: 1 week ago