COMPUTER PROGRAMMING I SUMMER 2011 5.03 Apply operators and Boolean expressions.

Slides:



Advertisements
Similar presentations
5.04 Apply Decision Making Structures
Advertisements

Factors and Prime Numbers When two or more numbers are multiplied to give a certain product, each number is called a factor of the product. The numbers.
Math is a language, learn the words!
Multiply and Divide Decimals
Apply Sub Procedures/Methods and User Defined Functions
CS0004: Introduction to Programming Variables – Numbers.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Order of Operations & Evaluating Expressions. Review: Order of Operations Please- Parentheses Excuse- Exponents My- Multiplication Dear- Division Aunt-
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
CPS120: Introduction to Computer Science Operations Lecture 9.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Algebra 1c 1-1 Symbols and Expressions Terms to Know: Variable: A symbol that represents a number. Algebraic Expression: Is a collection of numbers, operators,
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Order of Operations ( ) + X . The Order of Operations tells us how to do a math problem with more than one operation, in the correct order.
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
Operators.
A number sentence is a short way of writing a mathematical expression. EXAMPLE I could write: eight plus six equals fourteen or I could write it this way:
Evaluate Is your answer 33 or 19? You can get 2 different answers depending on which operation you did first. We want everyone to get the same.
Computer Science Up Down Controls, Decisions and Random Numbers.
Order of Operations C. N. Colón Algebra I St. Barnabas HS Bronx, NY.
Use TryParse to Validate User Input
Do Now: Evaluate
5.03 Apply operators and Boolean expressions
5.04 Apply Decision Making Structures
Objective 7.03 Apply Built-in Math Class Functions
Exponents and Order of Operations
Order of Operations.
Use TryParse to Validate User Input
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Order of Operations ÷ + - X.
Arithmetic, Exponents, Equations and Inequalities
Please Excuse My Dear Aunt Sally
A standard way to simplify mathematical expressions and equations.
43 Order of Operations  ( ) + - X.
Please Excuse My Dear Aunt Sally
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Evaluating Expressions
43 Order of Operations  ( ) + - X.
Objective The student will be able to:
Math unit 1 review.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
PEMDAS MATH MADE EASY.
Order of Operations.
Order of Operations STES.
Differences between Java and JavaScript
Order of Operations 1-2 Objective: Students will evaluate numerical expressions and algebraic expressions using the order of operations. S. Calahan 2008.
43 Order of Operations  ( ) + - X.
Order of Operations PEMDAS.
Objective The student will be able to:
Objective The student will be able to: use the order of operations to evaluate expressions.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
I can USE THE ORDER OF OPERATIONS USE GROUPING SYMBOLS.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Symbols and Expressions
5.03 Apply operators and Boolean expressions
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Presentation transcript:

COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions

Objective/Essential Standard Essential Standard: 5.00 Apply Programming & Conditional Logic Indicator: 5.03 Apply operators and Boolean expressions. (3%)

Operators What are operators?  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/Comparison Operators.  We will use all of these in programming. For now let’s look at the math operators.

Basic Math Operators These you are familiar with: + (add), - (subtract) / (divide) * (multiply) ^ (Exponents) New Math operators include: \ integer divide - returns the whole of the division. Mod (Modulus division) - returns the remainder of the division.

Samples of Math with various Operators Addition +  intNumber = num1 + num2 Subtraction –  intNumber = num Multiplication *  intNumber = num1 * num2 Division /  intNumber = 51 / num2 Integer Division \  intNumber = 51 \ num2 Modulus Mod  intNumber = 5 mod 2 Exponents ^  intNumber = 5^3‘5 cubed Remember with division- dividing by zero returns a fatal error. When dividing it is a good idea to use error checking to prevent this error which will terminate your program.

Operators of Operations Just as in math, Please Excuse My Dear Aunt Sally describes the precedence applied to math in programming  Parentheses  Exponents  Multiply  Divide (NOTE: Division will be complete in the order in which it appears in the problem, no ranking with division types.)  Add  Subtract

Examples Using Familiar Operators OperatorExampledblResult +dblResult = dblResult = 4 – 31 *dblResult = 3 * 412 *, +dblResult = 3 * *, +, ()dblResult = 3 * (4 + 5)27 ^, *dblResult = 2^3 * 648

Division Operators Regular division  Rounds the decimal portion if assigned to an integer.  This is the division with which you are most familiar. Integer division  cuts off the decimal portion and returns the integer ( \ ) Modulus division  returns the remainder resulting form the division (mod)

Integer division 19 \ 5 = 3 You may be a little confused by these new types of divisions but it is really simple. Anytime you divide a number into another number the answer returned is the whole part of the quotient.

Modular division 19 Mod 5 = 4 Modular Division is about finding the remainder Anytime you divide a number into another number the answer returned is the remainder part of the quotient. Divisor 5 19 Dividend 3 R 4 Quotient 15 4 Remainder

Sample Program Write a program that will accept 2 numbers and perform regular division, integer division and mod division based on the button clicked.

Sample Code ‘Declare & Input Dim intNumer As Integer = Convert.ToInt32(txtnumerator.Text) Dim intDenom As Integer = Convert.ToInt32(txtdenominator.Text) Dim intAnsDiv, intAnsIntDiv, intAnsMod As Integer ‘Calculate intAnsDiv = intNumer / intDenom intAnsIntDiv = intNumer \ intDenom intAnsMod = intNumer Mod intDenom ‘Output lbloutput.Text = intNumer.ToString & "/" & intDenom.ToString & " is " & intAnsDiv.ToString & vbCrLf & intNumer.ToString & "\" & intDenom.ToString & " is " & intAnsIntDiv.ToString & vbCrLf & "And" & vbCrLf & intNumer.ToString & " Mod " & intDenom.ToString & " Is " & intAnsMod.ToString

Division Operators Dim intNumer As Integer = 18 ‘sets intNumer = 18 Dim intAnRegDiv As Integer = 0 Dim intAnsIntDiv As Integer = 0 Dim intAnsModDiv As Integer = 0 intAnRegDiv = intNumer / 4‘intAnRegDiv = 4.5 ‘so intAnRegDiv is ‘assigned 5 due to ‘rounding intAnsIntDiv = intNumer \ 4‘intAnsIntDiv = 4 intAnsModDiv = intNumer mod 4 ‘intAnsModDiv = 2

Relational Operators Used to create a Boolean expression  One that evaluates to True or False Visual Basic Relational Operators > greater than < less than >= greater than or equal to <= less than or equal to = equal <> do not equal

Boolean as a Data Type This type can be either True or False  May represent On or Off  May represent Yes or No

Boolean Expression The condition of an If… Then statement is a Boolean Expression. The expression evaluates to True or False Relational Operators can be used to form Boolean Expressions

Writing Boolean Expressions Relational OperatorBoolean ExpressionResult >, intNum = 4intNum > 6False >, intNum = 8intNum > 6True <, intNum = 7intNum < 10True >=, intNum = 6intNum >= 6True <=, intNum = 6intNum <= 6True <>, intNum = 6intNum <> 6False Below is an DeskCheck (table of possible outputs):

Sample Program Write a program that will accept 2 numbers and perform addition, subtraction, multiplication, division, or mod division based on the button clicked.

Sample Code Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim dblNum1, dblNum2, dblResult As Double dblNum1 = Convert.ToDouble(txtNum1.Text) dblNum2 = Convert.ToDouble(txtNum2.Text) dblResult = dblNum1 + dblNum2 lblResult.Text = dblResult.ToString End Sub

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 us/library/b6ex274z(v=VS.80).aspx us/library/b6ex274z(v=VS.80).aspx For more information on relational operators us/library/yf3abyat.aspx us/library/yf3abyat.aspx