Download presentation
Presentation is loading. Please wait.
1
5.03 Apply operators and Boolean expressions
Computer Programming I
2
Objective/Essential Standard
Essential Standard: 5.00 Apply Programming & Conditional Logic Indicator: 5.03 Apply operators and Boolean expressions. (3%)
3
Operators What are operators? Welcome back to Math class!
Operators are the symbols we use for performing math. You have used them since early in life. There are several types of operators. Basic Math operators, Boolean and Relational Operators. We will use all of these in programing. For now let’s look at the math operators.
4
Basic Math Operators These you are familiar with: + (add),
- (subtract) / (divide) * (multiply) ^ (Exponents) There are 2 other types of division in programming: \ integer division - returns the integer portion of the quotient. Mod (Modulus division) - returns the remainder portion of the division.
5
More on the 3 Types of Division
Regular division Rounds the decimal portion if assigned to an integer. Show the decimal portion if assigned to a double. This is the division with which you are most familiar. Integer division cuts off the decimal portion and returns just the integer ( \ ) Modulus division returns the remainder portion of the quotient (mod)
6
Order of Operations Just as in math, Please Excuse My Dear Aunt Sally describes the precedence applied to math in programming Parentheses Exponents Multiply – from left to right Divide (NOTE: Division will be complete in the order in which it appears in the problem, no ranking with division types.) Add– from left to right Subtract– from left to right
7
Examples Using Familiar Operators
dblResult + dblResult = 3 + 4 7 - dblResult = 4 – 3 1 * dblResult = 3 * 4 12 *, + dblResult = 3 * 4 + 5 17 *, +, ( ) dblResult = 3 * (4 + 5) 27 ^, * dblResult = 2^3 * 6 48
8
Relational Operators Used to create a Boolean expression
One that evaluates to True or False Note: the default (initial) value of a Boolean Expression is false Visual Basic Relational Operators > greater than < less than >= greater than or equal to <= less than or equal to = equal to <> not equal to
9
Truth Tables Truth tables show the possible outcomes of combining any two boolean expressions using the AND operator OR, or the NOT operator. Here’s an example using AND
10
Writing Boolean Expressions
Below is a DeskCheck (table of possible outputs): Relational Operator Boolean Expression Result >, intNum = 4 intNum > 6 False >, intNum = 8 True <, intNum = 7 intNum < 10 >=, intNum = 6 intNum >= 6 <=, intNum = 6 intNum <= 6 <>, intNum = 6 intNum <> 6
11
Wrap Up In this short PowerPoint we looked at some of the different operators can be used in Visual Basic. For more information on arithmetic operators For more information on relational operators And
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.