Section 6: Programming Basics 81
Problems
1. The village of Sonance has installed a 12-o’
firehouse steeple. The sound level at the firehouse door, 3.2
meters from the whistle, is 138 decibels. Write a program to find
the sound level at various distances from the whistle.
Use the equation L = L
0
− 20 log (r/r
0
), where:
L
0
is the known sound level (138 dB) at a point near the source,
r
0
is the distance of that point from the source (3.2 m),
L is the unknown sound level at a second point, and
r
is the distance of the second point from the source in meters.
What is the sound level at 3 km from the source (r = 3 km)?
A possible keystroke sequence is:
| ¥ ´ b C 3.2 ÷ | o 20 * ” 138 +
| n | ¥
taking 15 program lines and 15 bytes of
memory. This problem can be solved in a more general way by
removing the specific values 3.2 and 138 from the program, and
instead recalling the L
0
and r
0
values from storage registers; or by
removing 3.2 and 138 and loading L
0
, r, and r
0
execution: L
0
v r v r
0
.
(Answer: for r = 3 km, L = 78.5606 dB.)
2. A “typical large”
tomato weighs about 200 grams, of which about
188 g (94%) are water. A tomato grower is trying to produce
tomatoes of lower percentage water. Write a program to calculate
the percent change in water content of a given tomato compared
to the typical tomato
. Use a programmed stop to enter the water
weight of the new tomato.
What is the percent change in water content for a 230 g tomato of
which 205 g are water?
A possible keystroke sequence is:
´ b Á .94 v ¦
(enter water weight of new
tomato) v ¦ (enter total weight of new tomato) ÷ |
∆ | n taking 11 program lines and 11 bytes of memory.
(Answer: for the 230 g tomato above, the percent change in
percent water weight is −5.1804%.)