Darren Provine at Rowan University


(Click here for text version.)

Practice Exam Problems

Exam One

Here are some problems from the book which may be useful practice for the first exam.

Programming Problems

Problems from the book

  1. Compute the distance to a storm based on the time delay between thunder and lightning. Page 96, #29.
  2. Compute winning percentage of a baseball team. Page 97, #30.
  3. Compute pounds lost due to exercise. Page 97, #31.
  4. Plato's rule for age of a wife, Page 192, #14.

Problems I made up

  1. Build a Visual Basic form, with two text boxes, two buttons, and one label. The buttons should say "Miles -> Feet" and "Yards -> Feet". The user should be able to type a number of miles into one box, push the button, and see how many feet it is. If the user types a number of yards into the other box, and clicks the right button, it should how how many feet it is. (Note: a mile is 5280 feet, and a yard is 3 feet.)
  2. Build a form with one text box, one button, and two labels. When the user clicks the button, the text in the box should be copied to the labels: one in all uppercase letters, and one in all lowercase.
  3. Write a program which reads three numbers (x, y, and z) and prints the following values:
    • (x2 + 3y) / 5
    • (x+1)(y+2)(z+3)
    • y2 - 4xz

    For example, given the input `2 3 4', it should print:

    2.6
    105
    -23
    
  4. Write a function `compute' which takes three double parameters, x, y, and z, and returns the value of `3x2 + 5y + 10z'. For example, compute(10,8,2) should return 360. Write your function so that it can be called by this click event:
    Private Sub Command1_Click
        Dim x As Double, y As Double, z As Double
    
        x = Val(txtX.text)
        y = Val(txtY.text)
        z = Val(txtZ.text)
    
        Picture1.Print compute(x, y, z)
    End Sub
    

Conceptual Problems

For these, the program is given to you and you have to figure out what it does. After you think you have the answer, you can type in the program and run it to see if you were correct.

Problems from the book

  1. Finding maximum height of a thrown ball, Page 189, #4.
  2. Find volume of a cylinder, Page 189, #5.

Problems I made up

  1. What is printed by the following code?
    
        Dim x As Integer, y As Integer, z As Integer
    
        x = 10
        y = 20
        z = 30
    
        z = (x + y) * (z - x)
        picResults.Print z
        z = 4 + (y / x)
        picResults.Print z
        z = 29 mod 5
        picResults.Print z
        picResults.Print (x / y) + 8
    
    
  2. What is printed when Command1 is clicked?
    Private Sub Command1_Click()
        Dim a As Integer, b As Integer
    
        a = 1
        b = 2
        g(b)
        Call f(a,b)
        Call f(b,a)
    End Sub
    
    Private Sub f(x As Integer, y As Integer)
        Picture1.Print "f: "; x
        g(y)
    End Sub
    
    Private Sub g(z As Integer)
        Picture1.Print "g: "; z
    End Sub
    
    

(US flag) This page's URI: http://elvis.rowan.edu/~kilroy/class/intro/?Prac1
Last modified: Friday, 20 February 2009, 3:19:13pm