Homework Chapter 3

Topics: Ring, Real number, Natural number Pages: 8 (1580 words) Published: May 12, 2014

Multiple Choice
1) Module
2) Divide and Conquer
3) Header
4) Call
5) Return
6) Top-down Design
7) Flowchart
8) Local Variable
9) Scope
10) Argument
11) Parameter
12) By Value
13) By Reference
14) Global variable
15) Global

True or False
1) False
2) True
3) True
4) False
5) True
6) False
7) False
8) True
9) True
10) False
11) True
12) False

Short Answers
1) You can call the module several times instead of writing it out each time. 2) The header is the starting point and the body is a list of statements that belong to the module. 3) It will return back to its previous point in the program. 4) A local variable is declared inside the module only. Only the statements inside the module can access it. 5) A local variable’s scope begins at the variable’s declaration and ends at the end of the module in which the variable is declared. 6) When you pass by value you pass a copy. When you pass by reference, you can modify the contents. 7) Global variables make debugging difficult because any statement in a program can change its value.

Algorithm Workbench
1) Module timesTen(Integer value)
Declare Integer result
Set result = * 10
Display result
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)

Module main()
Call showValue (12)
End Module

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?

A=3
B=2
C=1

4) Assume that a 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.

Call display(Integer age, Real income, String 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.

Module getNumbers( Real Ref numbers)
Display " Enter number."
Input number
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

It will display if the number are equal to or less than integers x and y.

7) 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 Ref a, Real Ref b)
Set a = 0
Set b = 0.0
Display a, " ", b
End Module

It will allow the user to enter a decimal

Programming Exercises
1) Kilometer Converter Design a modular program that asks the user to enter a distance in kilometers, and then converts that distance to miles. The conversion formula is as follows: Miles = Kilometers × 0.6214

Module main()
Display “Enter Kilometers”
Call kiloConvert()
End Module

Module kiloConvert(Integer value)
Declare Integer miles
Set miles = value * 0.6214
Display mile
End Module

2) Sales Tax Program Refactoring Programming Exercise 6 in Chapter 2 was the Sales Tax program. For that exercise you were asked to design a program that calculates and displays the county and state sales tax on a purchase. If you have already...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • homework Essay
  • Chapter 3 Homework Essay
  • MAT540 Week 3 Homework Essay
  • Chapters 1-3 Homework Problems Essay
  • Operations Management Homework Chapter 3 Essay
  • Homework 3 Essay
  • homework 3 Essay
  • Homework Unit 3 Essay

Become a StudyMode Member

Sign Up - It's Free