E0001 Computers in Engineering - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

E0001 Computers in Engineering

Description:

E0001 Computers in Engineering. Inputs to the Computer. What did we cover last week ... PRINT'pi = ';pi. PRINT 'circumference is';circ. The End. TUTORIAL ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 28
Provided by: usq9
Category:

less

Transcript and Presenter's Notes

Title: E0001 Computers in Engineering


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 59 - 66
  • 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

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
  • 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

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 2pir
  • 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 2piradius
  • PRINTradius radius
  • PRINTpi pi
  • PRINT circumference iscirc
  • DIM radius AS integer
  • DIM pi AS double
  • DIM circ AS double
  • radius 3.2
  • pi 22/7
  • circ 2piradius
  • 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 32 / 5 4

23
  • 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

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

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

26
  • 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?

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
Write a Comment
User Comments (0)
About PowerShow.com