Chapter 3 Algorithm Workbench

Remember!! This are MY answers…this are solutions but MY SOLUTIONS!

1. Design a module named ‘timesTen’. The module should accept an Integer argument. When
the module is called, it should display the product of it’s argument multipled times 10.
ANSWER:There are no indentation here, you have to figure out the indentation!
Module main()
Declare Integer number
Display “The product of the number times 10: ”
Input number
Call timesTen(number)
End Module
Module timesTen(Integer value)
Declare Integer product
Set product = value * 10
Display product
End Module

2. Examine the following pseudocode module header, and then write a statement that calls the
module, passing 12 as an argument
Module showValue(Integer quantity)
ANSWER: There are no indentation here, you have to figure out the indentation!
Call showValue(12)

3. Look at the following pseudocode module header:
Module myModule(Integer a, Integer b, Integer c)
Now look at the following call to ‘myModule’:
Call myModule(3, 2, 1)
When this call executes, what value will be stored in ‘a’? What value will be stored in ‘b’? What
value will be stored in ‘c’?
ANSWER:
These are the values that will be stored in the following:
a = 3
b = 2
c = 1

4. Assume that the pseudocode program contains the following module:
Module display(Integer arg1, Real arg2, String arg3)
Display “Here are the values:”
Display arg1, ” “, arg2, ” “, arg3
End Module
Assume that the same program has a main module with the following variable declarations:
Declare Integer age
Declare Real income
Declare String name
Write a statement that calls the ‘display’ module and passes these variables to it.
ANSWER:
Call display(age, income, name)

5. Design a module named ‘getNumber’, which uses a reference parameter variable to accept
an Integer argument. The module should prompt the user to enter a number and then store the
input in the reference parameter variable.
ANSWER: There are no indentation here, you have to figure out the indentation!
Module main()
Declare Integer userInput
Display “Enter a number: ”
Input userInput
Call getNumber(userInput)
End Module
Module getNumber(Integer Ref numberInput)
End Module

6. What will the following pseudocode program display?
Module main()
Declare Integer x = 1
Declare Real y = 3.4
Display x, ” “, y
Call changeUs(x, y)
Display x, ” “, y
End Module
Module changeUs(Integer a, Real b)
Set a = 0
Set b = 0
Display a, ” “, b
End Module
ANSWER:
1 3.4
0 0
1 3.4

7. What will the following pseudocode program display?
Declare Integer x = 1
Declare Real y = 3.4
Display x, ” “, y
Call changeUs(x, y)
Display x, ” “, y
End Module
Module changeUs(Integer Ref a, Real Ref b)
Set a = 0
Set b = 0
Display a, ” “, b
End Module
ANSWER:
1 3.4
0 0
0 0

Leave a Reply

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