HTTP/1.0 200 OK Content-type: text/html Test 9 - Statements

,6/3 19:19 CDT,Due date-->9/20/2003 10:00 CDT

  1. What is the value of x after executing?
    x=7 y= 10
    x=x*27-y+33%2*(-8)
    y=x*x-y*0xAB
    x=x+y

  2. Suppose the following definitions are in effect.
    P=false
    Q=true
    R=false
    Check all expressions that evaluate to TRUE.
    1) not (not P) 2) P and Q 3) P or R 4) P and (Q or R)

  3. Consider the following code segment:
    if (i<=j) then
    print(1)
    else
    print(2)
    end
    print(3)
    What prints if i is 3 and j is 5?
    1) 23 2) 13 3) 123 4) 3

  4. Short-circuit evaluation is a programming trick. What does it optimize?
    1) space 2) time 3) both 4) neither

  5. Assume the following definitions are in effect.
    P=true
    Q=false
    R=false
    Check all expressions that "short-circuit" during execution.
    1) Q and P 2) P or R 3) not P 4) R and (Q or R)

  6. Is the following for loop legal?
    for x=6,, do print(x) end
    1)yes 2)no

  7. Is the following for loop legal?
    for x=6,1 do print(x) end
    1)yes 2)no

  8. If all variables have the integer value 1, what is the value of x after executing x = x*y ?

  9. How many times will the following loop execute if x= 13 and y=3?
    while (x>=8) do y = y+x end
    1)0 2)8 3) 13 4)a lot

  10. What number does the following program print?
    x=1 total=0
    repeat
    y=x*x total = total+y x=x+1
    until (x>8)
    print(total)

  11. Is the expression ( 11>4) and (4<3)
    1) false 2) true

  12. Is the expression (9>6) or (1<3)
    1) false 2) true

  13. Which of the following statements transfers control to the end of a for, while?
    1)return 2)goto 3)continue 4)break

  14. How many times is i=i+1 executed?
    while (3<5) do i=i+1 end

    1) 0 2) 1 3) 2 4) lots

  15. How many times is i=i+1 executed?
    for j=0, 3 do i=i+1 end
    1) 0 2) 1 3) 3 4) 4 5) lots

  16. What prints for the following?
    for i=1, 6, 2 do print(i) end

  17. What prints for the following?
    for i=8, 5, -1 do print(i) end

  18. What prints for the following?
    for i=2, 1, 3 do print(i) end

    1) nothing 2) lots 3) 2 4) 2222

  19. Check all the loop statements that break can be used to exit.
    1) do 2) while 3) switch 4) if 5) for 6) assignment

  20. What prints for the following?
    for i=1, 5, 2 do print(i) break end
    1) nothing 2) lots 3) 1 4) 135

  21. The minimum number of variables to implement a program that counts the number of its inputs that are positive, negative, or zero is
    1) 1 2) 3 3) 4 4) 6

  22. The best data type (of those listed) to implement a program that counts is
    1) boolean 2) character 3) integer 4) String

  23. What is the minimum number of conditional tests necessary to sort any 3 integers into ascending order?
    1) 2 2) 3 3) 4 4) 7

  24. Which of the following is the correct syntax for a label?
    1) here: 2) ::here:: 3) :here: 4) here::

  25. What prints for the following?
    i=2
    ::startLoop::
    if i>5 then goto endLoop end
    print(i)
    i=i+2
    goto startLoop
    ::endLoop::

  26. Typically, every variable should be preceded by which keyword?
    1) local 2) static 3) global 4) int