Flowcharts - Carnegie Mellon University

2y ago
65 Views
2 Downloads
347.52 KB
9 Pages
Last View : 9d ago
Last Download : 3m ago
Upload by : Maxine Vice
Transcription

ProgrammingFlowchartsFlowchartsA flowchart visually represents and organizes the steps used to write the program—it is a diagram of the “flow” of theprocess. 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 FlowchartsMove from step to step in the chart by following the lines between them. Perform any action listed when youreach a Statement Block (rectangle), and then choose from several different paths to follow when you reach aDecision Block (diamond).PARTS of a FLOW CHARTStart of Program — Marks the beginning ofthe program, begin here. Follow the line to get tothe next block.StartTake one step forwardStatement Block — A statement to execute,or a behavior to perform.Decision Block — A decision point in your program.Gone 50steps?NoAsk a simple question, and do different things dependingon the answer.Yes/No (also True/False, etc.) — Answers to the questionposed in the decision block. Follow the line labeled with theappropriate answer.YesEndEnd of Program - Marks the end of the program.If you reach this point, the program is done!Exercises1. 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 2005 Robomatter Inc.DATE6.5

ProgrammingFlowchartsWriting FlowchartsHow do you get from a complex task to an organized flowchart describing how to do it? Start with a flowchartcontaining just the task. Now break it down into smaller, more specific steps in another flowchart. Then, go backand see if you can break down any of those behaviors into simpler parts. Keep on repeating this process until you’vereached steps that are simple enough for your robot to perform!StartStartWash handsStartTurn on waterWash handsTurn on waterDispense soapDispense soapWash handsRub hands togetherWash handstill cleanWash hands till cleanNoHandsclean?Rinse soap offYesRinse soap offTurn off waterTurn off waterDry handsDry handsEndEndEndExercise5. 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 wearTake a showerEat breakfastLeave house for schoolGet out of bedLook for your shoesBrush your teethPut toast in the toasterCheck your alarm clockTurn on showerNAME 2005 Robomatter Inc.Put your shoes onHit snooze buttonGet dressedComb your hairCheck the timeDATE6.6

ProgrammingFlowchartsExercises6. What behavior does the flow chart below describe?StartPump airTire at ratedpressure?NoYesEnd7. 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 Consortium building.”e. “Turn on oven. Cook turkey for 4 hours or until meat thermometer reaches 180 degrees.”8. Make a flow chart for the process of crossing the street.Hint: Looking both ways won’t do any good unless you use that information to make some decisions.9. Bonus: Write a flow chart that tells you how to read flow charts.NAME 2005 Robomatter Inc.DATE6.7

Teacher ProgrammingFlowchartsExercises1. In the flowchart above, what will be the first action you take?Take one step forward.2. If you haven’t gone 50 steps yet, what will you do next?Take another step forward3. If you’ve gone 50 steps, what do you do?Nothing, you have reached the end of the flow chart.4. Describe the eventual result of your actions if you follow the flowchart above from start to finish.You will walk forward for 50 steps. 2005 Robomatter Inc.6.8

Teacher ProgrammingFlowcharts5. (This is a sample answer only. Student answers may vary.)StartSelect somethingto wearCheck youralarm clockHit Snooze buttonTimeto get up?Get DressedNoLook for shoesYesGet out of bedFoundshoes?Pour cereal intobowlYesPut shoes onEat cerealLeave houseBrush teethEndTurn on showerTimeto get up?Adjust watertemperatureNoYesTake showerComb hair 2005 Robomatter Inc.6.9No

Teacher ProgrammingFlowchartsExercises:6. The behavior shown in the flowchart is filling a tire with air from a pump.7. a. “If it’s raining, bring an umbrella.”b. “Take twenty paces, then turn and shoot.”StartStartTake 20 pacesRainingOutside?Take a stepYesBring umbrellaNoGone 20paces?EndYesTurn aroundc. “Go forward until the Touch Sensor (on port 1)is pressed in, then stop.”StartShootGo forwardTouchsensorpressed?YesStop robotEnd 2005 Robomatter Inc.EndNoNote: Stopping the robot is not the same as the program stoppingbecause it’s reached its end. Stopping the robot means bringing it toa physical halt, whereas ending the program simply means no morecommands are issued.This is an important distinction to make for later on.6.10No

Teacher ProgrammingFlowcharts7. 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 Consortium building.”Turn right onto Foster St.StartFollow Foster St.Follow Liberty Ave.Gone2 miles?Reachedleft turn?NoNoYesYesTurn leftTurn left onto 40th St.Follow streetFollow 40th St.Reachedbridge?ReachedNREC?NoYesYes 2005 Robomatter Inc.End6.11No

Teacher ProgrammingFlowcharts7. e. “Turn on oven. Cook turkey for 4 hours or until meat thermometer reaches 180 degrees.”StartNote: This key word in this exercise is the wordOR between the two conditions. As an additionalexercise, consider the ways in which this diagramwould change if you replaced the word OR with theword AND.Turn on ovenWaitYes4 hourselapsed?NoTherm.at 180 ?NoYesEnd8. Make a flow chart for the process of crossing thestreet. Hint: Looking both ways won’t do anygood unless you use that information to makesome decisions.StartLook leftSee carscoming?YesNoLook rightNote: This solution is good, but a trulywell-thought out solution will include adescription of how you should cross thestreet (continuing to look both ways foroncoming traffic).The important thing here is to note thatyou must make a decision with the datayou gather by looking–you don’t just lookfor looking’s sake, a point which is oftenoverlooked.See cars Yescoming?NoCross street 2005 Robomatter Inc.6.12End

Teacher ProgrammingFlowcharts9. Bonus: Write a flow chart that tells you how to read flow charts.StartGo the Start blockin the FlowchartFollow the line tothe next blockReachedYesa StatementBlock?Follow the NO lineto the next blockFollow the YES lineto the next blockYesAnswerto questionis “No”?NoYesNoAnswerto questionis “Yes”?YesNoNoERROR in FlowchartReacheda DecisionBlock?NoReachedan EndBlock?YesEnd 2005 Robomatter Inc.6.13Perform the action listed in theStatement Block

2005 Robomatter Inc. 6.8 Programming Flowcharts Exercises 1. In the flowchart above, what will be the first action you take? Take one step forward. 2. If you haven’t gone 50 steps yet, what will you do next? Take another step forward 3. If you’ve gone 50 steps, what do you d

Related Documents:

CMMI Appraisal Program The Software Engineering Institute is a federally funded research and development center sponsored by the U.S. Department of Defense and operated by Carnegie Mellon University CMMI, Capability Maturity Model and Carnegie Mellon are re gistered in the U.S. Patent and Trademark Office by Carnegie Mellon University

CMMI Appraisal Program The Software Engineering Institute is a federally funded research and development center sponsored by the U.S. Department of Defense and operated by Carnegie Mellon University CMMI and Carnegie Mellon are registered in the U.S. Patent and Trademark Office by Carnegie Mellon University

Carnegie Mellon University Pittsburgh, PA, USA {stace, ihowley, dps, paulos}@cs.cmu.edu Robotics Institute2 Carnegie Mellon University Pittsburgh, PA, USA ltrutoiu@cs.cmu.edu Mechanical Engineering3 Carnegie Mellon University Pittsburgh, PA, USA ckute@andrew.cmu.edu ABSTRACT With over 13.3 million children living below poverty line in

Protecting Browsers from Cross-Origin CSS Attacks Lin-Shung Huang Carnegie Mellon University linshung.huang@sv.cmu.edu Zack Weinberg Carnegie Mellon University zack.weinberg@sv.cmu.edu Chris Evans Google cevans@google.com Collin Jackson Carnegie Mellon University collin.jackson@sv.cmu.edu ABSTR

Impact from Innovation: Carnegie Mellon University's Role as a Local and Global Economic Engine Final Report iv EXECUTIVE SUMMARY World-class institutions of higher education such as Carnegie Mellon University (CMU) are widely known for their academic and research contributions. They are also major contributors to their local economies.

1 Reverse Engineering Liam O' Brien April 2005 2005 by Carnegie Mellon University Sponsored by the U.S. Department of Defense 2005 by Carnegie Mellon University

ming.zeng@sv.cmu.edu Patrick Tague Carnegie Mellon University Moffett Field, CA, USA patrick.tague@sv.cmu.edu Joy Zhang Carnegie Mellon University Moffett Field, CA, USA joy.zhang@sv.cmu.edu Permission to make digital or hard copies of all or part of this work for personal or

Co-Director, Carnegie Mellon Institute for eCommerce (1998-2004 ) Vice-Chair, University Research Council (2000-2002) Director, eBusiness Technology degree program, Carnegie Mellon (2003-2018) Director, M.S. in Artifi