Sunteți pe pagina 1din 4

CSci 120 Visual Basic: Midterm Exam

Oct 15, 2008 Name___________________________________

True or False? Circle the letter corresponding to your choice. (20 points)

T F 1. A Visual Basic project can contain one or more solutions.

T F 2. A Console Application is a type of Visual Basic project.

T F 3. A Class Library is a type of Visual Basic project.

T F 4. A ListBox is a type of Visual Basic project.

T F 5. When a subroutine or function is called, parameter values can be


passed using either the ByVal or the ByRef option.

T F 6. Option Explicit is a Visual Studio flag setting which is “on” by default.

T F 7. Decimal, Integer and Single are all names of .NET numeric data types.

T F 8. Visual Basic allows you to use either the '+' character or the '&' character to
represent the concatenation operation for Strings.

T F 9. A Visual Basic “condition” is an expression whose value is either True or False.

T F 10. A Button, TextBox or other VB control has a Visible property whose value can be
either True or False.

T F 11. A Button control can have a Click event procedure.

T F 12. A TextBox control can have a Click event procedure.

T F 13. The message displayed in a Label control cannot be changed while a VB


program is running.

T F 14. The keyword Shared modifying a VB subroutine or variable in a Class


definition means that one copy of it is shared by all instances of the class.

T F 15. The first element of a Visual Basic array has zero as its index value,

T F 16. Adding too many comments in a program can make it run slower.

T F 17. Visual Basic has a number of different loop structures, including For...Next,
Do While ... Loop, Do Until ... Loop and For Each ... Next.

T F 18. A Module can contain one or more subroutines.

T F 19. A Class can contain one or more subroutines.

T F 20. A Function in a Class can be either Public or Private.


Fill in the Blanks (40 points)

1. A Visual Studio Solution consists of one or more projects.

2. To make one project in a VB solution aware of definitions in another project, you need to
define a reference in the VB project that needs to use those remote definitions.

3. In order to run VB programs on your computer, you don't need to install Visual Studio or
the entire VB development environment, but you would need to install the CLR or common language runtime.

4. The value of a String variable is a sequence of characters.

5.An apostrophe in a line of a Visual Basic program marks the beginning of a comment.

6. The value of the VB expression 40/3 is 13.333 .

7. The value of the VB expression 40\3 is 13 ..

8. You can display information on a form by assigning a value to a Label's text property.

9. The value of the VB expression “Hello World!”.ToUpper() is HELLO WORLD! .

10. The value of the VB expression “Visual Basic”.SubString(4, 2) is al .

11. If you attempt to compute too large a value in an Integer variable, integer overflow can occur.

12. VB Structures differ from VB Classes because a Structure is a value type whereas a
Class is a reference type.

13. If you want a subroutine to make some changes to one of the parameters it is passed, that
parameter should be passed by reference (or ByRef) .

14. The ReDim statement in VB can be used to change the size of an array and reallocate
the right amount of memory space to satisfy the new space requirement.

15. The If ... Then statement can execute one group of statements if a condition is true and a
different group of statements if that condition is false.

16. Variables in a VB class which are not Shared are called instance variables .

17. A condition is an expression whose value is either True or False.

18. If the condition c1 And c2 is True, then c1 must be True and c2 must be True .

19. The value of the VB expression 100 MOD 12 is 4 (the remainder when 100 is divided by 12) .

20. The value of the VB expression “Jack” & ”Jill” is “JackJill” .


What output will each of the following segments of VB code generate? Assume that each code segment is a part
of a Console Application. Use the rectangle on the left side of the page as your “console screen”.
(20 points).

testing For n As Integer = 1 To 20 Step 4


testing Console.WriteLine(“testing”)
testing Next
testing
testing

hello there Dim s As String = “hello there”


HELLO THERE Console.WriteLine(s)
hello there Console.WriteLine(s.ToUpper())
Console.WriteLine(s)

3-3 Dim x As Double = 100\31


93 Console.WriteLine(x & “-“ & x)
Console.WriteLine(31*x)

two ' define array of strings


twothree Dim a() As String = {“one”, _
“two”, “three”}
Console.WriteLine (a(1))
Console.WriteLine (a(1)+a(2))

0 ' define array of integers


1 Dim n() As Integer = {0, 1, 2, 3}
Dim x As Integer = 10
For Each v In n
If v < x Then
Note: This is a corrected version of the Console.WriteLine(v)
question. There was a misprint on the End If
9AM exam ... so no points were deducted. x = x/2
Next
Short Answer (20 points)

1. A Visual Basic project could be a Windows Application? In which situations is this the best
choice for the project type?

The development of a Windows application requires one to invest time and effort in creating
and testing a Windows form. This is most appropriate for the creation of an application
program that requires a lot of interaction with a human user and/or an “event driven”
application which allows a user to enter data in a number of possible orders.

2. A Visual Basic project could be a Console Application? In which situations is this the best
choice for the project type?

An application that doesn't run interactively is an excellent candidate for a console application.
In many cases, testing of subroutines and functions is conveniently done with a console
application because input data and execution patterns are planned in advance and can be readily
carried out by a “main routine”.

3. A Visual Basic project could be a Class Library? In which situations is this the best choice for
the project type?

A Class Library is a depository for useful functions and subroutines. If a project results in the
development of some such useful tools, they can be stored in a Class Library where they can
then be easily made available to other projects that need to use those functions or subroutines.

4. When testing code, you can't typically identify all of the tests your code needs to pass. What
principles should guide you in developing a test plan and testing scenarios so that high-quality
testing can be achieved?

Ideally, a plan for testing a software project should start falling into place before the actual
development of that software begins. Before coding begins, one should attempt to think of all
the tests the code is expected to pass. Then a representative subset of these tests can be selected
for actual testing purposes.

It is desirable to know exactly what software is supposed to do before development of that


software begins ... otherwise the programmer is faced with the awkward problem of building
something that has an incomplete description.

If a program is supposed to be able to handle a variety of different inputs, it is important to test


it carefully using extreme (maximum or minimum) allowable values as well as mid-range
values and out-of-range values.

S-ar putea să vă placă și