branching aco101: introduction to computer science

21
Branching ACO101: Introduction to Computer Science

Upload: sophia-simon

Post on 21-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Branching ACO101: Introduction to Computer Science

Branching

ACO101: Introduction to Computer Science

Page 2: Branching ACO101: Introduction to Computer Science

Flowcharting is a way

• Of modeling a system• It is the design of the system and it is what we

do in the Inception and Elaboration phases of a project.

Page 3: Branching ACO101: Introduction to Computer Science

Flowcharts : Review

• Are:

–A schematic representation of a process–And a visual way to describe an

algorithm

Page 4: Branching ACO101: Introduction to Computer Science

Shapes used in flowcharts

Page 5: Branching ACO101: Introduction to Computer Science

Terminators are oval (sometimes you see circles)

Page 6: Branching ACO101: Introduction to Computer Science

Processes are rectangles; they always do something

Page 7: Branching ACO101: Introduction to Computer Science

Decisions are diamonds and they always have a question

Page 8: Branching ACO101: Introduction to Computer Science

These flowcharts are all Examples of Branching

Page 9: Branching ACO101: Introduction to Computer Science

Flowchart for an if statement

Page 10: Branching ACO101: Introduction to Computer Science

Flowchart for an if/else

Page 11: Branching ACO101: Introduction to Computer Science

Nested branching

Page 12: Branching ACO101: Introduction to Computer Science

Multiple alternatives

• Sometimes you wish you had more than one else.

• That is what the else if and the switch is for.

Page 13: Branching ACO101: Introduction to Computer Science

Switch and else if flowchart

Page 14: Branching ACO101: Introduction to Computer Science

So here is the sample “if statement” from Scratch

Page 15: Branching ACO101: Introduction to Computer Science

PsCode is…..

• We will choose a question for the crab to ask.• The seeker [crabby] will ask that question• If the question number is divisible by 5 then

the fairy will give a positive answer to the crab• Other wise she will give a negative answer to

the crab.•

Page 16: Branching ACO101: Introduction to Computer Science

Open Visio and copy this flowchart

Page 17: Branching ACO101: Introduction to Computer Science

So what does that look like in code?

• First – pick a question number and save it to memory

• Second – create a crab object– Make a call to a method called getOneQuestion

• Third – create a fairy object– Make a call to a method called getOneAnswer

Page 18: Branching ACO101: Introduction to Computer Science
Page 19: Branching ACO101: Introduction to Computer Science

Retrieve the question and write it to the screen using the variable

Page 20: Branching ACO101: Introduction to Computer Science

Is the question number divisible by 5??

Page 21: Branching ACO101: Introduction to Computer Science

Now lets set up the branching