Program Design and Algorithm Development
Program Design and Algorithm Development
Algorithm
Development
Katja Fennel
Lab 5
Objective
Design goals
Examples
Temperature conversion
Marine Modelling February 12, 2010 Guessing Game
Katja Fennel
Oceanography
Dalhousie University
5.1
Program Design and
Learning objective: Algorithm
Development
Katja Fennel
Objective
Structure plan
Design goals
Design process
Examples
Temperature conversion
Introduce the steps of program design and the concept of Guessing Game
5.2
Program Design and
Structure Plan: Algorithm
Development
Katja Fennel
Objective
Structure plan
Design goals
• helpful strategy for how to think about the development of Design process
5.3
Program Design and
Design goals: Algorithm
Development
Katja Fennel
Objective
Structure plan
Design goals
• software that works Design process
5.4
Program Design and
Design Process: Algorithm
Development
Katja Fennel
Objective
• step 1: problem analysis (establish context, understand
Structure plan
nature of problem, develop detailed statement of
Design goals
mathematical problem to be solved) Design process
Examples
Temperature conversion
Guessing Game
5.5
Program Design and
Design Process: Algorithm
Development
Katja Fennel
Objective
• step 1: problem analysis (establish context, understand
Structure plan
nature of problem, develop detailed statement of
Design goals
mathematical problem to be solved) Design process
5.5
Program Design and
Design Process: Algorithm
Development
Katja Fennel
Objective
• step 1: problem analysis (establish context, understand
Structure plan
nature of problem, develop detailed statement of
Design goals
mathematical problem to be solved) Design process
5.5
Program Design and
Design Process: Algorithm
Development
Katja Fennel
Objective
• step 1: problem analysis (establish context, understand
Structure plan
nature of problem, develop detailed statement of
Design goals
mathematical problem to be solved) Design process
5.5
Program Design and
Design Process: Algorithm
Development
Katja Fennel
Objective
• step 1: problem analysis (establish context, understand
Structure plan
nature of problem, develop detailed statement of
Design goals
mathematical problem to be solved) Design process
5.5
Program Design and
Examples of structure plans: Algorithm
Development
Katja Fennel
Design goals
1 Initialize temperature in Fahrenheit Design process
5.6
Program Design and
Examples of structure plans: Algorithm
Development
Katja Fennel
Design goals
1 Initialize temperature in Fahrenheit Design process
5.6
Program Design and
Here is my version: Algorithm
Development
Katja Fennel
convert_F2C.m :
% This script converts temp.s from the Fahrenheit Objective
Structure plan
% to the Celsius scale.
Design goals
Design process
% 1. Initialize temperature in Fahrenheit (F) Examples
% use "input" command to receive input from the Temperature conversion
Guessing Game
% command line
F = input(’Enter temperature in degrees F: ’);
% 2. Calculate and display Celsius temperature (C)
% 2.1. Subtract 32 from F and multiply by 5/9
C = (F-32)*5/9;
% 3. Display C
% use "disp" command to display the result
disp([’This temperature corresponds to ’ num2str(C) ...
’ degrees C.’])
% 4. Stop
Katja Fennel
Objective
MATLAB thinks of an integer between 1 and 10 (it generates Structure plan
this number at random). We need to guess it. If our guess is Design goals
too high or too low, MATLAB will tell us. When we are right Design process
MATLAB will display a congratulation message. Examples
Temperature conversion
Guessing Game
5.8
Program Design and
Another example: Guessing game Algorithm
Development
Katja Fennel
Objective
MATLAB thinks of an integer between 1 and 10 (it generates Structure plan
this number at random). We need to guess it. If our guess is Design goals
too high or too low, MATLAB will tell us. When we are right Design process
MATLAB will display a congratulation message. Examples
Temperature conversion
Guessing Game
5.8
Program Design and
Algorithm
Development
Katja Fennel
Objective
Structure Plan: Structure plan
Design goals
Design process
Examples
Temperature conversion
Guessing Game
5.9
Program Design and
Algorithm
Development
Katja Fennel
Objective
Structure Plan: Structure plan
Design process
2 Ask for our guess
Examples
3 While the guess is wrong: Temperature conversion
Guessing Game
1 If guess is too low, say so
2 If guess is too high (otherwise), say so
3 Ask for new guess
4 If we make it past 3. we must be right: congratulate
5 Stop
5.9
Program Design and
Algorithm
Development
Katja Fennel
Objective
Structure Plan: Structure plan
Design process
2 Ask for our guess
Examples
3 While the guess is wrong: Temperature conversion
Guessing Game
1 If guess is too low, say so
2 If guess is too high (otherwise), say so
3 Ask for new guess
4 If we make it past 3. we must be right: congratulate
5 Stop
Now write it!
5.9
Program Design and
Exercise: Algorithm
Development
Katja Fennel
Objective
Structure plan
Come up with the structure plan for a script that projects the Design goals
population of China forward in time for 8 decades (starting from Design process
1980). This will use 1980 population structure data and death Examples
Temperature conversion
rates form the handout. Guessing Game
5.10