1. Consider the following arrays with the contents given (you have to declare them in your program).
Array1:
3 8 13 12 20 25 19 17 30 13
Array2:
10 blocks of no numbers
Array3:
E0A1+E9A2 E1A1+E8A2 E2A1+E7A2
Blocks 4 to 9 have nothing stored
Block 10 has E9A1+E0A2
a. Convert each of the even number in Array1 to its immediate next higher odd number and each of the odd number in the array to its immediate lower even number. This conversion will be done in a subroutine named Modifier. The modification will be done using logic so that the modifier works for any data in the given array. Before modifications, all the data in the array needs to be saved in the stack so that in future we can use the original data again.
b. Now, populate Array 2 with the saved data in the stack. Multiply each of the data (only the even numbers) by 4. This modification will be done by another subroutine named Incrementor.
c. Now populate Array3 such that element 0 of Array3 is the summation of element 0 0f Array1 and element 9 of Array2. Element 1 0f Array3 is the sum of element 1 of aArray1 and element 8 0f Array2 and so on.
d. Finally, send the content of element 0 of Array3 to PORT 0 of the trainer kit.
3 answers
```python
def Modifier(arr):
stack = [] # Stack to save original data
for i in range(len(arr)):
if arr[i] % 2 == 0: # Even number, convert to lower even number
arr[i] -= 1
else: # Odd number, convert to higher odd number
arr[i] += 1
stack.append(arr[i]) # Save original data in stack
return arr, stack
def Incrementor(stack):
arr2 = [0] * 10 # Initialize Array2 with 10 blocks of no numbers
for i in range(len(stack)):
if stack[i] % 2 == 0: # Even number, multiply by 4
arr2[i] = stack[i] * 4
return arr2
def populateArray3(arr1, arr2):
arr3 = []
for i in range(len(arr1)):
if i < len(arr2):
arr3.append(arr1[i] + arr2[i])
return arr3
def sendToPort0(element):
print("Sending content of element 0 of Array3 to PORT 0:", element)
# Array1
arr1 = [3, 8, 13, 12, 20, 25, 19, 17, 30, 13]
# a. Modifier
modified_arr1, stack = Modifier(arr1)
print("Modified Array1:", modified_arr1)
print("Stack:", stack)
# b. Incrementor
arr2 = Incrementor(stack)
print("Array2:", arr2)
# c. Populate Array3
arr3 = populateArray3(modified_arr1, arr2)
print("Array3:", arr3)
# d. Send content of element 0 of Array3 to PORT 0
sendToPort0(arr3[0])
```
Note: The solution assumes that PORT 0 refers to a specific output mechanism in the trainer kit. You may need to modify the `sendToPort0` function implementation accordingly based on the requirements or specifications of your trainer kit.