Computer Science 230 – Fall 2004
11/04/04 Mid Term Test # 2 Test Form A
Name:
Instructions:
Answer ALL questions on the answer sheet provided.
Hand in TEST, Answer Sheet, and Help Sheet, each with your name on it.
Remember to put the letter of your test form on your answer sheet.
Please ask any clarifying questions you have (come up).
Completion (3 points each)
True/False (2 points each)
Multiple Choice (3 points each)
A) when defining them in the procedure, you must specify their data type
B) when passing them to a procedure, you must specify their type in the call
C) all parameters for a given procedure must be the same type
D) all of the above
E) none of the above
A) a fileWriter variable is used for writing to output files
B) a stream reader variable is used for reading from input files
C) when checking for the end of a file, a fileEnd variable is consulted
D) all of the above
E) none of the above
A) if the file already exists, the open will cause an exception
B) if the file already exists, the open will cause previous contents to be lost
C) if the file already exists, new content will be added after the existing contents at the end of the file
D) all of the above
E) none of the above
Valid/Invalid (4 points each)
Dim x as integer = 137
Do
X = X / 10
Until x < 1
Private sub doSomething ( byVal firstparam as double, byVal secondparam as String)
‘ valid code in here – assume body of procedure is fine
End sub
And assume variables have been declared and properly initialized:
Dim silly as double = 12.5
Dim wild as String = “Wild World”
Report if the following is call is valid or invalid – if invalid, explain why!
doSomething(wild,silly)
dim x as integer = 3
dim y as integer = 50
do while (x < 10) AndAlso (y <100)
x = x + 1
y = y + 3
loop
Dim I as integer
For I = 5 to 3 step -1
Msgbox(i.toString() )
Next i
Short Answer (points as shown)
(6 points)
Dim inpf as IO.StreamReader
Dim cnt as integer = 0
Dim current as string
Inpf = IO.File.OpenText(“myinputs.txt”)
For cnt = 0 to 10
Current = inpf.ReadLine()
lstStuff.items.add(current)
next cnt
inpf.close()
Doing and Understanding: (points as shown)
(5 points)
Dim num as integer = 20
Dim max as integer = 12
do
Msgbox(“==> “ & num.toString( ) )
Num = num + 1
Loop while num < max
(6 points)
Dim x as double = 100
Do while Withdraw(x, 30)
msgbox(“X: “ & x.toString( ))
loop
Private function Withdraw( byRef balance as double, byVal amount as double) as Boolean
If balance >= amount then
Balance = balance – amount
Return true
Else
Return false
End if
End function
(9 points)
Dim X as integer = 1
Dim Y as integer = 2
For cnt = 1 to 2
X = x + cnt
Y = y + x
Do until y > 15
Y = y * x
Msgbox( “in - X: “ & x.toString() & “ Y: “ & y.toString())
Loop
Msgbox( “out - X: “ & x.toString() & “ Y: “ & y.toString())
Next cnt
Msgbox(“outa here”)
(8 points)
Dim inpf as io.streamreader
Dim strLine as string
Dim loc as integer
Dim stuff as string
Inpf = io.file.opentext(“text.txt”)
Do until inpf.peek = -1
strLine = inpf.ReadLine()
loc = strLine.IndexOf(“,”c)
stuff = strLine.substring(loc + 1)
msgbox(“stuff: “ & stuff)
loop
text.txt:
Hello, The, Numb
I, End, By
Must, Of, Linkin
Be, The, Park
Writing Code (points as shown)
(6 points)
(8 points)
(12 points)