mIS 120 STUDY GUIDE FOR EXAM 1 / Spring 2008

NOTE: At least 10 the following questions will be in EXAM 2

Chapter 7: How to handle exceptions and validate data

Private Sub btnCalculate_Click(ByVal sender as System.Object, _

ByVal e As System.EventArgs) Handles btnCalculate.Click

Dim weightInPounds As Decimal = 0d

Try

weightInPounds = Convert.ToDecimal(txtPounds.Text)

If weightInPounds > 0 Then

Dim weightInKilos As Decimal = weightInPounds / 2.2d

lblKilos.Text = weightInKilos.ToString("f2")

Else

MessageBox.Show("Weight must be greater than 0.", "Entry error")

txtPounds.Select()

Catch ex As FormatException

MessageBox.Show("Weight must be numeric.", "Entry error")

txtPounds.Select()

End Try

End Sub

1.(Refer to code example 7-1.) What type of data validation does this program do?

a. / range checking only
b. / valid data type checking only
c. / range checking and valid data type checking
d. / it doesn’t do any data validation

ANS:C

2.(Refer to code example 7-1.) If the user clicks the Calculate button without entering data in the text box, what does the code do?

a. / It calculates the weight in kilograms.
b. / It causes a runtime error.
c. / It displays a dialog box with the message “Weight must be greater than 0.”
d. / It displays a dialog box with the message “Weight must be numeric.”

ANS:D

3.What statement causes a new exception to occur?

a. / Finally / c. / Throw
b. / Catch / d. / Try...Catch

ANS:C

4.You typically do not throw an exception

a. / when invalid data is detected
b. / to test an exception handler
c. / when the processing that’s done by a procedure can’t be completed
d. / after catching an exception and performing some processing

ANS:A

5.In Visual Basic, exceptions are

a. / objects / c. / in the Exception namespace
b. / classes

ANS:A

6.The code within a Catch block is executed when

a. / the code in the Try block doesn’t compile
b. / the code in the Try block throws an exception
c. / the Try block finishes executing
d. / a runtime error occurs

ANS:B

Chapter 8: How to work with arrays and collections

1.When you declare and initialize the values in an array, you are actually creating an instance of what class?

a. / String / c. / ArrayList
b. / SortedList / d. / Array

ANS:D

2.To refer to the ninth element in a one-dimensional array named sales, you code

a. / sales(8) / c. / sales(10)
b. / sales(9) / d. / sales.Item(9)

ANS:A

3.Which of the following statements declares a valid rectangular array?

a. / Dim ra As String / c. / Dim ra()() As String
b. / Dim ra(4,4) As String / d. / Dim ra()() As String(4)(4)

ANS:B

4.Which of the following statements determines the number of elements in a one-dimensional array named customers?

a. / Dim size As Integer = customers.UpperBound
b. / Dim size As Integer = customers.Length
c. / Dim size As Integer = customers.Size()
d. / Dim size As Integer = Arrays.Size(customers)

ANS:B

Chapter 9: How to work with dates and strings

1.In Visual Basic, dates and times are actually stored as the number of

a. / milliseconds that have elapsed since January 1, 0001
b. / seconds that have elapsed since January 1, 0001
c. / minutes that have elapsed since January 1, 0001
d. / ticks that have elapsed since January 1, 0001

ANS:D

2.Which of the following statements does not create a DateTime object whose date is set to March 28, 2007 (assume the computer’s regional settings are configured for the United States)?

a. / Dim date As Date = "03/28/2007"
b. / Dim date as DateTime = DateTime.Parse("03/28/2007")
c. / Dim date as Date = #03/28/2007#
d. / Dim date as DateTime = CDate(txtDate.Text)

ANS:A

3.Which property of the DateTime structure returns the current date with the time set to 12:00:00 AM?

a. / Today
b. / CurrentDate
c. / Now
d. / Date

ANS:A

4.If a variable named date contains a valid DateTime value, which of the following statements checks if the date falls in a leap year?

a. / Dim isLeap As Boolean = date.IsLeapYear
b. / Dim isLeap As Boolean = date.IsLeapYear()
c. / Dim isLeap As Boolean = DateTime.IsLeapYear(date)
d. / Dim isLeap As Boolean = DateTime.IsLeapYear(date.Year)

ANS:D

5.Which statement determines the due date for an invoice that is due 45 days after the invoice date?

a. / Dim dueDate As DateTime = invoiceDate.Add(45)
b. / Dim dueDate As DateTime = invoiceDate.AddDays(45)
c. / Dim dueDate As DateTime = invoiceDate.Add(new TimeSpan(45))
d. / Dim dueDate As DateTime = invoiceDate.Add(DateTime.DAYS, 45)

ANS:B

6.What is the value of startDate after the following statements are executed?

Dim startDate As New DateTime(2004, 3, 1)

startDate = startDate.AddMonths(3)

a. / March 1, 2004 / c. / January 3, 2004
b. / June 1, 2004 / d. / March 3, 2004

ANS:B

Chapter 10: More skills for working with Windows forms and controls

1.What control do you use to create a group of radio buttons?

a. / group box
b. / button set
c. / button group
d. / border

ANS:A

2.How do you retrieve the selected item in a list box?

a. / With the SelectedItem property / c. / With the GetSelection method
b. / With the Selection property / d. / With the GetSelectedItem method

ANS:A

3.What event is raised when the user selects an item from the drop-down list of a combo box?

a. / SelectedIndex / c. / TextChanged
b. / SelectedIndexChanged / d. / SelectedItem

ANS:B

4.What does the following code do?

For i As Integer = 1 To cboNumbers.Items.Count Step 2

cboNumbers.Items(i) = "XXX"

Next

a. / It changes the first item in the combo box to “XXX”.
b. / It changes every item in the combo box to “XXX”.
c. / It changes every second item in the combo box to “XXX”.
d. / It doesn’t change any items in the combo box.

ANS:C

Chapter 11: How to create and use classes

1.In a three-layer application, the three layers are

a. / the business layer, the middle layer, and the database layer
b. / the presentation layer, the middle layer, and the database layer
c. / the presentation layer, the access layer, and the database layer
d. / the presentation layer, the middle layer, and the dataset layer

ANS:B

2.When you design and develop business classes for an application, your goal is to

a. / allow development to be spread among members of a development team
b. / separate the business rules from the presentation and database logic
c. / make the application easier to develop and maintain
d. / all of the above

ANS:D

3.A class defines the properties and methods of

a. / a structure / c. / an object
b. / a value / d. / a member

ANS:C

4.The process of creating an object from a class is known as

a. / instantiation / c. / inheritance
b. / encapsulation / d. / modeling

ANS:A

5.What feature are you taking advantage of when you call the ToDecimal method of the Convert class without knowing how it’s coded?

a. / instantiation / c. / inheritance
b. / encapsulation / d. / modeling

ANS:B

Chapter 12: How to debug an application

1.When doesn’t Visual Studio enter break mode?

a. / When your application handles an exception that’s thrown
b. / When the application reaches a breakpoint that has been set
c. / When you start the execution of an application by stepping through it
d. / When you select the Break All command from the Debug menu

ANS:A

2.One benefit of the new Edit and Continue feature is that it lets you

a. / find more than one bug in a single test run
b. / find and fix more than one bug in a single test run
c. / find more than one bug in a test run without exiting from break mode
d. / find and fix more than one bug in a single test run without exiting from break mode

ANS:B

3.You can use the Step Out command to

a. / execute all statements in the rest of the application without interruption
b. / execute all statements in the rest of the current procedure without interruption
c. / execute all statements in the next procedure without interruption
d. / execute all statements up to the next breakpoint

ANS:B

4.What command steps through a program one statement at a time?

a. / Step Next / c. / Step Into
b. / Step Over / d. / Step Out

ANS:C