Slides - Chapter 4

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

This preview shows pages 1–19. 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
C OMPARISON O PERATORS Comparison operators (or relational operators ): Used as part of the condition in an If…Then…Else statement to compare two values Most commonly used comparison operators: Equal to: = Greater than: > Greater than or equal to: >= Less than: < Less than or equal to: <= Not equal to: <> 15

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

View Full Document
How to use comparison operators in a condition 16
How to use comparison operators in a condition (cont’d.) C OMPARISON O PERATORS ( CONT D .) 17

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

View Full Document
C OMPARISON O PERATORS ( CONT ' D .) Comparison operators: Have no order of precedence
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern