Section 6: Programming Basics

81

Problems

1.The village of Sonance has installed a 12-o'clock whistle in the 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 = L0 – 20 log (r/r0), where: L0 is the known sound level (138 db) at a point near the source,

r0 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:

¥ ´bC 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 L0 and r0 values from storage registers; or by removing 3.2 and 138 and loading L0, r, and r0 into the stack before execution: L0 vr vr0.

(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) ÷ ∆ ntaking 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%.)