1 e0001 computers in engineering built in functions
TRANSCRIPT
![Page 1: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/1.jpg)
1
E0001 Computers in E0001 Computers in EngineeringEngineering
Built in Functions
![Page 2: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/2.jpg)
2
General NotesGeneral Notes
Check when the first assignment is due! Have you thought about it? Although not due it should be completed by
now!!!! Assignments may be “posted”on the 4th
floor Z block
![Page 3: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/3.jpg)
3
What is the outcome?What is the outcome?
READ studnumber, names$
DATA 12345, “smith”
total$ = “6”
PRINT total$ + 4
![Page 4: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/4.jpg)
4
Readings and ExercisesReadings and Exercises
Schneider Section 3.4 p 72-78 Schneider Practice Problems 3.4 p 78;
programming problems #’s 57, 60, 62, 66, 68
![Page 5: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/5.jpg)
5
Rem statementsRem statements
Rem short for REMARK used for adding comments to code useful for the programmer, not the user non executable line Two ways of adding comments
– REM– ‘
![Page 6: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/6.jpg)
6
ExamplesExamples
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
![Page 7: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/7.jpg)
7
Numeric FunctionsNumeric Functions
covers common numeric and trigonometric terms– square root - SQR(x)– SIN(angle), COS(angle), TAN(angle)
BEWARE - (angle) must be in RADIANS
– LOG (x) see handout for more examples
![Page 8: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/8.jpg)
8
Examples of Numeric Examples of Numeric FunctionsFunctions
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
ABS - absolute value– ABS(-3) = 3; ABS(7) = 7– ABS(SQR(CINT(x)))
![Page 9: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/9.jpg)
9
String FunctionsString Functions
allows examining strings or parts; combining strings
allows string comparisons using <, >, = (relational operators)
![Page 10: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/10.jpg)
10
Examples of String FunctionsExamples of String Functions
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”
![Page 11: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/11.jpg)
11
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
see also MID$(x$,n,m) and RIGHT$(x$,n) LCASE$(X$); UCASE$(X$);
INSTR(n,X$,Y$) 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.
![Page 12: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/12.jpg)
12
Built-in FunctionsBuilt-in Functions
prewritten “subroutine” that does one operation
returns ONE value only designed to manipulate both numerical and
string data cover common calculations
![Page 13: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/13.jpg)
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
ProblemProblem
L/ g(11
4sin (
2))2
![Page 14: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/14.jpg)
14
TutorialTutorial
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
![Page 15: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/15.jpg)
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
![Page 16: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/16.jpg)
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)
![Page 17: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/17.jpg)
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
![Page 18: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/18.jpg)
18
The EndThe End
![Page 19: 1 E0001 Computers in Engineering Built in Functions](https://reader036.vdocuments.us/reader036/viewer/2022083008/56649f065503460f94c1b44e/html5/thumbnails/19.jpg)
19
Now change the program to Now change the program to include INPUT statementsinclude 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