Slides - Chapter 4

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

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

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

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

View Full Document
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
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

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

View Full Document
T HE S ELECTION S TRUCTURE ( CONT ' D .) Selection structures you might use today 4
T HE S ELECTION S TRUCTURE ( CONT ' D .) Selection structures you might use today (cont’d.) 5

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

View Full Document
Problem specification for Mountain Biking T HE S ELECTION S TRUCTURE ( CONT ' D .) Interface for the Mountain Biking application 6
T HE S ELECTION S TRUCTURE ( CONT ' D .) Pseudocode containing only the sequence structure 7

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

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

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

View Full Document
Modified problem specification and pseudocode containing a dual-alternativ e selection structure 10
Dual-alternative selection structure shown in a flowchart 11

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

View Full Document
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
How to use the If…Then…Else statement 13

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

View Full Document
How to use the If…Then…Else statement (cont’d.) 14