Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

Write your code incrementally! Compile, run, and test your code one function at a time.

A function prototype should be written for each function and placed BEFORE the main

procedure.

All functions should be written AFTER the main procedure.

Each function should have a comment explaining what it does.

Each function parameter should have a comment explaining the parameter.

You must implement the following algorithm in the main procedure to formulate your solution.Follow these instructions exactly, including specifications for functions, to receive full credit:

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 Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago