Ingen bildrubrik

Download Report

Transcript Ingen bildrubrik

Från verkligt problem till
Datorprogram?
Du vet vad Du vill göra, men hur kommer man
till ett färdigt C-program?
Structure diagram
By 2IT Data students …
”Morningwhile has gold in mouthd”
Morning routine
Get dressed
Eat breakfast
Go to school
Division
Time
Sequence (order in time)
Morning routine
Get dressed
8:00 am
Eat breakfast
8:02 am
Sequence
Go to school
8:05 am
Sequence parts
Time
Structure diagram
”Morningwhile has gold in mouthd”
Morning routine
Get dressed
Find clothes
Take from
wash basket
Eat breakfast
Go to school
Put clothes on
Ask girlfriend
where clothes are
Division
Time
Selection
What colour on your socks?
If blue exists
Blue
If blue doesn’t exist,
but pink does
Pink
Selection
Else
White
Selection parts
Structure diagram
”Morningwhile has gold in mouthd”
Morning routine
Get dressed
Find clothes
Take from
wash basket
Put clothes on
Ask girlfriend
where clothes are
Eat breakfast
Go to school
Many glasses of beer
One glass
of beer
Division
Time
Iteration (repetition)
Drink beer (lightbeer)
Many glasses
of beer
Iteration
As long as you’re thirsty
One beer
Iteration part
Structure diagram
”Morningwhile has gold in mouthd”
Morning routine
Get dressed
Find clothes
Take from
wash basket
Put clothes on
Ask girlfriend
where clothes are
Eat breakfast
Many glasses of beer
One glass
of beer
Go to school
Take a cab
Run
One step
Division
Time
Flow chart
Morning route
Flowcharts are
onedimensional. They
are used when you have
to describe exactly how
the code is processed.
Get dressed
ELSE
Search clothes
IF you find basket
Get from laundry
basket
Ask girl/boyfriend
Put on the clothes
Eat breakfast
The Structure diagram
is easier to follow.
Eat one pancake
WHILE pancakes <> 0
Go to school
IF money = 0
ELSE
Run
Take a cab
Move foot one step
WHILE distance to school <> 0
Crossing
Imagine driving in car B, just behind
another car A.
You come to a crossing.
How will you know which direction it
will chose?
A
B
Car A has to make a selection
Crossing
How can you see in which direction the car in
front of you will choose?
a selection of directions
Selection
Crossing
Red signal
Green signal
STOP
Left blinker
DRIVE
No blinker
Drive left
Straight ahead
Right blinker
Drive right
Marriage - a selection?
Young man´s
future choice
Marry girl
not JSP
Selectionparts
• A selection must contain at least two selection
components. If It only contains one there is no
selection.
Young man´s
future choice
Marry girl
Be free!!
Like this!
Al Bundy?
It is however possible to
leave a selection
component empty.
Young man´s
future choice
Marry girl
We know the end…? Peg.. - make dinner!
Rules of Christmas
Santa Claus
X-mas day
While gifts not 0
Checks his
slade
Gives one *
gift
not JSP
Santa changed his mind
• Parts connected to the same
component must be of similar
type
Santa Claus
X-mas day
First
Checks his
slade
This
is CORRECT!!
Last
Hands out
gifts
While gifts not 0
Gives one*
gift
Paint house - an iteration
Paint
House
While painter not satisfied
with color
Get paint*
While entire house not painted
Paint with*
Brush
not JSP
Now you can begin to paint
• An iteration can only contain one repeated component
Paint
House
Iterations
Get paint
Begin to
paint
While painter not satisfied
with color
*
Get one
can of paint
Iteration
components
While entire house not painted
Paint with
*
Brush
OK !
JSP-editor
Henrik Engström JSP-editor
Generate C
Web-Quiz
Web-Quiz
Pseudocode
Pseudocode is a compact and informal high-level
description of a computer programming algorithm
that uses the structural conventions of a
programming language, but is intended for human
reading rather than machine reading.
BubleSort algorithm in
psdeudocode
Example of pseudocode …
while not at end of list
compare adjacent elements
if second is greater than first
switch them
get next two elements
if elements were switched
repeat for entire list
Lycka till med övningarna!