Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objective 7.03 Apply Built-in Math Class Functions

Similar presentations


Presentation on theme: "Objective 7.03 Apply Built-in Math Class Functions"— Presentation transcript:

1 Objective 7.03 Apply Built-in Math Class Functions
Computer Programming I Image taken from:

2 Objects/Classes and Methods in Visual Basic
An object is a structure containing data and methods that manipulate the data. Almost everything you do in Visual Basic is associated with objects. If you are new to object-oriented programming, the following terms and concepts will help you get started. Classes and Objects The words "class" and "object" are used so much in object-oriented programming that it is easy to get the terms mixed up. Generally speaking, a class is an abstract representation of something, whereas an object is a usable example of the thing the class represents.

3 Objects/Classes and Methods in Visual Basic
Methods – Functions Methods are operations that can be performed on data. A method may take some input values through its parameters and may return a value of a particular data type. There are two types of methods in VB: Sub Procedures and Functions. For this Unit, we will discuss two built in classes with built in Functions: The Math and String classes.

4 Math Class Functions The Math class provides programmers with numerous built-in 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. Image taken from:

5 Using Abs(num) The Abs() function returns the absolute value of the number and works with the following data types: Decimal, Double, Integer, Single Abs() Function intNum Value after execution intNum = Math.Abs(4) 4 sngNum = Math.Abs(-4.123) 4.123 intNum = Math.Abs(0) Image taken from:

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

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

8 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() Function dblNum 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.

9 More info? This PowerPoint provided an overview of several methods in the Math class in Visual Studio. For more information on this topic


Download ppt "Objective 7.03 Apply Built-in Math Class Functions"

Similar presentations


Ads by Google