Slides - Chapter 4

Slides - Chapter 4 - CHAPTER 4 MAKING DECISIONS 1 BMGT 302...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
C HAPTER 4 M AKING D ECISIONS BMGT 302 Business Application Programming By Peng Huang R.H. Smith School of Business, University of Maryland 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
T HE S ELECTION S TRUCTURE Selection structure (or decision structure ): A decision need to be made based on the outcome of a condition or comparison Condition : Upon which the decision will be made Results in a Boolean (True or False) answer Single-alternative selection structure : performs a set of tasks only when the condition is true True path : the tasks to perform when the condition is true 2
Background image of page 2
T HE S ELECTION S TRUCTURE ( CONT D .) Dual-alternative selection structure : contains one set of tasks to perform when the condition is true and a different set of tasks to perform when the condition is false False path : the tasks to perform when the condition is false Pseudocode uses if…end if to denote a selection structure and else to denote the false path Indent instructions within the selection structure 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
T HE S ELECTION S TRUCTURE ( CONT ' D .) Selection structures you might use today 4
Background image of page 4
T HE S ELECTION S TRUCTURE ( CONT ' D .) Selection structures you might use today (cont’d.) 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Problem specification for Mountain Biking T HE S ELECTION S TRUCTURE ( CONT ' D .) Interface for the Mountain Biking application 6
Background image of page 6
T HE S ELECTION S TRUCTURE ( CONT ' D .) Pseudocode containing only the sequence structure 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
T HE S ELECTION S TRUCTURE ( CONT ' D .) Modified problem specification and pseudocode containing a single-alternative selection structure 8
Background image of page 8
Single-alternative selection structure shown in a flowchart Note the diamond is called decision symbol 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Modified problem specification and pseudocode containing a dual-alternativ e selection structure 10
Background image of page 10
Dual-alternative selection structure shown in a flowchart 11
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C ODING S INGLE -A LTERNATIVE AND D UAL - A LTERNATIVE S ELECTION S TRUCTURES If…Then…Else statement : used to code single- alternative and dual-alternative selection structures Else clause : an optional part of the If statement Only used for the dual-alternative selection structure Condition must be a Boolean expression that evaluates to either True or False Can contain variables, literal constants, named constants, properties, methods, arithmetic operators, comparison operators, and logical operators Statement block : set of statements in the true path or the false path 12
Background image of page 12
How to use the If…Then…Else statement 13
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
How to use the If…Then…Else statement (cont’d.) 14
Background image of page 14