1 / 31

- Meeting 2 - Understanding Structure

- Meeting 2 - Understanding Structure. By: Felix Valentin, MBA. Today Topic:. The Structures Code Unstructured Code Structure code Using The priming read Recognizing Structure and Using Special Structures Recognizing Structure The Case Structure Do..Loop structure.

kioko
Download Presentation

- Meeting 2 - Understanding Structure

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. - Meeting 2 -Understanding Structure By: Felix Valentin, MBA

  2. Today Topic: • The Structures Code • Unstructured Code • Structure code • Using The priming read • Recognizing Structure and Using Special Structures • Recognizing Structure • The Case Structure • Do..Loop structure

  3. The Structures Code Unstructured Code Number-doubling FLOW CHART SYMBOLS Pseudocode Statements Get Number Get Number Result = Number * 2 Print Result Result = Number * 2 Print Result

  4. The Structures Code Unstructured Code Spaghetti Code, When you add several thousand instructions to a program, including several hundred decisions, it is easy to create a complicated mess. Example case: HRD want to recruit a new employee, and have a several criteria to accept. Now how to translate this case to structure code logic?

  5. The Structures Code Unstructured Code FLOW CHART SYMBOLS

  6. The Structures Code Unstructured Code Pseudocode Statements BEGIN Get Iq, Exp IF (Iq > 120) THEN BEGIN IF (Exp > 1) THEN PRINT “ACCEPT” ELSE PRINT “REJECT” END ELSE IF (Iq > 100) THEN BEGIN IF (Exp > 3) THEN PRINT “ACCEPT” ELSE PRINT “REJECT” END ELSE IF (Iq > 80) THEN BEGIN IF (Exp > 5) THEN PRINT “ACCEPT” ELSE PRINT “REJECT” END ELSE PRINT “REJECT” END

  7. The Structures Code Structured Code • A structure is a basic unit of programming logic. • There are three structure of programming logic: • Sequence • Selection • Loop

  8. The Structures Code Structured Code • Sequence • Use to preform an action or event • A sequence can contain any number of events, but there is no chance to branch off and skip any of the events.

  9. The Structures Code Structured Code • Selection • With this structure, you ask a question, and depending on the answer, you take one of two courses of action • Some people call the selection structure an if-then-else because it fits the statement

  10. The Structures Code Structured Code • Selection with single course • In these cases you don’t take any special action. Example: if it is not raining or if the employee does not belong to the dental plan • The case where nothing is done is often called the null case

  11. The Structures Code Structured Code • Looping • Sometime also refer as repetition or iteration • In a loop, you ask a question; if the answer requires an action, you perform the action and ask the original question again

  12. The Structures Code Structured Code • All logic problems can be solved using only these three structures—sequence, selection, and looping • The three structures, of course, can be combined in an infinite number of ways • Attaching structures end-to-end is called stacking structures • Placing a structure within another structure is called nesting the structures

  13. The Structures Code Structured Code Flowchart and Pseudo code for Sequence within a Selection FLOW CHART SYMBOLS Pseudocode Statements

  14. The Structures Code Structured Code Flowchart and Pseudo code for Loop within Selection within Sequence within Selection FLOW CHART SYMBOLS Pseudocode Statements

  15. The Structures Code Structured Code

  16. The Structures Code Using the priming read • A priming read or priming input is the first read or data input statement in a program • If a program will read one hundred data records, you read the first data record in a statement separate from the other ninety-nine • With a selection structure, the logic goes in one of two directions after the question; then the flow comes back together • With a selection structure, the question is not asked a second time

  17. The Structures Code Using the priming read FLOW CHART SYMBOLS Pseudocode Statements BEGIN DO READ inputnumber CalculatedAnswer = inputnumber *2 PRINT CalculatedAnswer WHILE (NOT EOF) END

  18. The Structures Code Using the priming read Structured, But Nonfunctional Flowchart

  19. The Structures Code Using the priming read • Functional, But Nonstructural Flowchart

  20. The Structures Code Using the priming read Functional, Structured Flowchart and Pseudo code

  21. The Structures Code Using the priming read • Until you have some programming experience, it is difficult to appreciate the reasons for using nothing other than the three structures • However, staying with these three structures is better for the following reasons: • Clarity • Professionalism • Efficiency • Maintenance • Modularity

  22. The Structures Code • Pratice Case1: Base on beside flowchart It is structure logic or not?

  23. The Structures Code • Pratice Case2: Base on below flowchart, It is structure logic or not?

  24. Recognizing Structure and Using Special Structures • There are two special structure in programming logic, there: • Case • Do ... Until / Do ... While / Repeat ... Until

  25. Recognizing Structure and Using Special Structures Sample code using selection structure:

  26. Recognizing Structure and Using Special Structures • Base on previous case we can use CASE structure. • When using the case structure, you test a variable against a series of values, taking appropriate action based on the variable’s value • Even though a programming language permits you to use the case structure, you should understand that the case structure is just a convenience that might make a flowchart, pseudo code, or actual program code easier to understand at first glance

  27. Recognizing Structure and Using Special Structures Sample chart and code using case structure:

  28. Recognizing Structure and Using Special Structures • Do Loop Structure • In a do while loop, you ask a question and, depending on the answer, you might never enter the loop to execute the loop’s procedure • Conversely, in a do until loop you ensure that the procedure executes at least once; then, depending on the answer to the controlling question, the loop may or may not execute additional times

  29. Recognizing Structure and Using Special Structures Sample chart using do..loop structure:

  30. Recognizing Structure and Using Special Structures Sample chart using do..loop structure:

  31. Practice Case: • Create a flowchart and Pseudo code for counting sigma function. • Create a flow chart and pseudo code for this condition below, if the user input a product name and qty, application must sum amount of value of the product.

More Related