1 / 70

Examples Rules More examples

Program structure. Examples Rules More examples. Program structure. Transfering the problem into code. Split the problem into smaller problems. Make a structure of the problems (indata/outdata). Write down an operationlist and the conditions. ?. Program structure.

troy-baird
Download Presentation

Examples Rules More examples

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. Program structure • Examples • Rules • More examples

  2. Program structure Transfering the problem into code • Split the problem into smaller problems • Make a structure of the problems (indata/outdata) • Write down an operationlist and the conditions ?

  3. Program structure Transfering the problem into code • Split the problem into smaller problems • Make a structure of the problems (indata/outdata) • Write an operationslist and the conditions ? • Pseudocode can be used

  4. What is pseudocode? • Pseudocode is a combination between • ordinary language and real programcode • The pseudocode includes the sequences, • selections, iterations, conditions and operations • placed in the structurediagram • Pseudocode can be used to simplify the • structured problem before it becomes • real programcode

  5. Milk the cow - Pseudocode Peasant needs money

  6. 2 1 3 IF peasant_tired = yes ELSE By machine By hand WHILE milk = exist WHILE milk = exist * * Squeeze Squeeze 4 5 6 7 Milk the cow - Pseudocode Peasant needs money Operationlist Milk the cow 1. Input peasant_tired value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. While milk = exist

  7. 2 Milk the Sell milk 8 Operationlist cow 3 9 8. Input neighbour_home value 9. Read selection (neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value ELSE To neighbours To village 10 11 12 12 6 7 Conditionlist 4. If neighbour_home = yes Milk the cow - Pseudocode Peasant needs money IFneighbour_home = yes ELSE By hand WHILE milk = exist * Squeeze

  8. Spend money 8 Operationlist 9 13. Buy clothes 14. Read money value ELSE WHILE money = exist * Buy clothes To neighbours To village for wife 13 14 10 11 12 12 Conditionlist 5. While money = exist Milk the cow - Pseudocode Peasant needs money Sell milk If neighbour _home

  9. Milk the Sell milk Spend money cow IF neighbour_home = yes ELSE IF peasant_tired = yes WHILE money = exist ELSE * To neighbours To village Buy clothes By machine By hand for wife WHILE milk = exist WHILE milk = exist * * Squeeze Squeeze Milk the cow - Pseudocode Peasant needs money

  10. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist

  11. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 4. If neighbour_home = yes 5. While money = exist

  12. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 4. If neighbour_home = yes 5. While money = exist

  13. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 4. If neighbour_home = yes 5. While money = exist

  14. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist

  15. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist

  16. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist

  17. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist

  18. PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist

  19. OK! How about some real programcoding? PEASANT NEEDS MONEY Input peasant value IF peasant_tired = yes milk with machine ELSE milk by hand ENDIF Input milk value WHILE milk = exist Squeeze Read milk value ENDWHILE Input neighbour_home IF neighbour_home = yes sell milk to neighbours ELSE sell milk in village ENDIF Input money value WHILE money = exist Buy clothes for wife Read money value ENDWHILE Pseudocode Operationlist 1. Input peasant value 2. Read selection (hand/machine) 3. Input milk value 4. Squeeze 5. Read milk value 6. Squeeze 7. Read milk value 8. Input neighbour_home value 9. Read selection(neighbour/village) 10. Sell to neighbours 11. Sell to village 12. Input money value 13. Buy clothes 14. Read money value Conditionlist 1. If peasant_tired = yes (sel bm) 2. While milk = exist 3. If neighbour_home = yes 4. While money = exist

  20. The endpart 2

  21. C Solving 2nd degree equations • Structure diagram • Structure diagram to pseudocode • Pseudocode to C programming

  22. y = ax +bx +c 0 = ax +bx +c 2 2 2nd degree equation Solving 2nd degree equations Program structure D

  23. 0 = ax +bx +c 2 Solving 2nd degree equations Program structure 2nd degree equation Information

  24. 0 = ax +bx +c 2 Solving 2nd degree equations Program structure 2nd degree equation Solve equation? Information While answer ¹ n or N * One equation

  25. 0 = ax +bx +c 2 Solving 2nd degree equations Program structure 2nd degree equation Solve equation? Information While answer ¹ n or N * One equation Constant a Constant b Constant c Possible solution

  26. 0= ax +bx +c 2 D = b²/(4a²)-c/a Solving 2nd degree equations Program structure 2nd degree equation Solve equation? Information While answer ¹ n or N * One equation Constant a Constant b Constant c Possible solution If D ³ 0 Solution No real solution

  27. 0 = ax +bx +c 2 D = b²/(4a²)-c/a Solution No real solution Solving 2nd degree equations Program structure 2nd degree equation Solve equation? Information While answer ¹ n or N * One equation Constant a Constant b Constant c Possible solution If D ³ 0 If D = 0 Two solutions One solution

  28. 0 = ax +bx +c 2 Solve equation? D = b²/(4a²)-c/a While answer ¹ n or N * One equation Solution No real solution Solving 2nd degree equations Program structure 2nd degree equation Information 2 1 Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 If D = 0 11 Two solutions One solution 7 9 8 10

  29. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Rotate and Flip Solving equations Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n) end while Pseudo coding

  30. Solution No real solution Rotate and Flip Solving equations Solving 2nd degree equationsDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n) end while Pseudo coding Constant a 3 Information 1 2nd degree equation 2 Constant b 4 Solve equation? One equation * While answer ¹ n or N Constant c 5 7 If D = 0 One solution 6 If D ³ 0 8 Time 9 Two solutions Possible solution 10 11 2 Division

  31. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n) end while Pseudo coding

  32. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  33. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  34. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or NInput constant aInput constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  35. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or NInput constant aInput constant bInput constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  36. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant ccalculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n) end while Pseudo coding

  37. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/aIf D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  38. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  39. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  40. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a)display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  41. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display xelse calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  42. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x elsecalculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  43. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖDdisplay x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  44. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end ifelse display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  45. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if elsedisplay No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  46. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end ifAsk if user would like to solve an equation (y/n)end while Pseudo coding

  47. 2nd degree equation Solve equation? Information 2 While answer ¹ n or N 1 * One equation Constant a Constant b Constant c Possible solution 2 6 If D ³ 0 5 4 3 Solution No real solution If D = 0 11 Two solutions One solution 7 9 8 10 Solving equations Solving 2nd degree equationDisplay program informationAsk if user would like to solve an equation (y/n)While answer is not n or N Input constant a Input constant b Input constant c calculate D = b²/(4a²)-c/a If D ³ 0 If D = 0 calculate x = -b/(2a) display x else calculate x1= -b/(2a)+ÖD calculate x2= -b/(2a)-ÖD display x1, x2 end if else display No solution end if Ask if user would like to solve an equation (y/n)end while Pseudo coding

  48. Lego Mindstorms

  49. Lego Mindstorms

  50. C Solving equations Here’s an example of translating the pseudocode to C code Program

More Related