04 information processing expressions operators functions
This presentation is the property of its rightful owner.
Sponsored Links
1 / 19

04 – Information Processing: Expressions, Operators & Functions PowerPoint PPT Presentation


  • 63 Views
  • Uploaded on
  • Presentation posted in: General

04 – Information Processing: Expressions, Operators & Functions. 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

Download Presentation

04 – Information Processing: Expressions, Operators & Functions

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


04 information processing expressions operators functions

04 – Information Processing:Expressions, Operators & Functions


Session aims objectives

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


Information processing

Information Processing

Input Data

Process

Output Data

7

*

63

9

  • All computing problems:

    • involve processinginformation/data

      • information has meaning (e.g. 5lb 3.3kg 18 years)

      • data has no meaning (e.g 5 3.3 18)

    • following this pattern:

  • For example:

    • to multiply two numbers: 7 * 9 = 63


Information processing cont

Information Processing (cont.)

  • Hence, to solve any computing problem ask:

    • what information goes in

    • what processing is done to it

    • what information comes out


Example multiply

Example: Multiply

txtNum1

lblResult

txtNum2

btnMultiply

Option Explicit

Private Sub btnMultiply_Click()

lblResult.Caption = txtNum1.Text * txtNum2.Text

End Sub


Expressions

Expressions

  • The following assignmentstatement:lblResult.Caption = txtNum1.Text * txtNum2.Textcontains an expression

  • Given: txtNum1.Text = "7",txtNum2.Text = "9"can evaluate expression:lblResult.Caption = txtNum1.Text * txtNum2.Text(from above)lblResult.Caption = "7" * "9"(substitute)lblResult.Caption = 63(calculate)


Expression evaluation

Expression Evaluation


Operators

Operators

  • Sit between the data5 + 2 addition operatorresult is 7 5 - 2 subtraction operatorresult is 3 5 * 2 multiplication operatorresult is 10 5 / 2 division operatorresult is 2.5 "5" & "2" string concatenationresult is "52"

  • work with objects:txtNum1.Text * txtNum2.Text


Symbolic representation

Symbolic Representation

  • Symbols (names) representing data

    txtNum1.Text = "33"

  • Key concept in programming

Puts 33 into txtNum1.TextThe symbol txtNum1.Text

now represents 33


Numeric expressions

Numeric Expressions

many people instinctivelyknow these are wrong

data

data

data

data

  • 23 + 11 - txtNum1.Text * 2

  • 34 + * 12 + txtNum1.Text d o o d o d

  • txtNum1.Text + 1 – 21 45 d o d o d d

operator

operator

operator


String expressions

String Expressions

data

data

data

data

operator

operator

operator

  • "What is " & num1 & " times " & num2

  • "What is twice " num1 & "?"

  • "What is 6 minus " & & num & "?"

ERROR! missing operator

ERROR! missing data


Example addnum v1

Example: AddNum v1

txtNum1

lblResult

txtNum2

btnAdd

Option Explicit

Private Sub btnAdd_Click()

lblResult.Caption = txtNum1.Text + txtNum2.Text

End Sub


Types of information

Types of Information

  • Numbers (numeric)29 (integer/whole) 56.23(decimal/real)

  • Text (string)"Hello there!""BOO"

  • Pictures

  • Sound


Addnum problem

AddNum problem

  • The + operator works with:

    • numbers, and

    • text

  • Double Quotes " used in VB to show literal text

  • Text input boxes store text

23 + 16 = 39

"23" + "16" = "2316"


Functions operators

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)

Function

Parameter(s)

Result

SQR

(16)

4


Functions cont

Functions (cont.)

  • Functions: come before the data (which is in brackets)Sqr(16) square rootresult is 4Abs(-23) absolute valueresult is 23Int(2.543) integerresult is 2CInt("63") integer convertresult is 63Left("boo",2) left stringresult is "bo"Right("hello",3) right stringresult is "llo"Mid("hello",2,2) middle stringresult is "el"


Questions expressions

Questions: Expressions

  • What is the result of: 1 + CInt("23") + Int(2.76786) + Sqr(Int(9.4523))

  • What is the result of: "23" & "18" + Left("bob",1) + Right("sal",2)

  • Write an expression to:give integer value of "16.7658765"

  • Write an expression to:give the first two letters of "Mr John Smith"

1 + 23 + 2 + 3 = 29

"23" & "18" & "b" & "al" = "2318bal"

Int(CInt("16.7658765"))

Left("Mr John Smith", 2)


Example addnum v2

Example: AddNum v2

Option Explicit

Private Sub btnAdd_Click()

lblResult.Caption = CInt(txtNum1.Text) + CInt(txtNum2.Text)

End Sub


Tutorial exercises

Tutorial Exercises

  • Task 1: get the multiply example (from the lecture) working

  • Task 2: get the addnum examples v1 and v2 (from the lecture) working

  • Task 3: create a project with two text boxes (surname and forenames), and a button (initials). When the button is clicked the first character from each text box (i.e. the person's initials) should be displayed.

  • Task 4: create a new page that helps the user covert from Pounds to DollarsGo on-line and look up the current exchange rate

  • Task 5: modify your currency converter, so that the result is displayed to 2 decimal places, e.g. $62.45(you will need to use the Format function, look it up in the help system for an explanation)

  • Task 6: modify your currency converter, replace the dollar label with a text box, and add another button that converts the dollar value back to pounds.

  • Task 7: modify your currency converter, so that when the user types into the pounds text box only the appropriate button is enabled.


  • Login