Program Design and Branching Structures - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Program Design and Branching Structures

Description:

Lecture 2. Program Design and Branching Structures ... Decomposition, Step-Wise Refinement (Done with PseudoCode), Unit Testing, Program Testing, etc. ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 24
Provided by: macli
Category:

less

Transcript and Presenter's Notes

Title: Program Design and Branching Structures


1
Lecture 2
2
  • Program Design and Branching Structures
  • Introduction to Top-Down Design Techniques
  • Software Engineering
  • Big Codes REQUIRE Prior Analysis
  • Top-Down Design gt Standard Engineering Practice
    gt
  • Start with a big problem, break it into its
    components and solve
  • Keywords gt Software Engineering, Top-Down
    Design, Structured Programming, Algorithm,
    Decomposition, Step-Wise Refinement (Done with
    PseudoCode), Unit Testing, Program Testing, etc.)

3
(No Transcript)
4
  • Use of Pseudocode and Flowcharts
  • Graphical Description of Algorithms

5
(No Transcript)
6
  • Logical Constants, Variables and Operators
  • 3.3.1 Logical Constants and Variables
  • Logical constants .TRUE. , .FALSE.
  • Logical variable contains a logical value, i.e.,
    either .TRUE. or .FALSE.
  • Logical variables type specified as
  • LOGICAL V1, V2, V3, etc.
  • Example V1 .TRUE.
  • 3.3.2 Assignment Statements and Logical
    Calculations
  • General Form
  • Logical variable name logical expression (T or
    F)

7
  • 3 Relational Operators
  • Operate on Numeric Values to Produce Logical
    Result
  • General Form v1 .op. v2, where .op. is as
    follows
  • or
    .eq. Equal to
  • / or .ne. Not
    equal to
  • gt or
    .gt. Greater than
  • gt or
    .ge. Greater than or equal to
  • lt or
    .lt. Less than
  • lt or .le. Less
    than or equal to

  • (New) (Old)
  • Examples 3lt4 is T 3gt4 is F AgtB is F.
    (Alphabetical order)
  • Relational operations done after ALL arithmetic
    operations
  • Example 73 lt 211 What would happen if ALL
    ops were left to right?

8
Combinational Logical Operators
9
  • Logical Operators Operate on Logical Values to
    Produce a
  • Logical
    Result.
  • General Form l1 .op. l2, where .op. is as
    follows
  • .AND. Logical
    AND
  • A.AND.B If A and B are True, then logical
    expression is True.
  • .OR. Logical
    OR
  • A.OR.B If A or B is True, logical expression
    is True.
  • .EQV. Logical
    Equivalence
  • A.EQV.B If A is the same (T,F) as B, logical
    expression is True.
  • .NEQV. Logical
    Non-Equivalence
  • A.NEQV.B If A and B are different, logical
    expression is True.
  • .NOT. Logical
    NOT
  • .NOT.A A is changed to the reverse of A,
    i.e., TgtF, FgtT.
  • Hierarchy of Computational Operations (Within
    parentheses)
  • Arithmetic operations
  • Relational operations (LgtR)
  • .NOT. operators
  • .AND. operators (LgtR)
  • .OR. operators (LgtR)

10
  • Logical Values in I/O Statements
  • Input First T or F in next input field defines
    the variable. Error otherwise.
  • Output T output for a TRUE variable, F for a
    FALSE Variable.
  • Significance of Logical Variables and
    Expressions
  • Logical values are rarely the final result of
    Fortran programs.
  • Primarily used in controlling Branching and
    Looping Structures

11
  • Control Constructs Branches
  • IF statement and SELECT CASE statement
  • 3.4.1 Block IF Construct
  • Block of code executed only if logical
    expression is .T.
  • IF (logical expression) THEN
  • Statement 1 (Note indented code)
  • Statement 2
  • END IF

12
  • The ELSE and ELSE IF Clauses
  • IF (logical expression) THEN
  • Statement 1
  • Statement 2
  • ELSE IF (logical expression) THEN
  • Statement 1
  • Statement 2
  • ELSE IF (logical expression) THEN
  • Statement 1
  • Statement 2
  • ELSE
  • Statement 1
  • Statement 2
  • END IF
  • Note that ELSE is not required in above

13
(No Transcript)
14
(No Transcript)
15
(No Transcript)
16
(No Transcript)
17
(No Transcript)
18
  • Named Block IF Constructs
  • Optionally name Block IF Statements Helps us
    keep code straight
  • Ex L1 IF (logexp) THEN
  • ..........
  • L2 IF (logexp) THEN
  • .
  • L3 IF (Logexp) THEN
  • .
  • END IF L3
  • .
  • END IF L2
  • .
  • END IF L1

19
  • Notes Concerning Use of Block IF Constructs
  • Suggestion Use Names and Indented Form for
    Nested Block IFs.
  • 3.4.6 Logical IF Statement
  • IF (logical expression) Statement
  • Ex 1 IF (GOTO) GO TO 100
  • Ex 2 IF (GOTO) IF (A-B) 100,101,102

20
  • The SELECT CASE Construct
  • Form name SELECT CASE (case expr)
  • CASE (case value)
  • Statement Block Execute if case expr case
    value
  • Or
  • CASE (low value )
  • Statement Block Execute if case expr gt low value
  • Or
  • CASE ( high value)
  • Statement Block Execute if case expr lt high
    value
  • Or
  • CASE (low value high value)
  • Statement Block Execute if low value lt case expr
  • And high value gt case expr
  • END SELECT name

21
Example 1
22
Example 2
23
  • More on DeBugging
  • Use correct Relational/Logical Operators
  • Testing Real Variables for Equality a NoNo!
Write a Comment
User Comments (0)
About PowerShow.com