C++ Flowchart

Only available on StudyMode
  • Download(s) : 141
  • Published : April 14, 2013
Open Document
Text Preview
Programming

Flowcharts
Flowcharts
A flowchart visually represents and organizes the steps used to write the program—it is a diagram of the “flow” of the process. When programmers write code, they need to give the robot instructions that are both sequential and specific. Flowcharts enable programmers to work these steps out before needing to translate their behaviors into code.

Reading flowcharts
Move from step to step in the chart by following the lines between them. Perform any action listed when you reach a Statement Block (rectangle), and then choose from several different paths to follow when you reach a Decision Block (diamond).

Parts of a Flow Chart Start of program — Marks the beginning of the program, begin here. Follow the line to get to the next block.

Start

Take one step forward

Statement block — A statement to execute,
or a behavior to perform.

Decision block — A decision point in your program. Gone 50 steps? No Ask a simple question, and do different things depending on the answer.

Yes/No (also True/False, etc.) — Answers to the question
posed in the decision block. Follow the line labeled with the appropriate answer.

Yes End End of program — Marks the end of the program.
If you reach this point, the program is done!

Exercises
1. In the flowchart above, what will be the first action you take? _________________________________________________________ 2. If you haven’t gone 50 steps yet, what will you do next? ____________________________________________________________ 3. If you’ve gone 50 steps, what do you do? ______________________________________________________________________ 4. Describe the eventual result of your actions if you follow the flowchart above from start to finish. ________________________________ _____________________________________________________________________________________________________

NAME

DATE

6.5

©2005 Robomatter Inc. RE 2.5_RW 1.1

Programming

Flowcharts
Writing Flowcharts
How do you get from a complex task to an organized flowchart describing how to do it? Start with a flowchart containing just the task. Now break it down into smaller, more specific steps in another flowchart. Then, go back and see if you can break down any of those behaviors into simpler parts. Keep on repeating this process until you’ve reached steps that are simple enough for your robot to perform! Start

Start

Start

Wash hands
Turn on water

Wash hands
Turn on water

Dispense soap
Wash hands till clean

Dispense soap

Rub hands together

Wash hands

Wash hands till clean
Hands clean?
No

Rinse soap off

Yes

Turn off water

Rinse soap off

Dry hands

Turn off water

Dry hands

End

End
End

Exercise

5. On a separate sheet of paper, make a flowchart organizing the “flow” of getting ready to go to school in the morning. Be sure to include the following steps in your chart, but don’t be afraid to add other things if you need them!

Select something to wear Take a shower Eat breakfast Leave house for school Get out of bed

Look for your shoes Brush your teeth Put toast in the toaster Check your alarm clock Turn on shower

Put your shoes on Hit snooze button Get dressed Comb your hair Check the time

NAME

DATE

©2005 Robomatter Inc. RE 2.5_RW 1.1

6.6

Programming

Flowcharts
Exercises

6. What behavior does the flow chart below describe?
Start

Pump air

Tire at rated pressure?
Yes

No

End

7. Create flowcharts to represent these short tasks: a. “If it’s raining, bring an umbrella.” b. “Take twenty paces, then turn and shoot.” c. “Go forward until the Touch Sensor (on port 1) is pressed in, then stop.” d. “Follow Liberty Avenue for 2 miles, then take a left turn onto 40th Street. Go until you reach the bridge, but don’t cross the bridge. Instead, make a right turn onto Foster Street, then take the first left turn. Follow that road until you reach the National Robotics Engineering...
tracking img