Mark Dixon, SoCCE SOFT 131Page 1 03 – Information Processing: Expressions, Operators & Functions.

Slides:



Advertisements
Similar presentations
Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Advertisements

Mark Dixon Page 1 05 – Constants and Variables. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 mins short answer (5 - 6 words.
Mark Dixon, SoCCE SOFT 136Page 1 05 – Conditional Execution.
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 136Page 1 11 – User Defined Functions.
Mark Dixon, SoCCE SOFT 131Page 1 07 – Iterative Execution.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Information Technology Center Hany Abdelwahab Computer Specialist.
CIS101 Introduction to Computing Week 10 Spring 2004.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Software Development Lifecycle, & User Interface Design.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Passing Data between pages: Sessions, Query Strings, & Self Posting.
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 03 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Constants and Variables.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Conditional Execution.
CIS101 Introduction to Computing Week 10. Agenda Your questions Final exam and final project CIS101 Student Survey Class presentations: Your Mad Libs.
Mark Dixon, SoCCE SOFT 136Page 1 06 – Information Processing: Data-types, Constants, Variables.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon Page 1 04 – Data Types. Mark Dixon Page 2 Admin: On-line Quiz.
Visual Basic Chapter 1 Mr. Wangler.
Mark Dixon Page 1 10 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of code to declare a variable called h Write a line of.
CS0004: Introduction to Programming Variables – Numbers.
02 – Client-side code: JavaScript
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 1B Introduction (Tutorial)
Mark Dixon 1 07 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
Mark Dixon Page 1 09 – Arrays. Mark Dixon Page 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
M Dixon 1 04 – Data Types & Debugging. Questions: Expressions a)What is the result of: 7 + Int(8.245) b)Write an expression to: put a random number into.
Chapter 12: How Long Can This Go On?
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.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon 1 11 – Array Variables. Mark Dixon 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Mark Dixon Page 1 10 – Array Variables. Mark Dixon Page 2 C1 – In-class test Results mixed: –quite a few fails 34% (13/38) –some very good (91% max) ask.
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.
Mark Dixon 1 08 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
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.
Mark Dixon Page 1 05 – Problem Solving & Data Types.
Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)
Mark Dixon 1 14 – Functions and Modules. Mark Dixon 2 Questions: Parameters Consider the following code: Sub Move(ByRef obj, ByVal dist) obj.style.posLeft.
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon 1 03 – Information Processing. Mark Dixon 2 Questions: Events Consider the following code: a) How many unique events does it contain? b) Name.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon 1 9 – Case Study. Mark Dixon 2 Session Aims and Objectives Aims –To give an overview of the development of a web-page from initial idea to.
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
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)
Trigonometric Functions. A Block Data B Block Data.
Mark Dixon Page 1 05 – Problem Solving & Data Types.
M Dixon 1 02 – Dynamic HTML (client-side scripting)
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 Page 1 03 – Information Processing: Expressions, Operators & Functions.
Tutorial 11 1 JavaScript Operators and Expressions.
Mark Dixon 1 13 – Parameters. Mark Dixon 2 Question: Arrays How many array variables are in the following code: Dim x Dim y Dim f(4) x = 12 y = 6 f(2)
Chapter 13 Right Angle Trigonometry
Mark Dixon Page 1 09 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of VBScript code to declare a variable called h Write.
Mark Dixon Page 1 03 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Conditional Execution.
Visual Basic.NET Windows Programming
04 – Information Processing: Expressions, Operators & Functions
02 – Information Processing
06 – Conditional Execution
08 – Iterative Execution.
Presentation transcript:

Mark Dixon, SoCCE SOFT 131Page 1 03 – Information Processing: Expressions, Operators & Functions

Mark Dixon, SoCCE SOFT 131Page 2 Questions: Events Consider the following code: a) How many unique events does it contain? b) Name the event(s). Sub btnAns_OnClick() document.bgcolor = "yellow" lblComment.innertext = "Correct, well done!" document.bgcolor = "cyan" lblComment.innertext = "Sorry, try again" End Sub 1 Click OnClick

Mark Dixon, SoCCE SOFT 131Page 3 Questions: Properties Consider the following code: a) How many unique properties does it contain? b) Name the properties. Sub btnAns_OnClick() document.bgcolor = "yellow" lblComment.innertext = "Correct, well done!" document.bgcolor = "cyan" lblComment.innertext = "Sorry, try again" End Sub 2 bgcolor, innertext

Mark Dixon, SoCCE SOFT 131Page 4 Questions: Keywords Consider the following code: a) How many unique keywords does it contain? b) Name the keywords. Sub btnAns_OnClick() document.bgcolor = "yellow" lblComment.innertext = "Correct, well done!" document.bgcolor = "cyan" lblComment.innertext = "Sorry, try again" End Sub 2 Sub End

Mark Dixon, SoCCE SOFT 131Page 5 Session Aims & Objectives Aims –Introduce you to main processing concepts, i.e. expressions, operators and functions Objectives, by end of this week’s sessions, you should be able to: –evaluate expressions –assign a value to a object's property, using combination of literal values, operators, functions, and identifiers

Mark Dixon, SoCCE SOFT 131Page 6 Meet George Common Boa Constrictor –boa constrictor imperator Native to Central & South America No venom (no poison)

Mark Dixon, SoCCE SOFT 131Page 7 Looking after George Problem: –Difficult to keep –Require temperature and humidity controlled environment –Much of the literature is from the US Temperature in Fahrenheit: 80-85F day, 78F minimum at night (P Vosjoli 1998) Solution –Need a program to convert from Celsius to Fahrenheit

Mark Dixon, SoCCE SOFT 131Page 8 Example: Temp User Requirements –describe user's objectives no mention of technology Software Requirements –Functional list facilities to be provided (often numbered) –Non-functional list desired characteristics (often more subjective) SPECIFICATION User Requirements –help snake keeper convert from fahrenheit to celcius Software Requirements –Functional: –enter fahrenheit value –display celsius value –Non-functional should be quick and easy to use

Mark Dixon, SoCCE SOFT 131Page 9 Information Processing All computing problems: –involve processing information/data information has meaning (e.g. 5lb 3.3kg 18 years) data has no meaning (e.g ) –following this pattern: For example: –to add two numbers: = 16 Input DataProcessOutput Data

Mark Dixon, SoCCE SOFT 131Page 10 Information Processing (cont.) Hence, to solve any computing problem ask: –what information goes in –what processing is done to it –what information comes out

Mark Dixon, SoCCE SOFT 131Page 11 Example: Temp (User Interface) Temperature Fahrenheit: 0

Mark Dixon, SoCCE SOFT 131Page 12 To convert from Fahrenheit to Celsius: e.g. Fahrenheit is: Example: Temp (processing) c = 10 FahrenheitProcessCelsius 50

Mark Dixon, SoCCE SOFT 131Page 13 Operators Sit between the data = assignment operator addition operatorresult is subtraction operatorresult is 3 5 * 2 multiplication operatorresult is 10 5 / 2 division operatorresult is 2.5 convert mathematical symbols into operators: c = ((f – 32) * 5) / 9

Mark Dixon, SoCCE SOFT 131Page 14 Symbolic Representation Symbols (names) represent data txtFah.Value = 50 replace mathematical symbols with objects: parCel.innertext = ((txtFah.value - 32) * 5) / 9 Puts 50 into txtFah.Value The symbol txtFah.Value now represents 50

Mark Dixon, SoCCE SOFT 131Page 15 The following assignment statement: parCel.innertext = ((txtFah.value - 32) * 5) / 9 contains an expression Expressions Given: txtFah.Value = "68" can evaluate expression: parCel.innertext = ((txtFah.value - 32) * 5) / 9 (from above) parCel.innertext = (( ) * 5) / 9 (substitute) lblResult.InnerText = 20 (calculate)

Mark Dixon, SoCCE SOFT 131Page 16 Example: Temp (code) Untitled Page Sub btnCalc_OnClick() parCel.innertext = ((txtfah.value - 32) * 5) / 9 End Sub Fahrenheit: 0

Mark Dixon, SoCCE SOFT 131Page 17 Expression Evaluation

Mark Dixon, SoCCE SOFT 131Page 18 Expression Errors txtNum1.Value * * 12 + txtNum1.Value d o o d o d txtNum1.Value + 1 – d o d o d d many people instinctively know these are wrong data operator data operator

Mark Dixon, SoCCE SOFT 131Page 19 Example: Ball Char (v2) Functional Decomposition Incremental Development Get ball char to move automatically: –get ball char to appear on left of page –get ball char to move right on page

Mark Dixon, SoCCE SOFT 131Page 20 Client-side Object Model window object – properties include: –.status: get/set status bar window.status = “Hello” –.close: close current window window.close –.SetInterval: allow timed actions document object – properties include: –.title: get/set title of page –.write: write text to page –.bgColor: get/set background colour of page –.location: get/set current location of browser

Mark Dixon, SoCCE SOFT 131Page 21 Example: Ball Char (v2) Ball Char v2 Sub window_OnLoad () window.SetInterval "MoveBallRight", 50 End Sub Sub MoveBallRight () picBall.hspace = picBall.hspace + 5 End Sub Procedure name Interval (in milliseconds: 1000 = 1s)

Mark Dixon, SoCCE SOFT 131Page 22 Functions & Operators Used to: –process (manipulate) data Both Functions & Operators: –take input data/parameters (1 or more item) –process it –return a result which replaces the expression (substitution) Parameter(s) Result SQR Function (16)4

Mark Dixon, SoCCE SOFT 131Page 23 Functions (cont.) Functions: come before the data (which is in brackets) Sqr(16) square rootresult is 4 Abs(-23) absolute valueresult is 23 Int(2.543) integerresult is 2 Sin(3.1) sineresult is Cos(0) cosineresult is 1

Mark Dixon, SoCCE SOFT 131Page 24 Questions: Expressions a)What is the result of: Int(12.93) / 2 b)What is the result of: 1 + Int( ) + Sqr(Int(9.4523)) c)Write an expression to: give the square root of 9 d)Write an expression to: give the integer value of = 9 Sqr(9) Int( )

Mark Dixon, SoCCE SOFT 131Page 25 Absolute Positioning change properties – change position picBall.style.pixeltop picBall.style.pixelleftpicBall.width picBall.height document.body.clientwidth

Mark Dixon, SoCCE SOFT 131Page 26 Example: Space v1 Space Explorer Sub window_OnLoad() Randomize imgAstr.style.pixeltop = 100 End Sub Sub btnRand_OnClick() imgAstr.style.pixelleft = CInt( Rnd() * 300) parRand.innertext = imgAstr.style.pixelleft End Sub Shuffles random number generator Picks random number between 0 and 1

Mark Dixon, SoCCE SOFT 131Page 27 Example: Navigation Survey ship –mapping sea bed –must avoid oil rigs –8km of streamers (with hydrophones) –7-9 hours to turn know –cable length (500m) –cable angle work out –how far out

Mark Dixon, SoCCE SOFT 131Page 28 Example: Navigation Need to ensure horizontal distance –between ship and outer bouy (a) is less than –between ship and oil rig (b) bouy moves with current sensor equipment worth ~£30 million impossible to replace quickly a b

Mark Dixon, SoCCE SOFT 131Page 29 Trigonometry: Triangles hypotenuse (H) =500m opposite (O) adjacent (A) SOH CAH TOA Sin(ang) = O/H O = Sin(ang) * H Cos(ang) = A/H A = Cos(ang) * H Tan(ang) = O/A angle (ang)

Mark Dixon, SoCCE SOFT 131Page 30 Trigonometry: Radians Radians used by computers instead of degrees: 0 or 360 deg (0 or 6.2 rad) 90 deg (1.55 rad) 180 deg (3.1 rad) (4.65 rad) 270 deg rad = (deg/180) * 3.1 π π/2

Mark Dixon, SoCCE SOFT 131Page 31 Example: Navigation Navigation Sub Window_OnLoad() imgShip.style.left = 100 imgShip.style.top = 200 imgOilR.style.left = 150 imgOilR.style.top = 100 End Sub Angle:

Mark Dixon, SoCCE SOFT 131Page 32 Tutorial Exercises: Temperature LEARNING OBJECTIVE: to assign a value to a object's property, using combination of literal values, operators, functions, and identifiers Task 1: get the temperature example working Task 2: modify the temperature example so that it has two extra buttons – a plus and minus to increase and decrease the temperature

Mark Dixon, SoCCE SOFT 131Page 33 Tutorial Exercises: Exchange LEARNING OBJECTIVE: to assign a value to a object's property, using combination of literal values, operators, functions, and identifiers Task 1: create a new page that helps the user covert from Pounds to Dollars use the web to find the current exchange rate Task 2: Use the FormatNumber function to display the result to 2 decimal places. HINT: FormatNumber( , 3) gives

Mark Dixon, SoCCE SOFT 131Page 34 Tutorial Exercises: Ball Char LEARNING OBJECTIVE: to assign a value to a object's property, using combination of literal values, operators, functions, and identifiers Task 1: get the ball char (v2) example working Task 2: add a button that resets the ball char's horizontal position to 0 Task 3: add a text box that allows the user to enter the rate of increase Task 4: add a button that stops the ball char moving. HINT: button should put 0 into the text box Task 5: add two buttons – one for fast and one for slow Task 6: add two more buttons – one for fast backwards and one for slow backwards Task 7: use the properties window to hide the speed text box. Task 8: change the page to use absolute positioning.

Mark Dixon, SoCCE SOFT 131Page 35 Tutorial Exercises: Navigation LEARNING OBJECTIVE: to assign a value to a object's property, using combination of literal values, operators, functions, and identifiers Task 1: get the Navigation example working when the user clicks the Calc button, your program should calculate the angle in radians, and use this to re-position the bouy Task 2: modify the Navigation example so that the plus and minus buttons change the number of degrees by a value of 5