preview

Unit 4

Decent Essays

William Findley
Unit 4

Short answer
1. How do modules help you reuse code in a program? MODULES ALSO REDUCE THE DUPLICATION OF CODE WITHIN A PROGRAM..THIS BENEFIT OF USING MODULES IS KNOWN AS code reuse BECAUSE YOU ARE WRITING THE CODE TO PERFORM A TASK ONCE AND THEN REUSING IT EACH TIME YOU NEED TO PERFORM A TASK.

2. Name and describe the two parts that a module definition has in most languags.
A header and a body. Header indicates starting point, and the body is a list of statements.

3. When a module is executing, what happens when the end of the module is reached?
It’s executed and returned back to the point in main program where it was sidetracked from.

4. What is a local variable? What statement are able to access …show more content…

Module main()
Declare real purchase
Display “Enter the amount of purchase.”
Input purchase
Call Module totalState(purchase)
Call Module totalCounty(purchase)
Declare real totalTax
Declare real totalSale
Set totalTax = totalState + totalCounty
Set totalSale = purchase + totalTax
Display “Your amount of purchase is “, purchase
Display “Your total state tax is “, totalState
Display ”Your total county tax is “, totalCounty
Display “Your total tax is “, totalTax
Display “Your total of your sale is “, totalSale
End Module
Module totalState (real Ref purchase)
Set totalState sales tax = purchase * 0.04
End Module
Module totalCounty(real Ref purchase)
Set totalCounty sales tax = purchase * 0.02
End

Get Access