Sie sind auf Seite 1von 13

DANIEL MACINTYRE COLLEGIATE INSTITUTE

COMPUTER SCIENCE 20S


FINAL EXAMINATION
JUNE / 2009
N.MALANDRAKIS

/ 120 + / 10 + / 10 = / 140 = %

NAME: ___________________________
PART A: MULTIPLE CHOICE (50 x 1 MARKS)

Please place the letter of the correct answer on the line.

__1) What kind of information CANNOT be represented by a simple variable type in


Visual Basic?
a) text b) fraction c) yes or no d) decimals

__2) Which of the following events are activated in order to use Ascii codes for keys?
a) KeyDown b) KeyPress c) Load d) KeyUp

__3) Which of the following shows the proper order of mathematical operations followed by Visual
Basic?
a) brackets, powers, mult and div, add and subt.
b) powers, mult and div, add and subt, brackets.
c) powers, brackets, mult and div, add and subt.
d) mult and div, add and subt, brackets, powers.

__4) Which of the following statements would result in an error if typed as code?
a) Dim myArray(-4 to 5) As Integer
b) Dim x@ As Integer
c) Dim a_REALLY_sIlLyName3 As Double
d) Dim z As booleAn

__5) Which of the following Timer properties control moving a Timer around the form during run
time?
a) Left property b) Interval property
c) Top property d) None

__6) Which of the options below is not a standard Visual Basic data type?
a) currency b) strings c) whole numbers d) percentages

__7) Which of the following cannot be represented by a String type variable?


a) numerals b) letters c) icons d) “commas”

__8) Which statement is not used to declare something in a program?


a) Dim statement b) Declare statement
c) Global statement d) Const statement

__9) Of the following objects, which does NOT respond directly to events initiated by
the user?
a) textbox b) timer c) command button

__10) The Int() function…


a) rounds off a decimal b) converts a string to an integer
c) converts an integer to a string d) cuts of decimal places

__11) When a textbox has the focus, it is ready to


a) add program code b) display a calculated value
c) receive data from a file d) receive user input
__12) When you enter “end if” at the end of an If-Then statement, Visual Basic
automatically expands it to
a) Endif b) end if c) end If d) End If

__13) In this If_Then statement:

If condition Then
… statements
End If

…if the condition tested is False, the program

a) executes the statements between the Then and the End If.
b) executes the statements following the End If.
c) does not execute any statements at all.
d) executes both the statement between the Then and the End If and the
statements following.

__14) To include a comment in your code, start the comment


a) Anywhere on the line.
b) At the beginning of the line and precede it with a single quote.
c) Anywhere on the line and precede it with a single quote.
d) At the end of the line and precede it with a single quote.

__15) When you set the Visible property of a label to False, it


a) disappears when it is clicked b) disappears immediately
c) remains visible until the program is run
d) remains visible until the program is stopped

__16) To use more than one condition in an If-Then statement, you should join the
conditions with:
a) an And or Or b) &
c) + d) a True or False

__17) For the statement (a And b) to be True,


a) either a or b must be True b) both a and b must be True
c) neither a nor b must be True d) either a or b might be False

__18) 83 mod 19 is: a) 4 b) 6 c) 7 d) 0

__19) To calculate a cumulative sum you might see code that looks like…
a) T=T+x b) C=C+1 c) T+x=T d) C+1=C

__20) Incrementing means to


a) add x to the running total b) subtract 1 from the total
c) add 1 to the total d) add a new section to a program
__21) When keeping a running total with a statement like:

Balance = Balance + Transaction

a) the value of Transaction must be positive


b) the value of Transaction must be negative
c) the value of Transaction may be positive or negative
d) the value of Transaction may only be currency

__22) To have a For loop that executes 61 times, it would look like…
a) For x = -30 to 30 b) For x = -5 to 55
c) For x = 0 to 61 d) For x = 1 to 62

__23) The statement:

For x = 50 to 100

generates values for x that range from…

a) 1 to 50 b) 1 to 100 c) 50 to 100 d) 50 to 101

__24) A number is a perfect square if:

a) It has a whole number square root.


b) It doesn’t have a whole number square root.
c) It has 4 factors.
d) It looks like square.

__25) The ampersand operator (&) is used to


a) join a string together with a value
b) join two strings together
c) join a string together with the text from a textbox.
d) display text in a MsgBox

__26) For two strings to be equal, they must


a) be of equal length
b) match character by character and be of equal length.
c) match in the first n characters
d) be composed of the same characters.

__27) Usually the statements in the body of any loop are


a) indented b) printed in all caps c) printed in all lower case

__28) 41 Mod 2 is:

a) 0 b) 1 c) 41 d) 2
__29) Which two words should you type at the top of your code to insure that all spelling mistakes and
undeclared variables are caught?
a) Option Implicit
b) Check Spelling
c) Dim Explicit
d) Option Explicit

__30) In which of the following events would you see the expression “VBKey7”?
a) KeyDown
b) KeyPress
c) KeyAscii
d) KeyUp

__31) A variable declared with Global keyword in the general declarations sections of a
code module
a) is available only within the code module
b) is available to every procedure throughout the project
c) is a syntax error d) is always of the default type

__32) Declaring a variable within a procedure in a code module ensures visibility


a) only within that procedure
b) throughout the code module
c) throughout the form
d) throughout all forms

__33) Arrays are used to store


a) numbers b) strings c) user data typesd) all

__34) Which of the following cannot be used to declare an array?


a) Dim b) Declare d) Global

__35) If you know before a loop begins, how many times it should execute, use a
a) If…statement b) Select Case
c) For Next Loop d) Array

__36) What statement is an alternative to using several If…Then statements?

a) Select Case b) For Loop


c) Array d) Integer

__37) The following are three parameters sent to the InputBox function:
a) the value of the function, its title, and a prompt
b) its title, a prompt, and a default value
c) a prompt, a default value, and a message box
d) an icon, a prompt, and a caption

__38) To leave a For While loop prematurely, use an


a) Exit Loop b) Exit Do c) Exit For d) Exit Select

__39) If you need to resize an image, you should put it into a


a) picture box b) image box c) textbox

__40) When you move the mouse cursor over an object, which event gets executed?
a) MouseOver
b) MouseMove
c) KeyPress
d) MouseDown

__41) Which property controls if a label’s caption is centered or not?

a) IsCentered b) Alignment
c) Left d) Right

__42) Using For…Loops are a great way to access objects that are in a:
a) Select Case statement b) Control Array
c) For-statements d) Dim statements

__43) A timer interval of 450, in real-life seconds are:

a) 0.045 b) 4500 c) 0.45 d) 4.5

__44) To declare an array of 10 Strings with the name ALIST use the declaration
a) General ALIST(1 to 10) As String
b) Dim ALIST(1 to 10) As Srting
c) Dim ALIST(0 to 10) As String
d) Dim ALIST(1 to 10) As String

__45) When the statement “List1.Clear” is executed


a) the form is cleared b) the list box is cleared
c) the picture box is cleared d) the program stops

__46) The BEST variable name for a counter that counts how many times the number
“5” shows up in a list would be:
a) theVariableWhichCountsHowManyFives
b) fIvEcOuNt c) counter d) fiveCounter

__47) To move an object closer to the bottom of the form, which of the following
properties / commands would we NOT use?
a) Move b) Top c) Left d) the object name

__48) When a Timer is first put on a form, its Name & Interval properties are:
a) tmr1, 1000 b) Timer, 0 c) Timer1, 1000 d) Timer1, 0

__49) Which of the following is not a way to run a Visual Basic program?
a) Select Run from the Visual Basic menu bar, then select Start
b) Press the function key, F5
c) Click the start button from the Visual Basic toolbar
d) Type Start from the keyboard

__50) The files that make up a Visual Basic project are listed in the
a) Properties window b) toolbar
c) Toolbox d) Project window

PART B: TRUE-FALSE (T or F) (30 x 1 MARKS)

__51) The division operator is represented by the character, “\”.


__52) A timer control may be put on a form by choosing it from a menu item.
__53) 45 Mod 1 = 45.
__54) You cannot represent a fraction such as 1/7 exactly with a standard data type.
__55) The Str() function converts a string to a value.
__56) The default value of a Boolean variable when it’s first declared is True.
__57) The data type of the “Text” property of a textbox is Integer.
__58) If a is True and b is False, then (a And b) is True.
__59) 36 Mod 5 = 31.
__60) C = C + 1 is an illegal statement in Visual Basic; subtracting C from both sides
results in 0 = 1.
__61) A timer interval of 1 is equivalent to 0.01 real life seconds?
__62) The usual way to clear a textbox is to have a statement like txtX.Text = “ “.
__63) One reason to compare strings to each other is to sort them into alphabetical order.
__64) A string is less than another string if the first string is closer to z.
__65) One loop may not be used inside another.
__65) Strings are joined together with the ampersand operator.
__66) The condition tested in a Do While loop should eventually be false, so the loop
will end.
__67) To end your program at any time use the End command
__68) To gather input from the user, use a MsgBox statement.
__69) In a menu control array, each item of the array has a different name.
__70) The Select Case statement ends with the “Select End” statement.
__71) Global variables can be used to communicate values form one program to another.
__72) A user-defined data type is a combination of standard data types and other
user-defined types grouped together under a single name.
__73) A timer on the form has a Tag property.
__74) The Tag property can be a numeric or literal (string) value.
__75) The default value for an integer that has just been declared is 1.
__76) If you want code to execute as soon as you run your program, then you place
that code in the Form Load event.
__77) For-Next loops are used when you know exactly how many times you want a piece
of code to execute.
__78) The “Step” part of a For loop controls increments each time through the loop.
__79) Will the following code be error free:

Dim x as Integer

x=x/x

__80) There are 12 letters in the last name of your computer science teacher this year.

PART C: FILL IN THE BLANK (10 x 1 MARKS)

Fill in the blank with the term(s) that best fit the sentence.

81) The “number” that refers to the “slot” in an array is called an ______________.
82) The method / function which takes an ascii code is the _________ method.
83) To clear a list box, use the _________ property.
84) You declare variables whose values must be available to more than one form in a
_________________.
85) To see if x is divisible by y, you test the condition: if…______________.
86) To set up a loop that generates values of x from 10 to 75, use the statement
____________________ to begin.
87) Decimals are represented by the ______________ data type.
88) Find the length of a string with the _______ function.
89) The __________ function converts a string to all uppercase characters.
90) Often the name of a constant is written with ________________.
PART D: ERROR CHECKING (10 x 1 MARKS)

91) Consider the following pieces of code. There are errors in the pieces of code.
Your job is to find them and state the reason for the error. There is a single
quote at the end of each line. Wherever you see an error, CIRCLE the line that
contains the error, and write a sentence (comment) or two after the single quote
that explains the error. Some lines may contain more than one error.
(2 x 5 MARKS)
a)
Dim a As Integer '
Dim b As Integer '

cmdGo_Click() '

a=a/a '
'
b=x–5 '
'
For c = 1 to x '
'
1-c=b '
'
Next x '
'
End Sub '

b)
Dim myArray(4 to MAX) As String '
Const MAX = 50 '
Dim z As Integer '

cmdGo_Click()
myArray(3) = “Bob” '

z=0 '
temp = myArray(3) '

if z = 1 '
z=0 '
End If '
End Sub
PART E: LONG ANSWER

You will be given two long answer questions. For each question make sure to read the
instructions carefully and remember that you are writing code as if you were using V.B., which means
that all english comments are to be handled accordingly as they would in V.B.

92) You are to complete code for ONLY A CLICK EVENT, whose main purpose is to look after a
Mastercard statement for a customer. When the user clicks the command button you are to do
the following: (10 MARKS)

 Have an input box CONTINUALLY come up 10 TIMES asking the user if they
would like to make a purchase. They would then enter an amount.
i. Add the amount to a running total (starts off at 0), which will be their current
balance, which will always be displayed on a label called lblBalance.
ii. If the purchase has a negative amount, then assume that the
customer is making a payment on the balance, so that amount would
be subtracted from the balance, and then have the lblBalance updated
accordingly.
 The credit card has a MAXIMUM limit of $5000. If the balance ever happens to
exceed that limit then have a message box come up conveying that information to the
customer and do not allow any more purchases, only payments.
 If the user ever types in 0 for a purchase in the input box then that is your cue to end
the program.

You are to declare all variables, constants and ANY OTHER THINGS YOU NEED within the
event and if you think you need other things to help improve your mark then do whatever you
have to do to do that.

• WRITE CODE ON NEXT PAGE *

* USE THIS AREA AS ROUGH WORK *


92) Write code here:

cmdCreditCard_Click()
End Sub
93) You are to write code for a function called “Numbers,” which does the following when it’s
called: (10 MARKS)

 The user is inputing numbers via a textbox called txtNum.


 You are storing ONLY positive or negative odd numbers.
i. That means 1, 3, 5, …etc and -1, -3, -5, …etc.
ii. You can change any number to a positive by using Abs(x).
1. ex Abs(-5) = 5 Abs(-19) = 19 … and so on
 If the user does not enter a number which is what you want, then simply bring up a
message box indicating that the number is not a positive or … and that’s it. Wait for
them to enter another value in the textbox.
 If the user has entered a positive or negative odd number then you are to store it in an
ARRAY.
i. You will ALWAYS need to display how many numbers are in the
array at all times in a label.
 You can ask the user to enter numbers ONE AT A TIME.
 Once the user enters 0, then stop the loop, and display all the values of the array in a
listbox called lstNumbers.

You are to declare all variables, constants and ANY OTHER THINGS YOU NEED within the
event and if you think you need other things to help improve your mark then do whatever you
have to do to do that.

• WRITE CODE ON NEXT PAGE *

* USE THIS AREA AS ROUGH WORK *


93) Write code here:

Public Sub Numbers()

End Sub

Das könnte Ihnen auch gefallen