Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code in C++ language Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - 1. Write two primary helper

Please code in C++ language

image text in transcribed

Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - 1. Write two primary helper functions - one iterative (IsArrayPrimelter) and one recursive (IsArray PrimeRecur) - each of which 1. Take the array and its size as input params and return a bool. 2. Print out a message "Entering " as the first statement of each function. 3. Perform the code to test whether every element of the array is a Prime number. 4. Print out a message "Leaving " as the last statement before returning from the function. 5. Remember - there will be nested loops for the iterative function and there can be no loops at all in the recursive function. You will need to define other helper functions to make the recursive method work. 6. Remember - replace with the actual name of each function. 7. You can create secondary helper functions if you need, but only the primary helper functions can be invoked from 'main. Note - for all functions except 'main', the 'Entering ' and 'Leaving statements should be printed. 8. Hint - try to complete your iterative code first and then convert it piece by piece to the recursive code. 2. In your main: 1. Ask the user for the number of elements, not to exceed SORT_MAX_SIZE = 16 (validate input). 2. Create an array based on the size input provided by the user. 3. Get the input in a loop, validating that the integers input by the user are between 1 and 99, both inclusive 4. Make a call to the primary iterative function passing the array and its size. 5. If every member is a Prime, then the program should print out 'Prime Array using iteration, otherwise print out 'Not a Prime Array using iteration. 6. Then make a call to the primary recursive function passing the array and its size. 7. If every member is a Prime, then the program should print out 'Prime Array using recursion', otherwise print out 'Not a Prime Array using recursion! 8. If your functions are coded correctly, both should come up with the same answer, except you should have lots more output statements using recursion. 9. There is no sample output - you are allowed to provide user interactivity as you see fit but programs will be graded for clarity of interaction. 3. You can use language native arrays - DO NOT USE VECTORS, COLLECTIONS, SETS, BAGS or any other data structures from your programming language

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 Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions