Lab # 1 Requirments Lab #1 Requirements. Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - 1. Write two primary helper functions - one iterative...

1 answer below »
My new lab assignment (lab #4) is based on my lab #1. I will attach my lab assignment one and professor feedback and lab 4 (current lab) and requirements.


Lab # 1 Requirments Lab #1 Requirements. Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - 1. Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which 1. Take an array and its size as input params and return a bool such that ■ 'true' ==> array and all elements are prime, ■ 'false' ==> at least one element in array is not prime, so array is not prime. 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 one other helper function (IsPrimeRecur) for the recursion which should also not contain any loops to make it a true recursive method. 6. Remember - replace with the actual name of each function. 7. Including your 'main', there will be a total of 4 functions in your program and 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. You can expect the user will input the number of elements for the array on one line, not to exceed SORT_MAX_SIZE = 16 (validate input). 2. Create an array based on the size input provided by the user. 3. On the next input line you can expect the user will provide all the array elements separated by spaces. Validate that the integers input by the user are between 1 and 9999, both inclusive. Remember: 1 is not a prime number. 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. 4. There will be only one code file in your submission. 5. Remember to take multiple screenshots so that they are clearly readable without needing to zoom in. 6. For documentation, include your name block as well pre/post and pseudocode for the 3 functions which are not 'main'. 7. Upload your code file and the screenshots in one zip file. Do not include anything else. Professore comments on my code: Comments: -15 (leniently) your code does not print the leaving statement at the right place in the recursive function, your recursive prime check doesn't have output statements. No deduction - your check for prime is not optimal. No deduction for the missing pre/post documentation this time. """ CIS 22C Summer Quarter Professor: Manish Goel Student: Tannaz Anvari ********** Started date: 06/29/2021 Updated dates: 06/30/2021, 07/01/2021, 07/02/2021 Final submission date: 07/03/2021 """ # Code With Explanation: #create the IsArrayPrimeIter function accepting an array and size of the array def IsArrayPrimeIter(array, size): #print entering message print("Entering IsArrayPrimeIter") #initialize variable isArrPrime to True isArrPrime = True #loop in every index of array for index in range(size): #get the number of the index number = array[index] #if the number is less than 2 if number < 2:="" #update="" isarrprime="" to="" false="" isarrprime="False" #break="" the="" loop="" break="" #create="" inner="" loop="" ranging="" from="" 2="" to="" number="" for="" num="" in="" range(2,="" number):="" #check="" remainder="" of="" number="" divided="" by="" num,="" if="" equal="" to="" 0="" if="" number="" %="" num="=" 0:="" #udate="" isarrprime="" to="" false="" isarrprime="False" #break="" the="" inner="" loop="" break="" #if="" isarrprime="" is="" false,="" break="" the="" outer="" loop="" if="" not="" isarrprime:="" break="" #print="" leaving="" message="" print("leaving="" isarrayprimeiter")="" #return="" isarrprime="" return="" isarrprime="" #create="" function="" isarrayprimerecur="" accepting="" the="" array="" and="" size="" of="" the="" array="" def="" isarrayprimerecur(array,="" size):="" #print="" entering="" message="" print("entering="" isarrayprimerecur")="" #initialize="" variable="" isarrprime="" to="" true="" isarrprime="True" #get="" the="" 1st="" value="" on="" the="" array="" assign="" it="" to="" variable="" num="" and="" remove="" it="" using="" pop(0)="" num="array.pop(0)" #update="" size,="" decrement="" 1="" from="" the="" size="" size="" -="1" #assign="" num-1="" to="" variable="" possible_factor="" possible_factor="num" -="" 1="" #check="" if="" num="" is="" prime="" using="" function="" isprimerecur,="" assign="" return="" value="" to="" isarrprime="" isarrprime="IsPrimeRecur(num," possible_factor)="" #if="" size="" is="" not="" yet="" 0="" and="" isarrprime="" is="" still="" true="" if="" size="" !="0" and="" isarrprime:="" #print="" leaving="" message="" print("leaving="" isarrayprimerecur")="" #call="" isarrayprimerecur="" again="" passing="" the="" updated="" value="" of="" array="" and="" size="" return="" isarrayprimerecur(array,="" size)="" #else="" else:="" #print="" leaving="" message="" print("leaving="" isarrayprimerecur")="" #return="" isarrprime="" return="" isarrprime="" #create="" the="" helper="" function="" isprimerecur="" accepting="" number="" and="" factor="" def="" isprimerecur(number,="" factor):="" #if="" number="" is="" less="" than="" 2="" if="" number="">< 2:="" #return="" false="" return="" false="" #if="" factor="" is="" equal="" to="" 1="" already="" if="" factor="=" 1:="" #return="" true="" return="" true="" #if="" the="" remainder="" of="" number="" divide="" by="" factor="" is="" zero="" if="" number="" %="" factor="=" 0:="" #return="" false="" return="" false="" #else="" else:="" #call="" isprimerecur="" passing="" the="" number="" and="" updated="" factor="" return="" isprimerecur(number,="" factor="" -="" 1)="" #create="" main="" function="" def="" main():="" #initialize="" sort_max_size="" to="" 16="" sort_max_size="16" #get="" size="" from="" user="" size="int(input("Enter" size="" of="" array:="" "))="" #if="" size="" is="" greater="" than="" sort_max_size="" or="" size="" is="" less="" than="" 1="" if="" size=""> SORT_MAX_SIZE or size < 1:="" #print="" invalid="" message="" print("size="" invalid.="" the="" size="" of="" array="" should="" be="" up="" to="" 16="" numbers!")="" #end="" program="" exit()="" #initialize="" empty="" array="" array="[]" #while="" the="" elements="" in="" array="" is="" less="" than="" size="" while="" len(array)="">< size:="" #get="" number="" from="" user,="" assign="" to="" num="" variable="" num="int(input('Enter" number:="" '))="" #if="" num="" is="" greater="" than="" 0="" and="" less="" than="" or="" equal="" to="" 9999="" if="" num=""><= 0="" or="" num=""> 9999: #print invalid value message print('Value invalid. Please enter value from 1 to 9999') #if not else: #add num to array array.append(num) # Printing Array list print("Array List: ", array) print() #if the return value of IsArrayPrimeIter() is True, print prime array if IsArrayPrimeIter(array, size): print('Prime Array using iteration\n') #otherwise, print that it is not prime else: print('Not a Prime Array using iteration\n') #if the return value of IsArrayPrimeRecur() is True, print prime array if IsArrayPrimeRecur(array, size): print('Prime Array using recursion') #otherwise, print that it is not prime else:
Answered 3 days AfterJul 22, 2021

Answer To: Lab # 1 Requirments Lab #1 Requirements. Write the simplest program that will demonstrate iteration...

Arun Shankar answered on Jul 24 2021
141 Votes
class LinkedNode:
# Constructor
def __init__(self, data):
self.data = data
self.next
= None
# Getters
def get_data(self):
return self.data
def get_next(self):
return self.next
# Setters
def set_data(self, data):
self.data = data
def set_next(self, next):
self.next = next
def __str__(self):
return str(self.data)
class SinglyLinkedList:
# Constructor
def __init__(self):
self.count = 0
self.start = self.end = None
# Getters
def get_count(self):
return self.count
def get_start(self):
return self.start
def get_end(self):
return self.end
# Setters
def set_count(self, count):
self.count =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here