Objective 7.03 Apply Built-in Math Class Functions

Slides:



Advertisements
Similar presentations
5.04 Apply Decision Making Structures
Advertisements

Control structures Part 2 iteration control To enable repetition of a statement block.
Additional loop presentation
5.05 Apply Looping Structures
COMPUTER PROGRAMMING II SUMMER 2011 Visual Basic to C#
Apply Sub Procedures/Methods and User Defined Functions
CS0004: Introduction to Programming Variables – Numbers.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
Chapter 3 – Fundamentals of Programming in VB.NET VB.NET Controls VB.NET Events Numbers Strings Input and Output.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
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:
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
Applications Development
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 8 What’s Wrong with It?
Lesson 6 Selection Structures. Example program //This will convert a numeric grade into a letter grade import TerminalIO.KeyboardReader; public class.
1 Week 5 More on the Selection Structure. 2 Nested, If/ElseIf/Else, and Case Selection Structures Lesson A Objectives After completing this lesson, you.
1 Advanced Computer Programming Lab Calculator Project.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
PRACTICE SAC 1 Some solutions. 'inputs 'sale price 'postcode 'coupon codes 'processing 'calculate commissions (commission based on cost) 'calculate postage.
Chapter 8.  Visual Basic includes several built-in mathematical functions ◦ Abs ◦ Sqr ◦ Sgn ◦ IsNumeric ◦ Round ◦ Format ◦ Pmt ◦ PV ◦ FV.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
Controlling Program Flow with Decision Structures.
Introduction to VB programming Dr. John P. Abraham UTPA Chapters 2 & 3.
5.02B Decision Making Structure (part 2). Compound Boolean Expressions.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in Math Class Functions.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Computer Science Up Down Controls, Decisions and Random Numbers.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Use TryParse to Validate User Input
Visual Basic Fundamental Concepts
5.03 Apply operators and Boolean expressions
Chapter 11 – Exception Handling
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
Royal University of Phnom Penh
UNIT 4 Lesson 13 If statements.
Apply Procedures to Develop Message, Input, and Dialog Boxes
Lesson 18 Math Functions Lesson 19 Format Functions
Computer Programming I
Single Dimensional Arrays
Use TryParse to Validate User Input
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Introduction to VB programming
للمزيد زورونا على موقعنا الإلكتروني:
Visual Basic..
Boolean Expressions and If statements
Operations with Integers
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
Numbers.
Procedures and Functions
Sub Procedures and Functions
STARTING OUT WITH Visual Basic 2008
Operations with Integers
Objective 7.03 Apply Built-in Math Class Functions
Presentation transcript:

Objective 7.03 Apply Built-in Math Class Functions Computer Programming I

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() Function intNum Value after execution intNum = Math.Abs(4) 4 sngNum = Math.Abs(-4.123) 4.123 intNum = Math.Abs(0)

Using 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 (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() Function intNum Value after execution intNum = Math.Sign(4) 1 intNum = Math.Sign(-4) -1 intNum = Math.Sign(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() Function dblNum Value after execution dblNum = Math.Round(5.23651, 2) 5.24 decNum = Math.Round(5.23651) 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. Control Name Text/Items Label lblPrompt Enter a Number: lblAnswer Button btnAbs Absolute Value btnSqrt Square Root btnSign Sign btnRound Round It

Try It! Solution Private Sub btnAbs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbs.Click Dim dblNum As Double Dim input As String Try input = txtInput.Text dblNum = Convert.ToDouble(input) lblAnswer.Text = "The Absolute Value is " & Math.Abs(dblNum) Catch Ex As Exception MessageBox.Show(“Enter numeric values”) End Try End Sub

Try It! Solution Private Sub btnSqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSqrt.Click Dim dblNum As Double Dim input As String Try input = txtInput.Text dblNum = Convert.ToDouble(input) lblAnswer.Text = "The Square Root Value is " & Math.Sqrt(dblNum) Catch Ex As Exception MessageBox.Show(“Enter numeric values”) End Try End Sub

Try It! Solution Private Sub btnSign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSign.Click Dim dblNum As Double Dim input As String Try input = txtInput.Text dblNum = Convert.ToDouble(input) If (Math.Sign(dblNum) > 0) Then lblAnswer.Text = dblNum & " is a positive number" ElseIf (Math.Sign(dblNum) < 0) Then lblAnswer.Text = dblNum & " is a negative number." Else lblAnswer.Text = dblNum & " is a zero." End If Catch Ex As Exception MessageBox.Show(“Enter numeric values”) End Try End Sub

Try It! Solution Private Sub btnRound_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRound.Click Dim dblNum As Double Dim input As String Dim intPlaces As Integer Try input = txtInput.Text dblNum = Convert.ToDouble(input) intPlaces = Convert.ToInt16(InputBox("Enter the number of places", "Places to round")) lblAnswer.Text = "The Absolute Value is " & Math.Round(dblNum, places) Catch Ex As Exception MessageBox.Show(“Enter numeric values”) End Try End Sub

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 http://msdn.microsoft.com/en-us/library/32s6akha(v=VS.90).aspx http://msdn.microsoft.com/en-us/library/system.math.aspx