IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math.

Slides:



Advertisements
Similar presentations
Maths & Trig, Statistical functions. ABS Returns the absolute value of a number The absolute value of a number is the number without its sign Syntax ◦
Advertisements

Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
7.1Variable Notation.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
Types and Arithmetic Operators
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
JavaScript, Third Edition
INTRODUCTION TO PYTHON PART 1 CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Section 1.1 Numbers and Their Properties.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 3.  Traditionally, programming languages have assigned different types of data for different types of numbers.  In many languages, there may.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Copyright 2013, 2009, 2005, 2002 Pearson, Education, Inc.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
Input, Output, and Processing
Chapter 2: Using Data.
Week 2 - Friday.  What did we talk about last time?  Using Scanner to get input  Basic math operations.
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
CPS120: Introduction to Computer Science Operations Lecture 9.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Arithmetic Expressions Russell Taylor NC Computing Software Application Development.
1 Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter 1-1 Basic Concepts Chapter 1.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
Significant Figure Rules RulesExamples The following are always significant Non zero digits Zeros between non zero digits Zero to the right of a non zero.
IMS 4480: Introduction to Web Services 1 Dr. Lawrence West, MIS Dept., University of Central Florida Introduction to Web Services—Topics.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Recap……Last Time [Variables, Data Types and Constants]
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Doing math In java.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
29 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
Making Interactive Programs with Visual Basic .NET
Introductory Algebra Glossary The Language of Math.
Chapter 3 Math Operations. Objectives Use the assignment and arithmetic operators. Use operators in output statements. Explain the problem with division.
Variables, Operators, and Expressions
Topics Designing a Program Input, Processing, and Output
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Thinking Mathematically
BASIC ELEMENTS OF A COMPUTER PROGRAM
BIL 104E Introduction to Scientific and Engineering Computing
Assignment and Arithmetic expressions
Chapter 7 Objectives Define basic terms in algebra: integer, number statement, expression, and coefficient Learn the relationships between positive and.
Fundamental of Java Programming Basics of Java Programming
Introduction to Programming
Numbers.
Arithmetic Expressions & Data Conversions
CSI 101 Elements of Computing Spring 2009
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
VB Variables and Data
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
EECE.2160 ECE Application Programming
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
EECE.2160 ECE Application Programming
Arithmetic Expressions & Data Conversions
Presentation transcript:

IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math Operations –Using Parentheses to override precedence Writing and Interpreting VB Calculation Statements Mathematical Functions “A computer lets you make more mistakes faster than any invention in human history—with the possible exceptions of handguns and tequila” Mitch Ratcliffe

IMS 3253: Math 2 Dr. Lawrence West, MIS Dept., University of Central Florida Numeric Operations in Computer Code Computers were invented to process large quantities of numeric data Computers perform arithmetic operations on numeric values incredibly rapidly All computer operations can be performed using the basic operations of addition, subtraction, multiplication, and division. Most computer languages also provide for exponentiation Most also provide built in functions for more complex operations

IMS 3253: Math 3 Dr. Lawrence West, MIS Dept., University of Central Florida Objectives Understand the five fundamental arithmetic operations in VB Understand how to write and interpret mathematical calculations in VB Understand the precedence of mathematical operations in computers and how parenthetical grouping affects calculation order Understand the use of predefined mathematical functions available in VB

IMS 3253: Math 4 Dr. Lawrence West, MIS Dept., University of Central Florida Five Fundamental Arithmetic Operations VB supports five built-in arithmetic operations: OperationConventional NotationComputer Symbol –Addition –Subtraction –Multiplication3 x 43 * 4 –Division3  3 / 4 –Exponentiation ^ 4

IMS 3253: Math 5 Dr. Lawrence West, MIS Dept., University of Central Florida The Assignment Operation Many times the results of a calculation or other operation are assigned to a variable, property, or other value holder intSum = intFirstValue + intSecondValue intSum = Val(txtFirst.Text) + Val(txtSecond.Text) MainMenu.Top = (Screen.Height - MainMenu.Height) / 3 The calculation on the right of the equal sign is performed first and assigned to the location on the left The Equal Sign is an assignment operator

IMS 3253: Math 6 Dr. Lawrence West, MIS Dept., University of Central Florida Using Numeric Calculations Legal statements x = 4 y = 2 z = x + 5 t = x * 2 txtPrice.Text = x + y Const Pi = 3.14 dblDiameter = Pi * sglRadius dSqrt = x ^.5 Illegal statements 4 x + y z% = x% + txtInput.Text sglPrice = $1,456.98

IMS 3253: Math 7 Dr. Lawrence West, MIS Dept., University of Central Florida Precedence of Numeric Calculations Q: What is the result of * 2 ? A: Numeric operations have a defined hierarchy or precedence of calculation 1.Exponentiation 2.Multiplication and division 3.Addition and subtraction 4.Left to right within categories –Because multiplication precedes addition 5 is multiplied by two giving 10 first after which the three is added to give 13

IMS 3253: Math 8 Dr. Lawrence West, MIS Dept., University of Central Florida Precedence Exercises x + y / 2 y ^ 3 / 4 x + 2 * y - 2 * x 8 + x * y / y ^ ^ (1 / 4) What are the results of the following calculations if x = 12 and y = 4 ?

IMS 3253: Math 9 Dr. Lawrence West, MIS Dept., University of Central Florida Using Parentheses to Group Calculations Operations grouped in parentheses are performed first, regardless of the natural order of calculation * 2 = 13 (3 + 5) * 2 = 16 Parentheses may be nested ((3 + 5) * 8) / (2 * 4) = ? Parentheses may be used to visually format mathematical expressions even if no change to the calculation order is needed Inner parentheses are evaluated first

IMS 3253: Math 10 Dr. Lawrence West, MIS Dept., University of Central Florida More Precedence Exercises Write computer expressions for each mathematical expression

IMS 3253: Math 11 Dr. Lawrence West, MIS Dept., University of Central Florida Numeric Functions VB (and most other programming languages) provide predefined numeric calculations in the form of functions Functions often operate on a value and return some transformation of the value E.g. in x = 25 y = Sqrt(x) Sqr( ) is a predefined function which returns the square root of its argument (x in this case)

IMS 3253: Math 12 Dr. Lawrence West, MIS Dept., University of Central Florida Functions and Expressions as Arguments Functions may be nested E.g., in Math.Sqr(Math.Abs(x)) the absolute value of x is determined first and then becomes the argument of the square root function A calculation may be performed inside the argument of a function E.g., in Math.Sqr(x ^ 2) the value of x is first squared and then the square root of the result is taken Functions are always calculated from the inside out

IMS 3253: Math 13 Dr. Lawrence West, MIS Dept., University of Central Florida Empty Variables in Mathematical Operations Variables which have never been assigned a value are said to be ‘empty’ If a mathematical operation is performed on an empty variable the variable behaves as if its value is zero Be very careful as division by zero results in a runtime error which will crash the program. NB: Variables loaded from databases may sometimes contain a null value which is different from empty.

IMS 3253: Math 14 Dr. Lawrence West, MIS Dept., University of Central Florida Converting Data Types VB will automatically convert many numeric data types before performing calculations –Single precision values can be multiplied by integers, assigned to currency variables etc. Some conversions cannot take place –String values cannot be assigned to explicitly declared numeric variables (non variants) –Commonly arises when using text boxes, list boxes, grid controls, etc. Introduces inefficiency

IMS 3253: Math 15 Dr. Lawrence West, MIS Dept., University of Central Florida The Val( ) Function Val( ) returns the numeric value of its argument –Argument is typically a string but may be a number –Val converts strings to numbers A common use of Val is to convert values which must be treated as text into numbers intQty = Val(txtQty.Text) intCourse = Val(cboCourseNumber.Text) sglPrice = Val(InputForm.Tag) Or use the Convert method Some properties always contain characters

IMS 3253: Math 16 Dr. Lawrence West, MIS Dept., University of Central Florida The Val ( ) Function: Examples Val (“123.54”) Val (““) 0 Val(“123A45”) 123 Val(“A123”) 0 Val(“ ”)

IMS 3253: Math 17 Dr. Lawrence West, MIS Dept., University of Central Florida Methods of the Math Class NameDescription AbsOverloaded. Returns the absolute value of a specified number. AcosReturns the angle whose cosine is the specified number. AsinReturns the angle whose sine is the specified number. AtanReturns the angle whose tangent is the specified number. Atan2 Returns the angle whose tangent is the quotient of two specified numbers. BigMulProduces the full product of two 32-bit numbers. Ceiling Overloaded. Returns the smallest integer greater than or equal to the specified number. CosReturns the cosine of the specified angle. CoshReturns the hyperbolic cosine of the specified angle. DivRem Overloaded. Calculates the quotient of two numbers and also returns the remainder in an output parameter. ExpReturns e raised to the specified power. Floor Overloaded. Returns the largest integer less than or equal to the specified number.

IMS 3253: Math 18 Dr. Lawrence West, MIS Dept., University of Central Florida Methods of the Math Class (cont.) IEEERemainder Returns the remainder resulting from the division of a specified number by another specified number. LogOverloaded. Returns the logarithm of a specified number. Log10Returns the base 10 logarithm of a specified number. MaxOverloaded. Returns the larger of two specified numbers. MinOverloaded. Returns the smaller of two numbers. PowReturns a specified number raised to the specified power. Round Overloaded. Rounds a value to the nearest integer or specified number of decimal places. SignOverloaded. Returns a value indicating the sign of a number. SinReturns the sine of the specified angle. SinhReturns the hyperbolic sine of the specified angle. SqrtReturns the square root of a specified number. TanReturns the tangent of the specified angle. TanhReturns the hyperbolic tangent of the specified angle. TruncateOverloaded. Calculates the integral part of a number.