90 likes | 269 Views
Objective 7.03 Apply Built-in Math Class Functions. Computer Programming I. Image taken from: http://www.stsd.org/webpages/cyurconic/news.cfm?subpage=67815. Objects/Classes and Methods in Visual Basic . An object is a structure containing data and methods that manipulate the data.
E N D
Objective 7.03 Apply Built-in Math Class Functions Computer Programming I Image taken from: http://www.stsd.org/webpages/cyurconic/news.cfm?subpage=67815
Objects/Classes and Methods in Visual Basic An objectis 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.
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.
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: http://www.amazingclassroom.com/templates/blue_business/math_1.asp?cag=sample1
Using Abs(num) • The Abs() function returns the absolute value of the number and works with the following data types: • Decimal, Double, Integer, Single Image taken from: http://withlovero.com/2012/05/15/absolute-value-17-2/
Using Sqrt(num) • Sqrt(num) Returns the square root of a number as a double Image taken from: http://keep3.sjfc.edu/students/anb02630/e-port/vsg/virtual%20strudy%20guide%2021.html
Using Sign(num) • The Sign() function works with the following data types: • Decimal, Double, Int16, Int32, Int64, SByte, Single Image taken from: https://www.honors.umass.edu/event/last-day-adddrop
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. Note that 5 does round up here.
More info? • This PowerPoint provided an overview of several methods in the Math 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