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

Slides:



Advertisements
Similar presentations
Arithmetic in Pascal (2) Arithmetic Functions Perform arithmetic calculations Gives an argument to the function and it returns the result.
Advertisements

5.04 Apply Decision Making Structures
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
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
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.
Lecture 8 Visual Basic (2).
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.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
Numerical Functions & Tricks In today’s lesson we will look at: why we might want to use mathematical techniques some useful functions other mathematical.
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.
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.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
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.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in Math Class Functions.
Copyright © 2014 Pearson Education, Inc. Chapter 6 Procedures and 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
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
Objective 7.03 Apply Built-in Math Class Functions
Royal University of Phnom Penh
UNIT 4 Lesson 13 If statements.
Apply Procedures to Develop Message, Input, and Dialog Boxes
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
للمزيد زورونا على موقعنا الإلكتروني:
Boolean Expressions and If statements
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
Numbers.
Sub Procedures and Functions
Objective 7.03 Apply Built-in Math Class Functions
Presentation transcript:

COMPUTER PROGRAMMING I Objective 7.03 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

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  us/library/32s6akha(v=VS.90).aspx us/library/32s6akha(v=VS.90).aspx 