Mark Dixon, SoCCE SOFT 131Page 1 04 – Conditional Execution.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Mark Dixon, SoCCE SOFT 131Page 1 15 – Object Oriented Analysis, Design, and Programming.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Object Oriented Analysis, Design, and Programming.
Selection (decision) control structure Learning objective
Mark Dixon, SoCCE SOFT 131Page 1 09 – Procedures.
Mark Dixon, SoCCE SOFT 136Page 1 05 – Conditional Execution.
Mark Dixon, SoCCE SOFT 136Page 1 02 – Software Development Life-Cycle.
Mark Dixon Page 1 05 – Conditional Execution. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Object Oriented Analysis, Design, and Programming.
Mark Dixon, SoCCE SOFT 131Page 1 07 – Iterative Execution.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 06 – Iteration. Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –Revise Variables and Conditional execution.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging & Graphics.
Mark Dixon, SoCCE SOFT 131Page 1 06 – Iteration. Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 19 – Procedure Parameters.
Mark Dixon, SoCCE SOFT 131Page 1 08 – Procedures.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Software Development Lifecycle, & User Interface Design.
Mark Dixon, SoCCE SOFT 131Page 1 08 – Iterative Execution.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Conditional Execution.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon, SoCCE SOFT 131Page 1 10 – User Defined Functions.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Conditional Execution.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Control Arrays & Container Controls.
Mark Dixon, SoCCE SOFT 136Page 1 06 – Information Processing: Data-types, Constants, Variables.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Debugging, Sound, and Graphics.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Software Development Lifecycle, & User Interface Design.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Mark Dixon, SoCCE SOFT 136Page 1 9 – Procedures. Mark Dixon, SoCCE SOFT 136Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
Mark Dixon 1 05 – Conditional Execution. Mark Dixon 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6 words) currently.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Mark Dixon Page 1 06 – Conditional Execution. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Variables. Mark Dixon, SoCCE SOFT 131Page 2 Admin: Test (next week) In class test –teaching week 6 –university week.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)
Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.
22/11/ Selection If selection construct.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Introduction to Engineering MATLAB - 13 Agenda Conditional statements  If – end  If – else – end  if – elseif – else - end.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Visual BASIC 6.0.
Pay Example (PFirst98) Please use speaker notes for additional information!
Mark Dixon 1 06 – Conditional Execution. Mark Dixon 2 Admin: Test (next week) In class test –teaching week 7 50 minutes short answer (5 - 6 words max)
Mark Dixon Page 1 04 – Conditional Execution. Mark Dixon Page 2 Questions: Expressions a)What is the result of: 10 * Int( ) b)How many functions.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Procedures.
Controlling Program Flow with Decision Structures.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Conditional Execution.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Sequence, Selection, Iteration The IF Statement
06 – Conditional Execution
Microsoft Visual Basic 2005 BASICS
Introduction To Robot Decision Making
Lesson 04 Control Structures I : Decision Making
Computers & Programming Languages
Pages:51-59 Section: Control1 : decisions
Visual Basic – Decision Statements
Decision I (if Statement)
Learning Intention I will learn about programming using selection (making choices) with one condition.
Pages:51-59 Section: Control1 : decisions
Presentation transcript:

Mark Dixon, SoCCE SOFT 131Page 1 04 – Conditional Execution

Mark Dixon, SoCCE SOFT 131Page 2 Admin Technicians (Babbage 205) can provide you with free copies of (bring your own blank CDs): –MS Windows XP Professional (1 CD), includes MS Internet Information Services (term 2) –MS Visual Studio 6.0 (4 CDs), includes Visual BASIC 6.0 Visual InterDev 6.0 Visual C++ 6.0

Mark Dixon, SoCCE SOFT 131Page 3 Session Aims & Objectives Aims –to introduce the main concepts involved in getting the computer to act differently under different circumstances Objectives, by end of this week’s sessions, you should be able to: –evaluate conditional expressions, and –implement decision trees in code

Mark Dixon, SoCCE SOFT 131Page 4 Adaptive Behaviour So far –every statement always executed in sequence Often necessary for software to –change behaviour under different circumstances Example: A Pizza shop provides a delivery service. If the delivery is within five miles of the shop, then no delivery fee is charged. If the cost of the goods is less than £10 then a £3 delivery fee is charged, otherwise a £1.50 delivery fee is charged.

Mark Dixon, SoCCE SOFT 131Page 5 Decision Trees Natural language –ambiguous & difficult to follow Decision trees –express same information clearly Delivery Fee <= 5 miles > 5 miles >= £10 < £10 Free £1.50 £3.00

Mark Dixon, SoCCE SOFT 131Page 6 Conditions & Relational Operators Conditions – expression, evaluates to: –true(stored as –1) –false(stored as 0) contain relational operators: =is equal to >is greater than =is greater than or equal to is not equal to

Mark Dixon, SoCCE SOFT 131Page 7 Examples: Conditions Using literals: (34 = 34)(evaluates to true) (34 = 12)(evaluates to false) (34 > 4)(evaluates to true) (18 <=18)(evaluates to true) Using controls' properties: picMain.Left = 2300 (picMain.Left = 2300) (true) (picMain.Left = 2309 (false) (picMain.Left <> 189 (true) (picMain.Left > 1900 (true)

Mark Dixon, SoCCE SOFT 131Page 8 Logical Operators AndTrue when both items are True (picMain.Top > 5) AND (picMain.Top 55) (false) (picMain.Top > 6) AND (picMain.Top =6) AND (picMain.Top <= 23) (true) OrTrue when either item is True (picMain.Top = 23) OR (picMain.Top = 11) (true) (picMain.Top 55) (false) NotTrue when item is False Not (picMain.Top = 23) (false) Use to join conditions (assume picMain.Top is 23):

Mark Dixon, SoCCE SOFT 131Page 9 Exercise: Conditions What is the result of (picMain.Left is 5589): (picMain.Left > 4400) What is the result of (txtAge.Text is 19, txtSalary.Text is 10787): (txtAge.Text < 21) AND (txtSalary.Text < 10787) Write an expression to: check if picMain.height is larger than Write an expression to: check if picMain.Top is larger than picBall.Top true false (picMain.Height > ) (picMain.Top > picBall.Top)

Mark Dixon, SoCCE SOFT 131Page 10 If Then statements Use the following syntax: If condition Then [statementblock] End If For example: If txtAge.Text < 21 Then lblResult.BackColor = vbRed End If

Mark Dixon, SoCCE SOFT 131Page 11 If Then Else statements Use the following syntax: If condition1 Then [statementblock-1] [Else [statementblock-2]] End If For example: If txtAge.Text Then lblResult.BackColor = vbRed Else lblResult.BackColor = vbBlue End If

Mark Dixon, SoCCE SOFT 131Page 12 Example: Delivery Option Explicit Private Sub btnCalc_Click() If txtDist.Text <= 5 Then lblDel.Caption = 0 Else If txtCost.Text >= 10 Then lblDel.Caption = 1.5 Else lblDel.Caption = 3 End If End Sub Delivery lblDelbtnCalc txtDisttxtCost

Mark Dixon, SoCCE SOFT 131Page 13 Example: Tax Calculator v1 Inland Revenue Private Sub btnCalc_Click() lblTaxableIncome.Caption = "Taxable Income: " & txtGrossSalary.Text - txtAllowance.Text End Sub Salary v1

Mark Dixon, SoCCE SOFT 131Page 14 Example: Tax Calculator v2 Private Sub btnCalc_Click() If txtGrossSalary.Text > txtAllowance.Text Then lblTaxableIncome.Caption = "Taxable Income: £" & txtGrossSalary.Text - txtAllowance.Text Else lblTaxableIncome.Caption = "Taxable Income: £0" End If End Sub Salary v2

Mark Dixon, SoCCE SOFT 131Page 15 Example: Tax Calculator v3 Private Sub btnCalc_Click() If Val( txtGrossSalary.Text ) > Val( txtAllowance.Text ) Then lblTaxableIncome.Caption = "Taxable Income: £" & txtGrossSalary.Text - txtAllowance.Text Else lblTaxableIncome.Caption = "Taxable Income: £0" End If End Sub Salary v3

Mark Dixon, SoCCE SOFT 131Page 16 Example: BallChar v3 Option Explicit Private Sub tmrLeft_Timer() ' You need to work this out! End Sub Private Sub tmrRight_Timer() picBallChar.Left = picBallChar.Left If picBallChar.Left >= Me.ScaleWidth Then tmrRight.Enabled = False tmrLeft.Enabled = True End If End Sub BallChar v3 tmrLeft picBallChar tmrRight

Mark Dixon, SoCCE SOFT 131Page 17 Check Box - give user on/off, yes/no choice –Value: 1 (vbChecked) if selected 0 (vbUnchecked) if not selected Option Box - Used as a group to give user multiple options (only 1 item selected at a time) –Value: -1 (True) if selected 0 (False) if not selected Can place option boxes in Frame control: –groups option boxes Selection/Decision controls

Mark Dixon, SoCCE SOFT 131Page 18 Example: Face v2 Private Sub btnDraw_Click() picFace.Cls picFace.Circle (2400, 2400), 2000 If chkNose.Value = vbChecked Then picFace.Line (2400, 2200)-Step(0, 600) End If If optOpen.Value = True Then picFace.Circle (1600, 1600), 500 picFace.Circle (3200, 1600), 500 Else picFace.Line (1100, 1600)-Step(1000, 0) picFace.Line (2700, 1600)-Step(1000, 0) End If If optHappy.Value = True Then picFace.Circle (2400, 2400), 1200,, 3.4, 6 Else picFace.Circle (2400, 4400), 1200,, 0.6, 2.5 End If End Sub Face