View
219
Download
0
Tags:
Embed Size (px)
Citation preview
Catalog guidelines of 3-4 hours per week per unit
CS 14 Final Grade vs. Class Attendance, Win/Spr 2004
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Class Attendance
AB
C
D
Operators in VB: Part IOperators in VB: Part I
Symbol Name
^ Exponentiation* Multiplication/ Division + Addition - Subtraction
We have seen 5 arithmetic operators
Operators in VB: Part IIOperators in VB: Part II
Symbol Name
= Equality < > Inequality ()< Less Than> Greater Than<= Less Than or Equal To () >= Greater Than or Equal To ()
We have seen 6 relational operators
Operators in VB: Part IIIOperators in VB: Part III
Symbol Name
Not Negation And ConjunctionOr Disjunction
We have seen 3 Boolean operators
Operators in VB: Part IIIIOperators in VB: Part IIII
Symbol Name
& Concatenation
We have seen 1 string operator
Operands in VB: Part IOperands in VB: Part I
Examples of arithmetic operands
5 The literal number 5
-2 The literal number –2
12.4 The literal number 12.4
Dim shtAge As Short The variable shtAge
Dim lngX As Short The variable lngX
Const sngTax = 1.07 The constant sngTax
Operands in VB: Part IIOperands in VB: Part II
Examples of string operands
“A” The literal string “A”
“-2” The literal string “-2”
“Homer” The literal string “Homer”
Dim strName As String The variable strName
Dim strQ As String The variable strQ
Const StrM = “NO” The constant StrM
Operands in VB: Part IIIOperands in VB: Part III
Examples of Boolean operands
True The literal logical value True
False The literal logical value False
Dim blnIsMale As Boolean The variable blnIsMale
Expressions In VB: Part IExpressions In VB: Part I
Expressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
1 1
1 + 1 2
1 + 1 + 1 3
Expressions In VB: Part IIExpressions In VB: Part II
Expressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
(1 + 1 + 1) 3
(1 + 1) * 3 6
10 / 3 3.333333333
1 + 1 2
-(1 + 1) -2
-(-1-1) 2
Expressions In VB: Part IIIExpressions In VB: Part III
Expressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
“Five” “Five”
“5” “5”
“(5 + 5)” “(5 + 5)”
“One” & “Time” “OneTime”
“One” & “ Time” “One Time”
“U” & (2).ToString “U2”
Expressions In VB: Part IIIIExpressions In VB: Part IIII
Expressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
“Five” + 5 illegal
+ 5 illegal
- 5 - 5
“One” & 5 illegal
10 / 0 Runtime error
0 / 10 0
Expressions In VB: Part VExpressions In VB: Part VExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
True True
False False
(True) True
Not(True) False
Not(False) True
Not(Not(False)) False
Expressions In VB: Part VIExpressions In VB: Part VIExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
2 > 1 True
2 < 1 False
(2 > 1) True
2 >= 1 True
(2 >= 2) True
(2 = 2) True
Expressions In VB: Part VIIExpressions In VB: Part VIIExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
Not(2 = 12) True
Not(12 = 12) False
Expressions In VB: Part VIIIExpressions In VB: Part VIIIExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
True And True True
True And False False
False And False False
False Or False False
False Or True True
Not(False Or True) False
Expressions In VB: Part IXExpressions In VB: Part IXExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value
Expression Evaluates to
True And (2 > 1) True
True And (2 = 1) False
(1 = 1) And (2 = 1) False
False Or False Or False False
True Or (False And True) True
(True Or False) And True True
Not((2 * 3 = 1 + 5) And (“U” & “2” = “U2”))
Not(( 6 = 1 + 5) And (“U” & “2” = “U2”))
Not(( 6 = 6 ) And (“U” & “2” = “U2”))
Not(( True ) And (“U” & “2” = “U2”))
Not(( True ) And ( “U2” = “U2”))
Not(( True ) And ( True ))
Not(( True ))
False
Expressions In VB: Part XExpressions In VB: Part XExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value Expression Evaluates to
Dim shtAge As Short
shtAge = 12
(shtAge + 2) 14
Dim shtX As Short
shtX = 0
(shtAge + 11) * 10 11
Expressions In VB: Part XIExpressions In VB: Part XIExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value Expression Evaluates to
Dim shtAge As Short
shtAge = 12
(shtAge > 11) True
Dim shtX As Short
shtX = 0
(11 / shtAge) * 10 Runtime Error
Expressions In VB: Part XIIExpressions In VB: Part XIIExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value Expression Evaluates to
Dim shtS As String
shtS = “Lisa”
(shtS) “Lisa”
Dim shtS As String
shtS = “Lisa”
shtS & “ Simpson” “Lisa Simpson”
Expressions In VB: Part XIIIExpressions In VB: Part XIIIExpressions consist of one or more operands and zero or more operators.
Expressions always evaluate to a single value Expression Evaluates to
Dim blnB As Boolean
blnB = False
(blnB And (12 > 2)) False
Dim shtS As String
shtS = “Lisa”
“Lisa” < “Bart” False
HomeworkRead Drills 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 4.1, 4.2, 4.3, 4,4, 4.5 4.6, 4.7, 4.8, 4.9, 4.10, 4.11, 4.13 and 4.14 in the book (the answers are in the book).
Working in groups of size 1, 2 or 3:Take one question from (3.1, 3.2, 3.3, 3.4, 3.5) and one from (3.6, 3.7, 3.8, 3.9, 3.10) and one from (4.1, 4.2, 4.3, 4,4, 4.5 4.6) and (4.7, 4.8, 4.9, 4.10, 4.11, 4.13, 4.14 ) and write a new version of it.
The next page shows examples of the type and quality of work I expect.
Homework is due on Friday the 15th
Joe Doe (SID 23431) and Jane Doe (SID 855675) Homework 1
1) Drill 3.3 on page 58 is as follows:
If the following code were executed, would an overflow occur? If so, why?
Private Sub btnCalculate_Click(... Dim shtVariable As Integer
shtVariable = 10000 shtVariable = shtVariable * 3End Sub
Private Sub btnCalculate_Click(... Dim shtVariable As Integer
shtVariable = 10000 shtVariable = shtVariable * 3End Sub
Answer: An overflow will not occur.
The exercise is suppose to test our knowledge of the concept of overflowing, which is defined as attempting to place a value into a variable which is too small to hold it. In our modification we have changed the exercise to consider the Long type, instead of the Integer type, and to consider the related concept of underflowing. which is defined as attempting to place a negative value into a variable whose type cannot hold such small values. According to the book, the most negative value a Long can hold is –9,223,372,036,854,775,808. So our example starts by defining a Long, initializing it to –9,223,372,036,854,775,800, then asking the user what will happen if we subtract 5, and what will happen if we subtract another 5. The exercise is below
If the following code were executed, would an overflow occur? If so, why?
Private Sub btnCalculate_Click(... Dim LngVar As Long LngVar = –9,223,372,036,854,775,800 LngVar = LngVar – 5 ‘what happens here? LngVar = LngVar – 5 ‘what about here?End Sub
Private Sub btnCalculate_Click(... Dim LngVar As Long LngVar = –9,223,372,036,854,775,800 LngVar = LngVar – 5 ‘what happens here? LngVar = LngVar – 5 ‘what about here?End Sub
Answer 1: (write an explanation here, ek)