Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 E0001 Computers in Engineering Built in Functions.

Similar presentations


Presentation on theme: "1 E0001 Computers in Engineering Built in Functions."— Presentation transcript:

1 1 E0001 Computers in Engineering Built in Functions

2 2 General Notes l Check when the first assignment is due! l Have you thought about it? l Although not due it should be completed by now!!!! l Assignments may be “posted”on the 4th floor Z block

3 3 What is the outcome? READ studnumber, names$ DATA 12345, “smith” total$ = “6” PRINT total$ + 4

4 4 Readings and Exercises l Schneider Section 3.4 p 72-78 l Schneider Practice Problems 3.4 p 78; programming problems #’s 57, 60, 62, 66, 68

5 5 Rem statements l Rem short for REMARK l used for adding comments to code l useful for the programmer, not the user l non executable line l Two ways of adding comments –REM –‘

6 6 Examples REM this line is a comment REM This program will calculate…. REM This program was written by…. INPUT r,b,h‘radius, base, height READ n$, no$‘name, number

7 7 Numeric Functions l covers common numeric and trigonometric terms –square root - SQR(x) –SIN(angle), COS(angle), TAN(angle) l BEWARE - (angle) must be in RADIANS –LOG (x) l see handout for more examples

8 8 Examples of Numeric Functions l SQR (x) - square root of x where x is –variable - given a value by the program or the user –arithmetic operation - (6-4)/360*12 l ABS - absolute value –ABS(-3) = 3; ABS(7) = 7 –ABS(SQR(CINT(x)))

9 9 String Functions l allows examining strings or parts; combining strings l allows string comparisons using, = (relational operators)

10 10 Examples of String Functions l LEN(s) - s is known as the argument –returns the length of the argument i.e. the number of characters contained in the argument –blanks are counted as characters –LEN(“John and Mary”) = 13 –Z$ = “John and Mary”: LEN(Z$) = 13 –IF LEN(Z$) = 20 THEN PRINT “HELLO”

11 11 l LEFT$(x$, n) - x$ is any string; n is an integer from 0 to LEN(x$) –x$ = “John and Mary” –PRINT LEFT$(x$,4) - gives the output John l see also MID$(x$,n,m) and RIGHT$(x$,n) l LCASE$(X$); UCASE$(X$); INSTR(n,X$,Y$) l VAL(X$) - converts a string whose contents represent a number to its numerical form. –ignores leading blanks –converts a string up to its first nonnumerical character into its numerical value.

12 12 Built-in Functions l prewritten “subroutine” that does one operation l returns ONE value only l designed to manipulate both numerical and string data l cover common calculations

13 13 The period P of a pendulum of length L and maximum displacement angle  is given by the formula P = write a program that requests as input the length and maximum angle of displacement, and displays the period of the pendulum Problem

14 14 Tutorial 1. What will be the contents of x after the following statement is executed? LET x = SQR((9 + 7) / ( 4 * 2) + 2) 2. Suppose num = 123.4567. What is the output? LET num = INT(100 * num +.5) / 100 PRINT num

15 15 3. What output is generated by the following statements (show the output EXACTLY as it would appear on the screen)? PRINT SQR (3^2 + 4^2) PRINT MID$ ("Milkshake", 5, 5) PRINT UCASE$ ("123jump") 5 shake 123JUMP try this for yourself

16 16 4. The following statements are valid. (T/F) LET H$ = "Hello" LET a$ = INSTR(H$, 3) 5. Given the data in the variable y$ shown below, which of the following statements will assign the value ALL to x$? LET y$ = "WHEN ALL ELSE FAILS, READ THE DIRECTIONS" (a) LET x$ = MID$(y$, 6, 3) (b) LET x$ = INSTR(6, y$, "ALL") (c) LET x$ = LEFT$(y$, 3) (d) LET x$ = MIDDLE$(y$, 6, 3) (e) LET x$ = RIGHT$(y$, 8)

17 17 6. What will be displayed when the following program is executed? LET a$ = "THE WHOLE" LET b$ = "PART" LET c$ = MID$(a$, SQR(4), LEN(b$)) PRINT c$ END

18 18 The End

19 19 Now change the program to include INPUT statements DIM radius AS integer DIM pi AS double DIM circ AS double radius = 3.2 pi = 22/7 circ = 2*pi*radius PRINT radius,pi,circ DIM radius AS integer, pi AS double, circ AS double pi = 22/7 INPUT radius circ = 2*pi*radius PRINT”radius = “;radius PRINT”pi = “;pi PRINT “circumference is“;circ


Download ppt "1 E0001 Computers in Engineering Built in Functions."

Similar presentations


Ads by Google