Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also...

46
Flowcharts Graphically representing the path of the program

Transcript of Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also...

Page 1: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

FlowchartsGraphically representing the path of the program

Page 2: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

You’ve maybe seen some of the joke flowcharts.

Page 3: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

The Birthday Card that I got my sister.

Page 4: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

On the back:

Page 5: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.
Page 6: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

That’s not what we are making.

Page 7: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Flowcharts are part of the program

process.

Page 8: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Flowcharts are also useful to help you

visualize the

flow of a program.

Page 9: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

YrsToVote = 18-Age

Start

Get Age

“Wait ” + YrsToVote

End

public VotingAge()

{

int Age = IO.inputInt (“Enter your age: “);

int YrsToVote = 18 - Age;

System.out.println(“Wait “ + YrsToVote);

}

An example:

Page 10: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Oval

Start

End

public VotingAge()

{

int Age = IO.inputInt (“Enter your age: “);

int YrsToVote = 18 - Age;

System.out.println(“Wait “ + YrsToVote);

}

Terminal

• One Start and One End for each program. No more, no less.• Only holds “Start” and “End”• Only one arrow comes out of the Start. No arrows for End.

Constructor Beginning

Constructor End

Page 11: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public VotingAge()

{

int Age = IO.inputInt (“Enter your age: “);

int YrsToVote = 18 - Age;

System.out.println(“Wait “ + YrsToVote);

}

Input

• Used for IO lines.• Only write “Get” + variable name• Don’t write the prompt (question)• Only one arrow comes out of it.

IO lines

Parallelogram

Get Age

Page 12: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public VotingAge()

{

int Age = IO.inputInt (“Enter your age: “);

int YrsToVote = 18 - Age;

System.out.println(“Wait “ + YrsToVote);

}

Processing

• Used for Math Lines.• Leave out the variable type, but write everything else• Only one arrow comes out of it.

Math lines

Rectangle

YrsToVote = 18-Age

Page 13: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public VotingAge()

{

int Age = IO.inputInt (“Enter your age: “);

int YrsToVote = 18 - Age;

System.out.println(“Wait “ + YrsToVote);

}

Output

• Used for System.out.println lines.• Leave out the System.out.println(); but write everything else• Only one arrow comes out of it.

System.out lines

“Wait ” + YrsToVote

Pencil

Page 14: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Terminal: start, end

Input: IO keyboard input

There is only one startand one end.

Arrows connect the pieces.

Flow is up to downor left to right.

Lines do not cross.

No shape can have more than 1 arrow come out of it.

Process: calculations

Output: System.out

Shape Formal: informal

RulesFlowchart Summary

Page 15: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

input

displayoutput

calculation

start/end

Page 16: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Make a flowchart for this code:

Start at the

beginning

public Mark() {int mark = IO.inputInt("What was your test mark? ");int total = IO.inputInt("What was the test total? ");int per = mark*100/total;System.out.println("That was "+per+"%");System.out.println("Good job!");

}

12345

Page 17: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Make a flowchart for this code:

What shape works for the

next line?

public Mark() {int mark = IO.inputInt("What was your test mark? ");int total = IO.inputInt("What was the test total? ");int per = mark*100/total;System.out.println("That was "+per+"%");System.out.println("Good job!");

}

12345

Page 18: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Get mark

Make a flowchart for this code:

And line two?

public Mark() {int mark = IO.inputInt("What was your test mark? ");int total = IO.inputInt("What was the test total? ");int per = mark*100/total;System.out.println("That was "+per+"%");System.out.println("Good job!");

}

12345

Page 19: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Get mark

Get total

Make a flowchart for this code:

What happens

inbetweenline 2 & 3?

public Mark() {int mark = IO.inputInt("What was your test mark? ");int total = IO.inputInt("What was the test total? ");int per = mark*100/total;System.out.println("That was "+per+"%");System.out.println("Good job!");

}

12345

Page 20: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Get mark

Per = mark*100/total

Get total

Make a flowchart for this code:

What shape is needed for line 3?

public Mark() {int mark = IO.inputInt("What was your test mark? ");int total = IO.inputInt("What was the test total? ");int per = mark*100/total;System.out.println("That was "+per+"%");System.out.println("Good job!");

}

12345

Page 21: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Get mark

“That was “ + per + “%”

Get total

Make a flowchart for this code:

What shape for

line 4?

public Mark() {int mark = IO.inputInt("What was your test mark? ");int total = IO.inputInt("What was the test total? ");int per = mark*100/total;System.out.println("That was "+per+"%");System.out.println("Good job!");

}

12345

Per = mark*100/total

Page 22: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Get mark

Get total

“Good Job”

Make a flowchart for this code:

How does it end?

public Mark() {int mark = IO.inputInt("What was your test mark? ");int total = IO.inputInt("What was the test total? ");int per = mark*100/total;System.out.println("That was "+per+"%");System.out.println("Good job!");

}

12345

“That was “ + per + “%”

Per = mark*100/total

Page 23: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Get mark

Get total

End

Make a flowchart for this code:

That’s all.

Gold star

public Mark() {int mark = IO.inputInt("What was your test mark? ");int total = IO.inputInt("What was the test total? ");int per = mark*100/total;System.out.println("That was "+per+"%");System.out.println("Good job!");

}

12345

“Good Job”

“That was “ + per + “%”

Per = mark*100/total

Page 24: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Let’s try another.

Page 25: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Make a flowchart for this output:

Start at the beginning

Cylinder Surface Area and Volume

Height: 4.2Radius: 3.4

The surface area is 99.04 The volume is 152.5317

Page 26: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Make a flowchart for this output:

What shape is line 1?

Cylinder Surface Area and Volume

Height: 4.2Radius: 3.4

The surface area is 99.04 The volume is 152.5317

Page 27: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start

Make a flowchart for this output:

What shape are the next

2 lines? (2&3)

Cylinder Surface Area and Volume

Height: 4.2Radius: 3.4

The surface area is 99.04 The volume is 152.5317

Print title

Page 28: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

StartGet

heightGet

radius

Make a flowchart for this output:

What about the last two lines?

Cylinder Surface Area and Volume

Height: 4.2Radius: 3.4

The surface area is 99.04 The volume is 152.5317

Print title

Page 29: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

StartGet

height

Print surface area

Get radius

Print volume

Make a flowchart for this output:Hey! Where

did those two numbers

come from?

Cylinder Surface Area and Volume

Height: 4.2Radius: 3.4

The surface area is 99.04 The volume is 152.5317

Print title

Oh yeah. We missed

a step.

Page 30: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

StartGet

height

Calculate surface area

Print surface area

Get radius

Print volume

Make a flowchart for this output:

Then, what shape to end it?

Cylinder Surface Area and Volume

Height: 4.2Radius: 3.4

The surface area is 99.04 The volume is 152.5317

Print title

Calculate volume

Page 31: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

StartGet

height

Calculate surface area

Print surface area

Get radius

Print volume

End

Make a flowchart for this output:

That’s all.

Cylinder Surface Area and Volume

Height: 4.2Radius: 3.4

The surface area is 99.04 The volume is 152.5317

Print title

Calculate volume

Gold star

Page 32: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

First, let’s classify the

code!

Page 33: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

Page 34: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

Page 35: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

Start with what shape?

Page 36: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

Start

What goes in the

parallelogram?

Page 37: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

Start Get a Get b Get c

Page 38: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

Start Get apos = (-b+(Math.sqrt(b*b-

4*a*c)))/2*aGet b

neg = (-b+(Math.sqrt(b*b-4*a*c)))/2*a

Get c

Page 39: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

Start Get apos = (-b+(Math.sqrt(b*b-

4*a*c)))/2*a

"The roots are "+pos+", "+neg

Get b

neg = (-b+(Math.sqrt(b*b-4*a*c)))/2*a

Get c

Page 40: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

public class flowchart {public static void main(String args[]) {new flowchart();

}public flowchart() {double a = IO.inputDouble("What is a?");double b = IO.inputDouble("What is b?");double c = IO.inputDouble("What is c?");double pos = (-b+(Math.sqrt(b*b-4*a*c)))/2*a;double neg = (-b-(Math.sqrt(b*b-4*a*c)))/2*a;System.out.println("The roots are "+pos+", "+neg);

}}

Very Important Side note: https://www.youtube.com/watch?v=VOXYMRcWbF8

Start Get apos = (-b+(Math.sqrt(b*b-

4*a*c)))/2*a

"The roots are "+pos+", "+neg

Get b

neg = (-b+(Math.sqrt(b*b-4*a*c)))/2*a

Get c

End

How do we end?

Page 41: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Flowcharts•Diagrams that trace how a computer

FLOWS through a piece of code.•Used to plan out a program before you

code.•Also used to understand a program

because it represents it visually.

Page 42: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

There is only one start and one end.

Arrows connect the pieces.

Flow is up to down or left to right.

Lines do not cross.

The only shape with can have 2 lines come out of it is a diamond.

No shape can have more than 2 lines come out of it.

Flowchart Rules

Page 43: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Start End

The ONLY thing it can

hold.

One of each per flow

chart.

Page 44: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Get n

int n = IO.inputInt("Number? ");

From IO,inputlines

ONLY write “Get” + variable name

Page 45: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

Calculate surface area

SA = 6 * a * a

int SA = 6 * a * a;

Math calculations

Leave the variable type off, put in the

calculation

Page 46: Flowchartsgorskicompsci.ca/ICS3U/Unit1/ppt8_Flowcharts.pdf · 2020. 11. 24. · Flowcharts are also useful to help you visualize the flow of a program.

System.out.println("Giant");System.out.println("The total is "+n);

Giant“The total

is “+n

System.out.printlnstatements

Just include what is in the brackets.