View
214
Download
0
Category
Tags:
Preview:
Citation preview
From real problem to From real problem to Computer program?Computer program?
You now what You want to do, but how to make it with a C-program?
Morning routine
Structure diagramStructure diagram
”Morningwhile has gold in mouthd”
Get dressed Eat breakfast Go to school
TimeTimeDivisionDivision
By 2IT Data students …
Sequence (order in time)Sequence (order in time)
Get dressed Eat breakfast Go to school
Morning routine
8:00 am 8:02 am 8:05 am Time
Sequence
Sequence parts
Structure diagramStructure diagram
”Morningwhile has gold in mouthd”
Find clothes Put clothes on
Morning routine
Get dressed Eat breakfast Go to school
DivisionDivisionTimeTime
Take fromwash basket
Ask girlfriendwhere clothes are
SelectionSelection
Blue Pink White
What colour on your socks?
If blue existsIf blue doesn’t exist,but pink does Else
Selection
Selection parts
Structure diagramStructure diagram
”Morningwhile has gold in mouthd”
Many glasses of beer
One glassof beer
DivisionDivisionTimeTime
Morning routine
Take fromwash basket
Ask girlfriendwhere clothes are
Find clothes Put clothes on
Get dressed Eat breakfast Go to school
Iteration (repetition)Iteration (repetition)
Many glassesof beer
One beer
Drink beer (lightbeer)
As long as you’re thirsty
Iteration
Iteration part
Structure diagramStructure diagram
”Morningwhile has gold in mouthd”
DivisionDivisionTimeTime
Take a cab Run
One step
Morning routine
Take fromwash basket
Ask girlfriendwhere clothes are
Find clothes Put clothes on
Get dressed Eat breakfast Go to school
Many glasses of beer
One glassof beer
Flow chartFlow chart
Move foot one step
Run
Go to school
Eat one pancake
Eat breakfast
Put on the clothes
Ask girl/boyfriendGet from laundrybasket
Search clothes
Get dressed
Morning route
IF you find basket
WHILE pancakes <> 0
Take a cab
IF money = 0
ELSE
ELSE
WHILE distance to school <> 0
Flowcharts are one dimensional. They are used when you have to describe exactly how the code is processed.
The Structure diagram is easier to follow.
CrossingCrossing
A
B
Imagine driving in car B, just behind another car A.You come to a crossing.How will you know which direction it will chose?
Car A has to make a selection
CrossingCrossing a selection of directionsa selection of directions
How can you see in which direction the car in front of you will choose?
Crossing
Green signal
STOP DRIVE
Red signal
Left blinker Right blinkerNo blinker
Drive left Straight ahead Drive right
Selection
Marriage - a selection?Marriage - a selection?
Marry girl
Young man´sfuture choice
not JSP
SelectionpartsSelectionparts
Young man´s future choice
• A selection must contain at least two selection components. If It only contains one there is no selection.
Marry girl Be free!!
Like this!
Al Bundy?Al Bundy?
Young man´s future choice
We know the end…? Peg.. - make dinner!
Marry girl
It is however possible to leave a selection component empty.
Rules of ChristmasRules of Christmas
Checks hisslade
Santa ClausX-mas day
Gives onegift
*
While gifts not 0
not JSP
Santa changed his mindSanta changed his mind• Parts connected to the same component must be of similar type
Santa ClausX-mas day
Checks hisslade
First
Hands out gifts
Last
This is CORRECT!! Gives one
gift
While gifts not 0
*
Paint house - an iterationPaint house - an iteration
PaintHouse
Get paint*While painter not satisfied with color
Paint withBrush
*
While entire house not painted
not JSP
Now you can begin to paintNow you can begin to paint
Get paint Begin to
paint
Paint
House
• An iteration can only contain one repeated component
Get onecan of paint
Paint with
Brush
* *
While painter not satisfied with color
While entire house not painted
Iterations
Iterationcomponents
OK !
JSP-editorJSP-editor
Henrik Engström JSP-editor
Generate CGenerate C
Web-QuizWeb-Quiz
Web-QuizWeb-Quiz
Good luck with your Good luck with your exercises!exercises!
Recommended