Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Basic I Programming

Similar presentations


Presentation on theme: "Visual Basic I Programming"— Presentation transcript:

1 Visual Basic I Programming
CSC 162 Visual Basic I Programming

2 Math and Number Functions
Rounding Functions Trigonometric Functions Exponential and Logarithmic Functions Sign-Number Functions Random Number Function

3 Math and Number Functions
Rounding Functions Round(x, y) Rounds x to y decimal places Examples: Round( , 2) produces Round( , 1) produces Round( , 0) produces 5 Int(x) Greatest integer function (rounds x down to the closest integer): Examples: Int(3.78) produces 3 Int(-3.78) produces Fix(x) Rounds x down to the closest integer towards zero Examples: Fix(3.78) produces 3 Fix(-3.78) produces

4 Int vs. Fix Int Int -1 1 -2 2 3 4 -3 -4 Fix Fix -1 1 -2 2 3 4 -3 -4

5 Math and Number Functions
Trigonometric Functions Sin(x) Sine of angle x (x measured in radians): sin(x) Example: Sin(0.52) produces Cos(x) Cosine of angle x (x measured in radians): cos(x) Example: Cos(0.7) produces Tan(x) Tangent of angle x (x measured in radians): tan(x) Example: Tan(0.854) produces Atn(x) Arctangent of x (result measured in radians): arctan(x) Example: Atn(1.148) produces

6 Math and Number Functions
Exponential and Logarithmic Functions Exp(x) Exponential function: ex Example: Exp(2.1) produces Sqr(x) Square root of x: Examples: Sqr(4) produces 2 Sqr(2) produces Log(x) Natural logarithm of x: ln(x) or loge(x) Examples: Log(24) produces Log(2.789) produces

7 Logarithm Bases and Names
log10(x) = log(x) loge(x) = ln(x) log2(x) = lg(x)

8 Math and Number Functions
Sign-Number Functions Abs(x) Absolute value of x: | x | Examples: Abs(4) produces 4 Abs(0) produces 0 Abs(-7.2) produces Sgn(x) Signum function (sign of x) Examples: Sgn(5.1) produces 1 Sgn(0) produces 0 Sgn(-3) produces

9 Math and Number Functions
Random Number Function Rnd() Generates a random number: 0 ≤ x < 1 Examples: X = Rnd() produces X = Rnd() produces X = Rnd() produces To generate a random number: a ≤ x ≤ b X = Int(Rnd() * (b – a + 1)) + a

10 Random Number Generators

11 Math and Number Functions
Obtaining π (pi) and e π (pi) Pi = 4 * Atn(1) e e = Exp(1) Converting between Degrees and Radians 180º ↔ πr Degrees to Radians Radians to Degrees

12 Programming Assignment 5
Lab Assignment Write a function DegToRad that converts an angle in degrees to radians. Use this function in a program that allows the user to input an angle (measured in degrees) in a textbox, and then computes the sine, cosine, tangent, cosecant, secant, and cotangent. Display these values in six textboxes with appropriate labels. Round all answers to four (4) decimal places Programming Assignment 5 Due Monday, November 10 / Tuesday, November 11 Page 241 #6.18 Page 241 #6.19


Download ppt "Visual Basic I Programming"

Similar presentations


Ads by Google