Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

  • Be the first to comment

  • Be the first to like this


  1. 1. Structured Programming A VERY important Philosophy for Writing Programs
  2. 2. This copy of Presentation can be found At
  3. 3. Bad Programming Habits <ul><ul><li>Foggy idea about what is to be done </li></ul></ul><ul><ul><li>Write program with no planning; Start from the beginning and write to the end </li></ul></ul><ul><ul><li>No systematic debugging; Considered it finished if it works on one example </li></ul></ul><ul><ul><li>Undesirable Results ! </li></ul></ul><ul><ul><ul><li>Do not know how to program </li></ul></ul></ul><ul><ul><ul><li>Programs with numerous bugs that take extremely long time to debug, or even failure to complete </li></ul></ul></ul><ul><ul><ul><li>Any change of requirement invites rewriting of the entire program again </li></ul></ul></ul>
  4. 4. Benefits of Structured Programming <ul><ul><li>Programs that meet the needs of the customer </li></ul></ul><ul><ul><li>Though initially take longer time to generate code, often result in code with runs with no bugs the first time it’s run </li></ul></ul><ul><ul><li>Easy to handle change in program specifications in the future </li></ul></ul>
  5. 5. Structured Programming <ul><ul><li>A tool that becomes popular since the 70’s </li></ul></ul><ul><ul><li>Should have been learnt by student that have taken any programming course </li></ul></ul><ul><ul><li>Absolutely essential for handling large programs that involve a team of programmers and huge number of man hours. </li></ul></ul><ul><ul><li>The other popular philosophy is “object oriented programming”, but many programmers prefers structured programming </li></ul></ul>
  6. 6. Seven Important Concepts of Structured Programming: 1. Structured Walkthrough <ul><ul><li>Before writing any program, the programming team must sit down with the customer and find out the requirement </li></ul></ul><ul><ul><li>Extremely important </li></ul></ul><ul><ul><li>Customer’s requirement is often imprecise </li></ul></ul><ul><ul><li>Iterative: several rounds of talks </li></ul></ul><ul><ul><li>Must result in a specifications that is </li></ul></ul><ul><ul><ul><li>very precise </li></ul></ul></ul><ul><ul><ul><li>Understandable by programmer in programming terms </li></ul></ul></ul>
  7. 7. 2. Stepwise Refinement <ul><ul><li>A “DIVIDE and CONQUER” strategy </li></ul></ul><ul><ul><li>When given a large job, divide it into smaller jobs. </li></ul></ul><ul><ul><li>Given any job, it is useful to divide it into </li></ul></ul><ul><ul><ul><li>Input </li></ul></ul></ul><ul><ul><ul><li>Process </li></ul></ul></ul><ul><ul><ul><li>Output </li></ul></ul></ul><ul><ul><li>Draw a tree </li></ul></ul><ul><ul><li>Refine each job level by level (Breadth first) </li></ul></ul><ul><ul><li>Use pseudo code to describe each job </li></ul></ul><ul><ul><li>Decision on data structure is delayed as much as possible </li></ul></ul>
  8. 8. Extremely Complex Job Input Process Output Level 1 Input from user Initialize … … Level 2 Initialize security settings … Level 3
  9. 9. 3. Modular Design <ul><ul><li>Each ellipse is a module </li></ul></ul><ul><ul><li>A module is a self contained block: </li></ul></ul><ul><ul><ul><li>It only receives inputs from its immediate ancestor </li></ul></ul></ul><ul><ul><ul><li>It only outputs to its immediate ancestor </li></ul></ul></ul><ul><ul><ul><li>Its computation should only require calling functions that are its immediate children and them only </li></ul></ul></ul><ul><ul><li>The input variables and output variables of each module should be specified when defining the module </li></ul></ul><ul><ul><li>Each module must be “programmable” – no magic block should exist </li></ul></ul>
  10. 10. 4. Bottom Up Coding <ul><ul><li>When the refinement has reached a simple function, code the simple function </li></ul></ul><ul><ul><li>You can test the simple function independently of the rest of the program </li></ul></ul><ul><ul><li>This gives you achievement and satisfaction, sustaining you through the long project </li></ul></ul><ul><ul><li>Project Manager exercises division of labour here, ask a member to be responsible solely for that function </li></ul></ul>
  11. 11. 5. Testing Using Stubs <ul><ul><li>A structured Programming project can be field tested before everything finishes </li></ul></ul><ul><ul><li>Stubs - for unfinished modules, use a human being to emulate it, act on the test inputs, she fits in the correct output data by hand </li></ul></ul><ul><ul><li>then other programmers can test their work </li></ul></ul><ul><ul><li>Meanwhile she continues to program her own module (according to MS Project timelines) </li></ul></ul>
  12. 12. 6. White Box and Black Box Testing <ul><ul><li>For each module and whole program </li></ul></ul><ul><ul><li>White Box </li></ul></ul><ul><ul><ul><li>Input something for which you know the desired result, it should give your expected output </li></ul></ul></ul><ul><ul><li>Black Box </li></ul></ul><ul><ul><ul><li>Treat it as a black box, input some data, is the result reasonable? </li></ul></ul></ul>
  13. 13. 7. Structured Programming Documents <ul><ul><li>A structured programming document is generated along with the program </li></ul></ul><ul><ul><li>When requirement of customer changes, go to the document </li></ul></ul><ul><ul><li>Does not need to rewrite the whole program, just find which modules need to rewrite and rewrite the module and the sub-tree under it </li></ul></ul><ul><ul><li>Programmer usually forgets their code in 2 months; the structured document helps her to refresh her work quickly </li></ul></ul>
  14. 14. Review <ul><ul><li>3 structures of structured programming </li></ul></ul><ul><ul><ul><li>Sequence </li></ul></ul></ul><ul><ul><ul><ul><li>Perform an action </li></ul></ul></ul></ul><ul><ul><ul><li>Branch </li></ul></ul></ul><ul><ul><ul><ul><li>Select an action (or no action) </li></ul></ul></ul></ul><ul><ul><ul><li>Loop </li></ul></ul></ul><ul><ul><ul><ul><li>Repeat an action </li></ul></ul></ul></ul>
  15. 15. Actions <ul><ul><li>Declare </li></ul></ul><ul><ul><ul><li>Need storage space for our actions/results </li></ul></ul></ul><ul><ul><li>Assign </li></ul></ul><ul><ul><ul><li>Random value </li></ul></ul></ul><ul><ul><ul><li>Mathematical expression </li></ul></ul></ul><ul><ul><ul><li>User input </li></ul></ul></ul><ul><ul><li>Output </li></ul></ul>
  16. 16. Decisions <ul><ul><li>Branching selects from two paths </li></ul></ul><ul><ul><li>Relational Operators turn integers into true/false </li></ul></ul><ul><ul><li>AND – the expression is TRUE if and only if both input variables are TRUE </li></ul></ul><ul><ul><li>OR – the expression is TRUE if either input variable is TRUE </li></ul></ul>
  17. 17. Two Branches <ul><ul><li>Did you roll a doublet? </li></ul></ul><ul><ul><ul><li>die1 == die2  double move </li></ul></ul></ul><ul><ul><ul><li>Normal move </li></ul></ul></ul>
  18. 18. Multiple Branches <ul><ul><li>What is your grade classification? </li></ul></ul><ul><ul><ul><li>>= 80  honours </li></ul></ul></ul><ul><ul><ul><li>>= 60  pass </li></ul></ul></ul><ul><ul><ul><li>Not pass </li></ul></ul></ul>
  19. 19. Sample Program <ul><ul><li>Write a program that tells a user if their input matches a random number between 1 and 10 </li></ul></ul><ul><ul><ul><li>Declare and get input </li></ul></ul></ul><ul><ul><ul><li>Declare and get random value </li></ul></ul></ul><ul><ul><ul><li>If input equals random value </li></ul></ul></ul><ul><ul><ul><ul><li>Output “good guess” </li></ul></ul></ul></ul>
  20. 20. Sample Program II <ul><ul><li>Write a program that takes two inputs and outputs the largest value </li></ul></ul><ul><ul><ul><li>Declare and get first input </li></ul></ul></ul><ul><ul><ul><li>Declare and get second input </li></ul></ul></ul><ul><ul><ul><li>If first value is greater than second value </li></ul></ul></ul><ul><ul><ul><ul><li>Output first value </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Otherwise, output second value </li></ul></ul></ul></ul>
  21. 21. Sample Program III <ul><ul><li>Write a program that takes three inputs and outputs the largest value </li></ul></ul>
  22. 22. Looping <ul><ul><li>In Sequence and Branching, each action is performed at most once </li></ul></ul><ul><ul><li>Looping allows certain actions to be repeated </li></ul></ul><ul><ul><li>Keeps programs from getting large and unmanageable </li></ul></ul>
  23. 23. Example of Looping <ul><ul><li>Program specification </li></ul></ul><ul><ul><ul><li>Take user inputs until they guess correctly </li></ul></ul></ul><ul><ul><li>Program </li></ul></ul><ul><ul><ul><li>Declare and initialize number </li></ul></ul></ul><ul><ul><ul><li>Declare guess </li></ul></ul></ul><ul><ul><ul><li>Input and compare guess </li></ul></ul></ul><ul><ul><ul><li>Input and compare guess </li></ul></ul></ul><ul><ul><ul><li>… </li></ul></ul></ul>
  24. 24. Looping Icon <ul><ul><li>Loops have same components as branches </li></ul></ul><ul><ul><li>Condition selects one of two paths </li></ul></ul><ul><ul><li>Optional path “loops back” to condition </li></ul></ul>
  25. 25. Sample Program <ul><ul><li>Write a program that outputs the values from 1 to 10 </li></ul></ul><ul><ul><ul><li>Declare and initialize value </li></ul></ul></ul><ul><ul><ul><li>While value is less than or equal to 10 </li></ul></ul></ul><ul><ul><ul><ul><li>Output value </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Increment value </li></ul></ul></ul></ul>
  26. 26. This copy of Presentation can be found At
  27. 27. Sample Program II <ul><ul><li>Write a program that uses repeated subtraction to get the remainder and quotient of an input dividend and divisor </li></ul></ul><ul><ul><ul><li>Declare and get inputs </li></ul></ul></ul><ul><ul><ul><li>Declare and initialize outputs </li></ul></ul></ul><ul><ul><ul><li>While more subtraction to perform </li></ul></ul></ul><ul><ul><ul><ul><li>Update outputs </li></ul></ul></ul></ul><ul><ul><ul><li>Output results </li></ul></ul></ul>
  28. 28. Kelas C <ul><ul><li>Rio Efency – 209512094 </li></ul></ul><ul><ul><li>Monica Amadia – 209512096 </li></ul></ul><ul><ul><li>Made Wisnu Darmadi – 209512101 </li></ul></ul><ul><ul><li>Sovianna Samosir – 209512116 </li></ul></ul><ul><ul><li>Alip Rinjat Moko – 209512120 </li></ul></ul>
  29. 29. Kelas D <ul><ul><li>Maulana Gita Nugraha – 209512128 </li></ul></ul><ul><ul><li>Ariyadi Nugroho – 209512129 </li></ul></ul><ul><ul><li>Eko Wicaksono Putra – 209512136 </li></ul></ul><ul><ul><li>Mochamad Ridwan – 209512146 </li></ul></ul><ul><ul><li>Hafid Wijayanto – 209512149 </li></ul></ul><ul><ul><li>Inggil Rinekso – 208512074 </li></ul></ul>