Download presentation
Presentation is loading. Please wait.
Published byValerie Hampton Modified over 8 years ago
1
Chapter 3 IFTHENELSE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured and Object-Oriented Design, 7e
2
Introduction In a SIMPLE SEQUENCE the steps are carried out in a sequential manner. It may be desirable to vary the sequence of processing steps carried out within a solution algorithm.
3
Billing Problem (Flowchart)
4
Billing Example Decision symbol The diamond-shaped symbol. A choice between two alternative paths, or sequences of instructions, is made.
5
Pseudocode Similar to some high-level programming languages, but it does not require that we follow strict rules as we would if actually writing a program.
6
Pseudocode—Introduction
7
IFTHENELSE Control Structure IFTHENELSE control structure A small, circular symbol, called a connector symbol, is used to represent the decision-making logic within the IFTHENELSE pattern
8
IFTHENELSE--Generic
9
Time Card Problem
10
Time Card Example No-function condition—null ELSE The no-function condition is represented by enclosing the key-word ELSE in parentheses.
11
Sample Problem 3.1 Payroll Problem Compute the pay for an employee. Regular pay will be computed as hours (through 40) times rate. Overtime pay (1.5 times hours times rate) for all hours worked over 40.
12
Payroll Problem (Flowchart)
13
Payroll Problem (Flowchart) cont.
14
Payroll Problem (Pseudocode)
15
Finding the Smallest Number (Flowchart)
16
Finding the Smallest Number (Pseudocode)
17
Sample Problem 3.3 Bank Problem Compute the new balance in a customer's bank account. A deposit (code of 1) or withdrawal (code of 2)
18
Bank Problem (Flowchart)
19
Bank Problem (Flowchart) cont.
20
Bank Problem (Pseudocode)
21
Character-String Constant The following information would be output as a result of 3 being input and the WRITE statement: Designate character-string by enclosing it in single or double quotation marks, distinguishing it from a variable name. If we included the variable name CODE within the quotation marks:
22
Character-String Constant Assign the value of a character-string constant to a variable by means of a statement. Use a character-string constant in a decision statement. Compared to the letter D. Compared to the value of the variable D.
23
Sample Problem 3.4 Sales Problem The commission rate is based on two factors, the amount of sales and the class to which the sales person belongs.
24
Sample Problem 3.4
25
Sales Problem (Flowchart)
26
Sales Problem (Pseudocode)
27
Sales Problem (Pseudocode) cont.
28
Sales Problem (Visual Basic— Screen 2)
29
Sales Problem (Visual Basic— Screen 3)
30
Enrichment If the user clicked the Compute Commission a message box will display information to the user.
31
Sales Problem (Visual Basic— Screen 4)
32
Sales Problem (Visual Basic— btnCompute_Click)
33
Sales Problem (Visual Basic— btnCompute_Click) cont.
34
Sales Problem (Visual Basic— btnEnd_Click)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.