COMPUTER PROGRAMMING I SUMMER 2011 6.01 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.
Apply Sub Procedures/Methods and User Defined Functions
Transparency 2 Click the mouse button or press the Space Bar to display the answers.
CS0004: Introduction to Programming Variables – Numbers.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
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-
When dividing a decimal by a whole number, place the decimal point in the quotient directly above the decimal point in the dividend. Then divide as you.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
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.
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.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
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.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Operators.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in Math Class Functions.
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:
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
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.
Question of the Day Solve for b: 2b + 7 = 15. Expressions and Equations Collecting Like Terms and Distributive Property.
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.04 Apply Built-in String Functions (3%)
Objective 7.03 Apply Built-in Math Class Functions
Exponents and Order of Operations
Simplifying Expressions; Order of Operations
Use TryParse to Validate User Input
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Please Excuse My Dear Aunt Sally
43 Order of Operations  ( ) + - X.
Please Excuse My Dear Aunt Sally
Objective The student will be able to:
43 Order of Operations  ( ) + - X.
Evaluating Expressions
43 Order of Operations  ( ) + - X.
Objective The student will be able to:
Objective The student will be able to:
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
PEMDAS MATH MADE EASY.
Order of Operations.
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.
Objective The student will be able to:
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.
Objective The student will be able to:
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
Objective The student will be able to:
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
43 Order of Operations  ( ) + - X.
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: Apply Conditional Logic Indicator: 6.01 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/Comparison 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) 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

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

Reading in Numbers Remember that a TextBox returns a String. Visual Studio will automatically “convert” this for you; however, it is good programming style to explicitly convert the string to a number. Use the Convert Method that is part of the System class. You should use the Convert methods when you are bringing in numeric input to use for “math” from now on.

Converting Strings to Numbers MethodPurposeExample ToInt16(String)Converts the specified string representation of a number to an equivalent 16-bit signed integer. intNum = Convert.ToInt16(strInput) ToDouble(StringConverts the specified string representation of a number to an equivalent double- precision floating-point number. dblNum = Convert.ToDouble(strInput) There are other Convert methods as well. us/library/system.convert_methods.aspx

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 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 \ 5 = 3 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 Dim intx As Integer = Convert.ToInt16(txtdividend.Text) Dim intd As Integer = Convert.ToInt16(txtdivisor.Text) Dim inta, intb, intc As Integer inta = intx / intd intb = intx \ intd intc = intx Mod intd Lbloutput.Text = intx.ToString & "/" & intd.ToString & " is " & inta.ToString & vbCrLf & intx.ToString & "\" & intd.ToString & " is " & intb.ToString & vbCrLf & "And" & vbCrLf & intx.ToString & " Mod " & intd.ToString & " Is " & intc.ToString

Division Operators Example: Dim x As Integer = 18 ‘sets x = 18 Dim a, b, c As Integer ‘sets variable a, b and c_ ‘as an integer Notice that: a = x / 4 ‘a is 4.5 so a is assigned 5 because of rounding b = x \ 4 ‘b is assigned 4 c = x mod 4 ‘c is assigned 2

Relational Operators Used to create a Boolean expression  One that evaluates to True or False  You have seen these also. Remember > greater than < less than >= greater than or equal to <= less than or equal to = equal <> do not equal

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 decNum1, decNum2, decResult As Decimal decNum1 = txtNum1.Text decNum2 = txtNum2.Text decResult = decNum1 + decNum2 lblResult.Text = decResult.ToString() End Sub

Wrap Up In this short PowerPoint we looked at some of the different operators can be used in Visual Basic Please continue to 6.02 which introduces decision making statements.