< previous page page_116 next page >

Page 116
Let's treat all of the quantities as named constants so that it is easier to change the program later. From measuring the map, you know that the distance from the museum to the record store is 1.5 inches, from the record store to the gallery is 2.3 inches, from the gallery to the bookshop is 5.9 inches, and from the bookshop to the concert is 4.0 inches. Here is the algorithmic solution:
DISTANCE1 = 1.5
DISTANCE2 = 2.3
DISTANCE3 = 5.9
DISTANCE4 = 4.0
SCALE = 0.25
Set totMiles = 0.0
Set miles = float(int(DISTANCE1 
* SCALE * 10.0 + 0.5)) / 10.0
Print DISTANCE1, miles
Add miles to totMiles
Set miles = float(int(DISTANCE2 
* SCALE * 10.0 + 0.5)) / 10.0
Print DISTANCE2, miles
Add miles to totMiles
Set miles = float(int(DISTANCE3 
* SCALE * 10.0 + 0.5)) / 10.0
Print DISTANCE3, miles
Add miles to totMiles
Set miles = float(int(DISTANCE4 
* SCALE * 10.0 + 0.5)) / 10.0
Print DISTANCE4, miles
Add miles to totMiles
Print a blank line
Print totMiles
From the algorithm we can create tables of constants and variables that help us write the declarations in the program.
Constants
NameValueDescription
DISTANCE11.5Measurement for first distance
DISTANCE22.3Measurement for second distance
DISTANCE35.9Measurement for third distance
DISTANCE44.0Measurement for fourth distance
SCALE0.25Scale factor of map

 
< previous page page_116 next page >