Submitted by: Submitted by bakerracing05
Views: 204
Words: 253
Pages: 2
Category: Science and Technology
Date Submitted: 02/22/2013 05:12 AM
Design a program that models the worm’s behavior in the following scenario:
A worm is moving toward an apple. Each time it moves, the worm cuts the distance between itself and the apple by its own body length until the worm is close enough to enter the apple. The worm can enter the apple when it is within one body length of the apple.
Analysis
Process
1. Display program title
2. Prompt for length of worm
3. Prompt for distance to apple
4. Calculate total moves
5. Output result
Input
Length of worm (real: WormLength)
Total distance to apple (real: TotalDistance)
Output
Write “Worm Enters Apple”
Design
Main Module
Declare WormLength as real
Declare TotalDistance as real
Declare TotalMoves as real
Declare DistanceRemaining as real
Write “Worm Behavior Program”
Write “This program models a worm’s behavior”
Write “when moving towards and entering an apple”
Write “What is the length of the worm?”
Input WormLength
Write “What is the total distance to the apple?”
Input TotalDistance
Write “The worm moves towards the apple:”
Write “moving one worm length each move”
TotalDistance/WormLength = TotalMoves
If TotalMoves ≠ TotalDistance/WormLength Then
Display DistanceRemaining
If DistanceRemaining ≤ WormLength Then
Enter Apple
Else
Repeat Move
End If
Write “Worm Enters Apple”
End Main Module
Input Results Module
Write “What is the length of the worm?”
Input WormLength
Write “What is the total distance to the apple?”
Input TotalDistance
End Input Results Module
Perform Calculations Module
TotalDistance/WormLength = TotalMoves
End Perform Calculations Module
Output Results Module
Write “Worm Enters Apple”