Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

No Downloads

Total views

631

On SlideShare

0

From Embeds

0

Number of Embeds

1

Shares

0

Downloads

9

Comments

0

Likes

1

No embeds

No notes for slide

- 1. Microsoft® Small Basic<br />The Math Object<br />Estimated time to complete this lesson: 1 hour<br />
- 2. The Math Object<br />In this lesson, you will learn about:<br />Using different operations of the Math object.<br />Using different properties of the Math object.<br />
- 3. The Math Object<br />The Math object offers many mathematical functions that you can use in your programs.<br />It includes various operations and properties, such as:<br />Do complex mathematical calculations boggle your mind at times? Don’t worry! <br /><ul><li> Cos
- 4. GetRandomNumber
- 5. Sin
- 6. SquareRoot
- 7. Remainder
- 8. Pi
- 9. Abs
- 10. ArcSin
- 11. Floor
- 12. GetDegrees
- 13. Log
- 14. Min</li></li></ul><li>Operations of the Math Object<br />Let’s learn about some operations of the Math object by writing a simple program.<br />In this example, you use the Sin and the Cos operation of the Math object to get the sine and the cosine of the angle you entered. You can also use the ArcSin operation to get the angle in radians from the sine value. Next, you can use the GetDegrees operation to convert the angle from radians to degrees. <br />
- 15. The Pi Property<br />The value of pi is an important aspect of some mathematical calculations. You can use the Pi property of the Math object to retrieve the value of pi in your calculations.<br />Let’s use this property to calculate the area of the circle.<br />output<br />In this example, you use the Pi property of the Math object to retrieve the value of pi. Then you use this value in the formula to get the area of the circle. <br />
- 16. The Abs Operation<br />Abs is another useful operation provided by the Math object. Let’s check it out.<br />With the help of the Abs operation, you can get the absolute value of the given number. For example, if you subtract a large number from a smaller number, it will result in a negative numeral.<br />In this example, you subtract two numbers. If the first number is smaller than the second, Abs operation returns a positive number.<br />
- 17. The Floor Operation<br />While creating your Small Basic program, how can you get the integer value of a decimal number? <br />That’s what the Floor operation is created for. It gives an integer value which is less than or equal to the specified decimal number.<br />Let’s see how you can use this operation in a program to calculate a student’s average grade.<br />In this example, you enter the grades received by a student in six subjects. Then, you use the Floor operation to get the student’s average as an integer value.<br />
- 18. The Log Operation<br />While doing complex calculations, you often need the log value of a particular number.<br />The Math object in Small Basic offers the Log operation to get the logarithm (base 10) value of the specified number.<br />In this example, you use the Log operation to get the log of 22.3.<br />
- 19. The GetRandomNumber Operation<br />Now, let’s discuss the GetRandomNumber operation of the Math object. <br />You can use this operation to get a random number between 1 and the specified maximum number.<br />Let’s use this operation in a program.<br />In this program, you draw the ‘*’ shape on the graphics window in different sizes and at different locations. <br />You first set the height, width, and background color of the graphics window. Then you use the GetRandomNumber operation to set the font size. The font size will be between 1 and 30 because you have specified 30 as the parameter for the GetRandomNumber operation. <br />Next, you use this operation to set the x- and y-coordinates of the asterisks at random.<br />
- 20. The Min Operation<br />The Math object provides another operation called the Min operation. You can use this operation to compare two numbers and get the smaller number of the two.<br />Let’s apply this operation in a program.<br />In this example, you accept two numbers and use the Min operation to compare the two numbers and display the smaller number in the text window. You also ensure that if the entered numbers are equal, the text window displays the statement “These numbers are the same.”<br />
- 21. The SquareRoot Operation<br />Let’s check out the SquareRoot operation of the Math object. You can use this operation to get the square root of a specified number.<br />In this example, you enter a number and use the SquareRoot operation to get its square root.<br />
- 22. The Remainder Operation<br />Let’s look at the Remainder operation of the Math object. You can use this operation to get the remainder in a division problem.<br />In this program, you want to check whether a number is even or odd.<br />You use the If condition to check if the entered number is completely divisible by 2 (the remainder is 0). If so, the number is an even number; otherwise, it is an odd number. To check the remainder, you use the Remainder operation of the Math object.<br />
- 23. Let’s Summarize…<br />Congratulations! Now you know how to:<br />Use different properties of the Math object.<br />Use different operations of the Math object.<br />
- 24. It’s Time to Apply Your Learning…<br />Write a program to draw circles of different sizes in the graphics window. Set the size of the circle by using the area of the circle and randomize the x- and y- coordinates of the circle.<br />Using the GetRandomNumber operation, write a program to move and rotate a rectangle in a random manner.<br />

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment