COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in Math Class Functions.

Slides:



Advertisements
Similar presentations
Java Math Class. What is the Math Class? The Math Class is another class that is prepared by Java for us to use We use this class for mathematical operations.
Advertisements

Arithmetic in Pascal (2) Arithmetic Functions Perform arithmetic calculations Gives an argument to the function and it returns the result.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
TK1913-C Programming1 TK1913-C Programming 1 C Library Functions C provides a collection of library functions for programmers If these library functions.
Computers and Scientific Thinking David Reed, Creighton University Functions and Randomness 1.
COMPUTER PROGRAMMING II SUMMER 2011 Visual Basic to C#
Apply Sub Procedures/Methods and User Defined Functions
XP Copyright 2003 Peter McDevitt 1 Microsoft Excel 2002 Lecture 2 – Working With Formulas and Functions.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
CS0004: Introduction to Programming Variables – Numbers.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
Variable Declaration  It is possible to declare multiple variables of the same data type on the same line.  Ex. double hours, rate, total;  Variables.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
CSC 162 Visual Basic I Programming. Randomizing and Formatting Randomizing Formatting –User-Defined Formats –Named Numeric Formats.
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
CSC Programming I Lecture 5 August 30, 2002.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
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.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions Image taken from:
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
Introduction to Programming with RAPTOR
Unit 1: Integers.  There are two types of problems:  1- When the signs are the same  = 5  = -5  2- When the signs are different  3.
Math Class Part of the Java.lang package. This package is from object so you do not have to import the lang package. Static: Math Class is static.
M ODULE 2 Multiplying and Dividing Integers. M ODULE 2 Multiplying and Dividing Integers Intro Video (Click Here)Click Here.
Numerical Functions & Tricks In today’s lesson we will look at: why we might want to use mathematical techniques some useful functions other mathematical.
Introduction to Access 2010 CIS120first.accdb is the database I am creating.
Applications Development
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Lesson 6 Selection Structures. Example program //This will convert a numeric grade into a letter grade import TerminalIO.KeyboardReader; public class.
Visual Basic I Programming
The Math Class Methods Utilizing the Important Math Operations of Java!
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Chapter 8.  Visual Basic includes several built-in mathematical functions ◦ Abs ◦ Sqr ◦ Sgn ◦ IsNumeric ◦ Round ◦ Format ◦ Pmt ◦ PV ◦ FV.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Math Class Mrs. C. Furman September 2, Math frequently used methods NameUse floor()rounds down ceil()rounds up pow(x,y)returns x to the power of.
Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
Computer Science 112 Fundamentals of Programming II.
Controlling Program Flow with Decision Structures.
5.02B Decision Making Structure (part 2). Compound Boolean Expressions.
Transparency 2 Click the mouse button or press the Space Bar to display the answers.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Loops Review. How to generate random numbers Math.random() will return a random decimal value in the form of a double. double num1 = Math.random(); num1.
Use TryParse to Validate User Input
5.03 Apply operators and Boolean expressions
5.04 Apply Decision Making Structures
Objective 7.04 Apply Built-in String Functions (3%)
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Objective 7.03 Apply Built-in Math Class Functions
Apply Procedures to Develop Message, Input, and Dialog Boxes
Value-Returning Functions
Lesson 18 Math Functions Lesson 19 Format Functions
Use TryParse to Validate User Input
Apply Procedures to Develop Menus, List Box and Combo Box Objects
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
Numerical Functions & Tricks
Numbers.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Input, Variables, and Mathematical Expressions
5.03 Apply operators and Boolean expressions
Objective 7.03 Apply Built-in Math Class Functions
Presentation transcript:

COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in Math Class Functions

Objective/Essential Standard Essential Standard 7.00 Apply Advanced Logic Indicator 7.03 Apply Built-in Math Class Functions (3%)

Math Class Functions Visual Studio provides the programmer with multiple built-in functions from the Math class, including the following: Math Class Functions  Absolute Value (Abs)  Square Root (Sqrt)  Sign (Sign)  Rounding (Round) The Math class is not limited to just these four functions.

Math Class Functions The Math class provides programmers with numerous functions. We will only look at a few of these functions. Abs(num)  Returns the absolute value of a positive or negative number Sqrt(num)  Returns the square root of a number Sign(num)  Returns the sign of a number Round (num, places)  Returns number nearest to the specified value.

Using Abs(num) The Abs() function works with the following data types:  Decimal, Double, Int16, Int32, Int64, SByte, Single Abs() FunctionintNum Value after execution intNum = Math.Abs(4)4 sngNum = Math.Abs(-4.123)4.123 intNum = Math.Abs(0)0

Using Sqrt(num) Returns the square root of a number as a double Sqrt() FunctiondblNum Value after execution dblNum = Math.Sqrt(4)2.0 dblNum = Math.Sqrt(0)0.0 dblNum = Math.Sqrt(-4)NaN (NaN represents a value that is not a number)

Using Sign(num) The Sign() function works with the following data types:  Decimal, Double, Int16, Int32, Int64, SByte, Single Sign() FunctionintNum Value after execution intNum = Math.Sign(4)1 intNum = Math.Sign(-4) intNum = Math.Sign(0)0

Round Function The Round() function works with either a decimal or a double. The variable/value that represents the number of places should be an Integer. Round() FunctiondblNum Value after execution dblNum = Math.Round( , 2)5.24 decNum = Math.Round( )5.0 dblNum = Math.Round(5.5)6.0 decNum = Math.Round(5.225, 2)5.23 Note that.5 does round up here.

Try It! Create a new application called mathExample  Save it into the location as instructed by your teacher. Add the following controls. When the button is clicked, the appropriate answer should be displayed in the lblAnswer label.  When the btnRound is clicked, it should display an input box to ask for the number of decimal places. ControlNameText/Items LabellblPromptEnter a Number: LabellblAnswer ButtonbtnAbsAbsolute Value ButtonbtnSqrtSquare Root ButtonbtnSignSign ButtonbtnRoundRound It

Conclusion This PowerPoint provided an overview of several methods in the Math class and the formatting method in the String class in Visual Studio. For more information on this topic  us/library/32s6akha(v=VS.90).aspx us/library/32s6akha(v=VS.90).aspx 