210 likes | 510 Views
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
E N D
Pseudocode Process Modelling Phil Campbell London South Bank University
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
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
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
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
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
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
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
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
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
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
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
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
[hungry] [not hungry] eat breakfast UML Activity Diagram begin if hungry then eat breakfast end if end Phil Campbell London South Bank University
[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
[not hungry] [hungry] eat UML Activity Diagram begin while hungry eat end while end Phil Campbell London South Bank University
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
Robot class Phil Campbell London South Bank University