Presentation is loading. Please wait.

Presentation is loading. Please wait.

E0001 Computers in Engineering

Similar presentations


Presentation on theme: "E0001 Computers in Engineering"— Presentation transcript:

1 E0001 Computers in Engineering
Inputs to the Computer

2 What did we cover last week
Variables why we use them how we name them how we define them how they work arithmetic operations print statement and zones

3 A Review from Last Week - Determine variables and outputs
x = 2 y = 3 * x x = y + 5 PRINT x + 4 y = y + 1 END x y 2 6 11 OUTPUT - 15 7

4 Determine types of variables
single precision integer double precision string variable total = 6 total% = 6 total# = 6 total$ = “6”

5 Key points arithmetic order
types of variables and how to assign specific types PRINT statement

6 Readings and Exercises
Schneider pp exercies 3.3 p 67 - as required Schneider p 69 #’s 17, 20, 21, 25

7 Inputs to the computer two main ways to get information into the computer INPUT statement READ and DATA statement

8 Input statement INPUT reads input from the keyboard or a file.
LINE INPUT reads a line of up to 255 characters from the keyboard or a file. INPUT [;] ["prompt"{; | ,}] variablelist LINE INPUT [;] ["prompt";] variable$ INPUT #filenumber%, variablelist LINE INPUT #filenumber%, variable$ Line Input used when inputting string and string input contains a comma

9 INPUT - simplest form INPUT variable1, variable2.... EXAMPLES: INPUT x
INPUT studnumber, names$ program stops and waits for user to enter variables number and type of variables must match

10 INPUT with prompt INPUT “prompt”; variablelist
INPUT “enter values for a and b”; a, b enter values for a and b? 1,2 INPUT “enter values for a and b”, a, b enter values for a and b1,2 variablelist separated by commas user input must match in type and number, separated by commas

11 CLS PRINT "This is a program to print envelopes." PRINT "Press any key when you are ready to begin " Temp$ = INPUT$(1) 'Assign value to variable LINE INPUT "Enter your name: "; YourName$ LINE INPUT "Enter your address: "; Address$ LINE INPUT "Enter your city, state, and ZIP code: "; CityEtc$ PRINT "Position envelope in printer and press Enter ." char% = 1 Temp$ = INPUT$(char%) LPRINT YourName$: LPRINT Address$ LPRINT CityEtc$

12 READ and DATA statements
READ statement assigns variables from corresponding DATA statement READ variable1, variable2... ..... DATA data1, data2... variable1 = data1; variable2 = data2 etc

13 following READ statements continue from data list
cannot ‘run out’ of data - OUT OF DATA ERROR variable types must match READ studnumber, names$ DATA 12345, “smith”

14 Restore statement Restores data pointer to start of data
next READ assigns from first DATA statement, first variable

15 What will be displayed when the following program is executed?
READ a, b LET x = a + b LET y = a * b RESTORE LET z = a - b PRINT x + y + z DATA 2, 4, 3, 1, 5, 3 END 21. What will be displayed when the following program is executed? READ a, b (b) 7 LET x = a + b READ a, b LET y = a * b RESTORE LET z = a - b PRINT x + y + z DATA 2, 4, 3, 1, 5, 3 END

16 Problem draw a flowchart which will
define variables for pi, radius and circumference as double, integer and double respectively set radius = 3.2, pi = 22/7 calculate the circumference print all variables

17 Flowchart

18 Dim statement DIM x AS LONG DIM y AS STRING DIM z AS DOUBLE
DIM zz AS INTEGER x& y$ z# zz%

19 Now write the program DIM radius AS integer DIM pi AS double
DIM circ AS double radius = 3.2 pi = 22/7 circ = 2*pi*r PRINT r,pi,circ Is this program correct?

20 Now change the program to include INPUT statements
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 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

21 The End

22 TUTORIAL 1. Which is the correct hierarchy for arithmetic operators (from those evaluated first to those evaluated last). 2. What value will be assigned to x when the following statement is executed? LET x = 4 * 3^2 / 5 * 4 3/5. Which is the correct hierarchy for arithmetic operators (from those evaluated first to those evaluated last). (a) (), ^, * /, 7. What value will be assigned to x when the following statement is executed? LET x = 4 * 3^2 / 5 * 4 (b) 28.8

23 3. The following statement is valid. (T/F) INPUT "IS THIS OK"; q
DATA 25, "X + 16", 14 5. The following statement is valid. (T/F) INPUT x, 5 15. The following statement is valid. (T/F) INPUT "IS THIS OK"; q true 19. The following statement is valid. (T/F) DATA 25, "X + 16", 14

24 6. What will be displayed when the following program is executed?
DATA 5, 3 READ c, d, e DATA 2, 4, 1 READ a DATA b, c, d PRINT c DATA 3, 4, 2, 1, 5 END 20. The following statement is valid. (T/F) INPUT x, 5 false 35. What will be displayed when the following program is executed? DATA 5, 3 (c= 5; d=3; e=2; a=4) READ c, d, e DATA 2, 4, 1 READ a DATA b, c, d PRINT c DATA 3, 4, 2, 1, 5 END

25 7. What will be the output of the following program?
CLS READ a$, b$, c$ PRINT a$, b$, c$, b$ DATA The, best, "of the" END 47. What will be the output of the following program? CLS READ a$, b$, c$ PRINT a$, b$, c$, b$ DATA The, best, "of the" END (b) The best of the best

26 7. Evaluate the following numeric expressions. (a) 2 - (1 - 1)
(b) 12 / * 2 (c) * 2 (d) ^ 2 (e) How would you modify the expression in (d) without changing any of the numbers so that it evaluates to 49? 52. Numeric expressions Evaluate the following numeric expressions. (a) 2 - (1 - 1) = (b) 12 / * 2=9 (c) * 2= (d) ^ 2=1 (e) How would you modify the expression in (d) without changing any of the numbers so that it evaluates to 49? (10-3)^2

27 Problem Suppose a ball is thrown straight up in the air with an initial velocity of 50 m/s. How high will the ball be after t seconds given that: ht = -16t2 + v0t + h0 where ht is height after t seconds; v0 is initial velocity and h0 is initial height


Download ppt "E0001 Computers in Engineering"

Similar presentations


Ads by Google