Date post: | 28-Dec-2015 |
Category: |
Documents |
Upload: | corey-george |
View: | 221 times |
Download: | 0 times |
E0001 Computers in Engineering
Inputs to the Computer
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
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
Determine types of variables
single precision integer double precision string variable
total = 6
total% = 6
total# = 6
total$ = “6”
Key points
arithmetic order types of variables and how to assign
specific types PRINT statement
Readings and Exercises
Schneider pp 59 - 66 exercies 3.3 p 67 - as required Schneider p 69 #’s 17, 20, 21, 25
Inputs to the computer
two main ways to get information into the computer• INPUT statement• READ and DATA statement
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 - 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
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
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$
READ and DATA statements
READ statement assigns variables from corresponding DATA statement
READ variable1, variable2...
.....
DATA data1, data2...
variable1 = data1; variable2 = data2 etc
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”
Restore statement
Restores data pointer to start of data• next READ assigns from first DATA
statement, first variable
What will be displayed when the following program is executed?
READ a, b
LET x = a + b
READ a, b
LET y = a * b
RESTORE
READ a, b
LET z = a - b
PRINT x + y + z
DATA 2, 4, 3, 1, 5, 3
END
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
Flowchart
p rin t va riab les
ca lcu la te c ircu m feren ce
le t rad iu s = 3 .2 &p i = 2 2 /7
d im en s ion variab les
Dim statement
DIM x AS LONG
DIM y AS STRING
DIM z AS DOUBLE
DIM zz AS INTEGER
x&
y$
z#
zz%
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?p rin t va riab les
ca lcu la te c ircu m feren ce
le t rad iu s = 3 .2 &p i = 2 2 /7
d im en s ion va riab les
Now change the program to include INPUT statementsDIM 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
The End
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. The following statement is valid. (T/F)
INPUT "IS THIS OK"; q
4. The following statement is valid. (T/F)
DATA 25, "X + 16", 14
5. The following statement is valid. (T/F)
INPUT x, 5
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
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
7. Evaluate the following numeric expressions.
(a) 2 - (1 - 1)
(b) 12 / 4 + 3 * 2
(c) 2 + 9 * 2
(d) 10 - 3 ^ 2
(e) How would you modify the expression in (d) without
changing any of the numbers so that it evaluates to 49?
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