Från verkligt problem till Datorprogram? Du vet vad Du vill göra, men hur kommer man till ett färdigt C-program?

Post on 16-Dec-2015

222 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Från verkligt problem till Från verkligt problem till Datorprogram?Datorprogram?

Du vet vad Du vill göra, men hur kommer man till ett färdigt 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 onedimensional. 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

PseudocodePseudocode

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 BubleSort algorithm in psdeudocodepsdeudocode

while not at end of listcompare adjacent elementsif second is greater than firstswitch them get next two elementsif elements were switchedrepeat for entire list

Example of pseudocode …

Lycka till med övningarna!Lycka till med övningarna!

top related