1 / 18

Pseudocode

Pseudocode. Process Modelling. Pseudocode. Simple explanation of the steps to achieve a task Can be reduced to Sequence Selection Iteration. Step follows step. Choose which steps to follow depending on some condition. Repeat steps a number of times. Sequence. begin wake up

john
Télécharger la présentation

Pseudocode

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pseudocode Process Modelling Phil Campbell London South Bank University

  2. Pseudocode Simple explanation of the steps to achieve a task Can be reduced to • Sequence • Selection • Iteration Step follows step Choose which steps to follow depending on some condition Repeat steps a number of times Phil Campbell London South Bank University

  3. Sequence begin wake up get out of bed shower dress eat end begin wake up get out of bed //shower go to bathroom take shower towel dry dress eat end The order is important All steps must be done Each step may be expanded Phil Campbell London South Bank University

  4. Selection begin if hungry then eat breakfast end if end begin if hungry then eat breakfast else drink coffee end if end hungry is either true or false hungry is a boolean condition Must either eat breakfast or drink coffee but not both. Phil Campbell London South Bank University

  5. Selection begin if hungry then eat breakfast else drink coffee end if end begin ifhungry=true then eat breakfast else drink coffee end if end hungry is either true or false hungry is a boolean condition Phil Campbell London South Bank University

  6. Selection begin if hungry then eat breakfast else drink coffee end if end begin ifhungry=false then eat breakfast else drink coffee end if end hungry is either true or false hungry is a boolean condition Phil Campbell London South Bank University

  7. Selection begin select preference case cereal: check milk in fridge case sausages : get frying pan case eggs : check use by date case toast: open bread bin end select end One and only one of the preferred actions will take place. Phil Campbell London South Bank University

  8. Iteration begin while hungry eat end while end As long as the hungry condition is true keep eating begin make toast for each slice of toast spread butter eat end for end Phil Campbell London South Bank University

  9. Iteration begin move forward move forward move forward move forward move forward move forward move forward move forward ... end begin while can move forward move forward end while end Phil Campbell London South Bank University

  10. Storing Values begin total <- 0; for each student add one to total end for display " value is " total; end increment total total <- total + 1 total++ Count the number of students Phil Campbell London South Bank University

  11. Storing Values begin totalHeight <- 0; count <- 0 for each student add student height to totalHeight increment count end for result <- totalHeight / count display "result is " result end Phil Campbell London South Bank University

  12. Student Heights 1.74 1.89 1.62 0 0 1.75 totalHeight count result begin totalHeight <- 0; count <- 0 for each student add student height to totalHeight increment count end for result <- totalHeight / count display "result is " result end 1.74 3.63 5.25 1 2 3 Result is 1.75 find the average height of a set of students Phil Campbell London South Bank University

  13. wake up get out of bed shower dress eat UML Activity Diagram begin wake up get out of bed shower dress eat end Phil Campbell London South Bank University

  14. [hungry] [not hungry] eat breakfast UML Activity Diagram begin if hungry then eat breakfast end if end Phil Campbell London South Bank University

  15. [hungry] [not hungry] eat breakfast drink coffee UML Activity Diagram begin if hungry then eat breakfast else drink coffee end if end Phil Campbell London South Bank University

  16. [not hungry] [hungry] eat UML Activity Diagram begin while hungry eat end while end Phil Campbell London South Bank University

  17. Answer to robot (general) begin whilenot at target turn left whilenot can move turn right end while move forward end while end Phil Campbell London South Bank University

  18. Robot class Phil Campbell London South Bank University

More Related