DOC PREVIEW
MSU LBS 126 - Decision Structures
Course Lbs 126-
Pages 21

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Decision StructuresSpacecraftDecisions (If Statements)QuestionsIf StatementsComparison OperatorsLogical OperatorsBoolean valueTest for SnowingAnds and OrsIf Blocks (True and False Options)If-then-else BlocksNested if-then-else structureIf –ElseIf – Else BlocksWhat if you have a bunch of choices?Select Case BlocksName CaseQuadratic equationSolutionQuadratic Formula SolverQuadratic EquationDecision StructuresSpacecraft•Divine Vessel V will orbits earth 14 times in 21 hours•First manned spacecraft of China, only the third country that can sendDecisions (If Statements)•Comparison Operators (>, < , <>, …)•Logical Operators (and, or, not)•TRUE or FALSE determines whether to proceed!QuestionsIfTemp < 32ThenIt is warm! It is COLD!TrueFalseIf Statements•If weather = “PRECIPITATION” Then•It is raining or snowing•If TEMP < 32 Then•It is COLD!If temp < 32 Then picture1.print “It is FREEZING!”End IfComparison Operators•See table 5.1•= equal to•<> unequal to•< less than•> greater than•<= less than or equal to•>= greater than or equal to•Works both for numbers and strings.Logical Operators•And, Or, Not•a >=b And b <> 2•a >=b Or b <> 2•And statements: Both must be true•Or statements: one or both must be true•Not statements: True if statement is falseBoolean value•Comparison operator and logical operator will return a Boolean value.•Boolean value has only two possibilities: True and FalseTest for Snowing•What are conditions for snowing?•Temperature?•Precipitation?Ands and Ors•If (weather = “PRECIPITATION”) And (TEMP < 32) Then•Tests for snow•If (weather = “PRECIPITATION”) Or (TEMP < 32) Then•Tests for bad weatherPRECIPNO<32>32NO< 32> 32And OrTFFF TTFTPRECIPIf Blocks (True and False Options)If condition1 Then …Statements…Else …Statements…End IfIf-then-else BlocksIf temp < 32 Then picture1.print “It is FREEZING!”Else picture1.print “It is not freezing”End IfNested if-then-else structureIf weather = “PRECIPITATION” thenIf TEMP <32 thenPicture1.Print “Snowing”ElsePicture1.Print “raining”End ifElse If TEMP <32 thenPicture1.Print “cold day”ElsePicture1.Print “warm day”End ifEnd ifIf –ElseIf – Else Blocks‘Get answer to question, “Did you‘have a fun spring break?” answer = Ucase(text1.text)answer = Trim(answer)If answer=“YES” Then picture1.print “Cool.”ElseIf answer=“NO” Thenpicture1.print “Sorry.”Else picture1.print “Can’t you even answer the question?”End IfWhat if you have a bunch of choices?•Case Selectors are great for multiple choices•Best for equalities, not inequalitiesSelect Case Blocks•Allows multiple options (not just true or false)Select Case Variable Case Condition1 Case Condition2 Case Condition3 Case ElseEnd SelectName CaseSelect Case Name Case “George W. Bush” picture1.print “Bring them on.” Case “terminator T-100” picture1.print “Alta vista babe.” Case “Conan O'Brien” picture1.print “This is such a good show. What a nice show... Great show” Case Else picture1.print “Wow, who is this guy!”End SelectQuadratic equation•aX2+bX+c=0•What is the solution to X?SolutionQuadratic Formula SolverQuadratic Equation•Write an algorithm for using the quadratic formula to determine if there are real roots for the equation•Will the program crash if b2-4ac < 0? •If you take square root for a negative number you will get a run time error.•The program should be able to deal with both real and complex


View Full Document

MSU LBS 126 - Decision Structures

Course: Lbs 126-
Pages: 21
Download Decision Structures
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Decision Structures and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Decision Structures 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?