Problem Solving

advertisement
Problem Solving
The Program Development Cycle and
Program Design Tools
Performing a Task on the
Computer
Determine the output
Identify the input
Determine how to process the input to
obtain the output
Input
Process
Output
Program Development Cycle
Analyze
Define the problem
Design
Develop an algorithm
Choose the interface
Select the objects
Code
Test and Debug
Complete the documentation
Program Design Tools
Flowcharts – Graphically depict the logical
steps to carry out a task and show how the
steps relate to each other.
Pseudocode – Uses English-like phrases with
some Visual Basic terms to outline the task.
Hierarchy charts – Show how the different
parts of a program relate to each other.
Flowcharts
Flowline
Terminator
Input/Output
Processing
Decision
Connector
Offpage connector
Miles to Kilometers Conversion
Program
Problem:
Your summer surveying job requires you do
calculations of distances in kilometers. All of
your data is in miles. Write a program the
performs the necessary conversion.
Input: distance in miles
Processing: convert miles to kilometers
1 mile = 1.609 kilometers
Output: distance in kilometers
Hierarchy Chart
Kilometers to
miles
conversion
program
Get
distance in
miles
Convert from
miles to
kilometers
Display
distance in
kilometers
Flowchart
Start
Get distance
in miles
Set
kilometers = 1.609 * miles
Display distance
in kilometers
End
Pseudocode
Get distance in miles
Convert the distance to kilometers
The distance in kilometers is 1.609 the
distance in miles
Display the distance in kilometers
Direction of Numbered NYC
Streets Algorithm
Problem:
Given a street number of a one-way street in
New York, decide the direction of the street.
(hint: even numbered streets run eastbound)
Input: Street number
Processing: Decide if the street number is
divisible by 2
Output: “Eastbound” or “Westbound”
Hierarchy Chart
Street
direction
program
Get street
number
Decide whether
street number is
even or odd
Display
direction
Flowchart
Start
Get Street
Number
No
Is Street
Number
Even?
Display
Westbound
Yes
Display
Eastbound
End
Pseudocode
Get Street number
If Street number is even Then
Display Eastbound
Else
Display Westbound
Download