Från verkligt problem till Datorprogram? Du vet vad Du vill göra, men hur kommer man till ett...

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

Transcript of Från verkligt problem till Datorprogram? Du vet vad Du vill göra, men hur kommer man till ett...

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

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?

Page 2: Från verkligt problem till 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 …

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

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

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

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

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

SelectionSelection

Blue Pink White

What colour on your socks?

If blue existsIf blue doesn’t exist,but pink does Else

Selection

Selection parts

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

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

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

Iteration (repetition)Iteration (repetition)

Many glassesof beer

One beer

Drink beer (lightbeer)

As long as you’re thirsty

Iteration

Iteration part

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

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

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

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.

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

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

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

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

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

Marriage - a selection?Marriage - a selection?

Marry girl

Young man´sfuture choice

not JSP

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

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!

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

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.

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

Rules of ChristmasRules of Christmas

Checks hisslade

Santa ClausX-mas day

Gives onegift

*

While gifts not 0

not JSP

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

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

*

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

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

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

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 !

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

JSP-editorJSP-editor

Henrik Engström JSP-editor

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

Generate CGenerate C

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

Web-QuizWeb-Quiz

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

Web-QuizWeb-Quiz

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

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.

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

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 …

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

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