5.03 Apply operators and Boolean expressions Computer Programming I
Objective/Essential Standard Essential Standard: 5.00 Apply Programming & Conditional Logic Indicator: 5.03 Apply operators and Boolean expressions. (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.
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.
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)
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
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
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
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
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
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 http://msdn.microsoft.com/en-us/library/b6ex274z(v=VS.80).aspx For more information on relational operators https://msdn.microsoft.com/en-us/library/dya2szfk.aspx And https://msdn.microsoft.com/en-us/library/wz3k228a.aspx