Chapter 8- Algorithm Workbench

NOTE: There are no TABS on the codes. THESE ARE MY PERSONAL solutions to the problem. Copy at your own risk.

1. Write a pseudocode declaration for a String array initialized with the following strings: “Einstein”, “Newton”, “Copernicus” and “Kepler”

Constant Integer SIZE = 4
Declare String names[SIZE] = “Einstein”, “Newton”, “Copernicus”, “Kepler”

2. Assume names is an Integer array with 20 elements. Design a For loop that displays each element of the array.

Constant Integer SIZE = 20
For index = 0 To SIZE – 1
Display names[index]
End For

3. Assume the arrays numberArray1 and numberArray2 each have 100 elements. Design an algorithm that copies the values in numberArray1 to numberArray2.

Constant Integer SIZE = 100
For index = 0 To SIZE – 1
Set numberArray2[index] = numberArray1[index]
End For

4. Draw a flowchart showing the general logic for totaling the values in an array.
(You should be able to answer this)

5. Draw a flowchart showing the general logic for finding the highest value in an array.
(You should be able to answer this)

6. Draw a flowchart showing the general logic for finding the lowest value in an array
(You should be able to answer this)

7. Assume the following declarations appear in a pseudocode program:
Constant Integer SIZE = 100
Declare Integer firstArray[SIZE]
Declare Integer secondArray[SIZE]
Also, assume that values have been stored in each elements of firstArray.
Design an algorithm that copies the values in firstArray to secondArray.

For index = 0 To SIZE – 1
Set secondArray[index] = firstArray[index]
End For

8. Design an algorithm for a function that accepts an Integer array as an argument and returns the total values in the array.

Function Integer getTotal(Integer array[], Integer arraySize)
Declare Integer index
Declare Integer total = 0
For index = 0 to arraySize – 1
Set total = total + array[index]
End For
Return total
End Function

9. Write a pseudocode algorithm that uses the For Each loop to display all of the values in the following array: Constant Integer values[SIZE] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

For Each num In values
Display num
End For

Leave a Reply

Your email address will not be published. Required fields are marked *