310 likes | 529 Views
- 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.
E N D
- 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
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
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?
The Structures Code Unstructured Code FLOW CHART SYMBOLS
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
The Structures Code Structured Code • A structure is a basic unit of programming logic. • There are three structure of programming logic: • Sequence • Selection • Loop
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.
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
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
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
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
The Structures Code Structured Code Flowchart and Pseudo code for Sequence within a Selection FLOW CHART SYMBOLS Pseudocode Statements
The Structures Code Structured Code Flowchart and Pseudo code for Loop within Selection within Sequence within Selection FLOW CHART SYMBOLS Pseudocode Statements
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
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
The Structures Code Using the priming read Structured, But Nonfunctional Flowchart
The Structures Code Using the priming read • Functional, But Nonstructural Flowchart
The Structures Code Using the priming read Functional, Structured Flowchart and Pseudo code
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
The Structures Code • Pratice Case1: Base on beside flowchart It is structure logic or not?
The Structures Code • Pratice Case2: Base on below flowchart, It is structure logic or not?
Recognizing Structure and Using Special Structures • There are two special structure in programming logic, there: • Case • Do ... Until / Do ... While / Repeat ... Until
Recognizing Structure and Using Special Structures Sample code using selection structure:
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
Recognizing Structure and Using Special Structures Sample chart and code using case structure:
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
Recognizing Structure and Using Special Structures Sample chart using do..loop structure:
Recognizing Structure and Using Special Structures Sample chart using do..loop structure:
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.