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

Info icon This preview shows pages 1–19. 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

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

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

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

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

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

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

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

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

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

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

View Full Document Right Arrow Icon
How to use the If…Then…Else statement (cont’d.) 14
Image of page 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
Image of page 15

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

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

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern