Exercises

advertisement
Overview
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
d
c
a
b
d
b
c
d
c
b
a
d
a
d
a program
machine code
Assembly
High-level
All of the above.
JIT compiler
class
talk
instance
encapsulation
abstraction
Polymorphism
base, derived
inheritance
a) head, body, legs, heart, lungs
b) eat, run, play, walk, bark
c) three
Programming with VB 2005 3E
0-4188-3674-5
1
Chapter 1 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
c Properties
d Solution Explorer
b .sln
d All of the above.
b Text
c Name
d StartPosition
The Text property controls the text that appears in the Windows form’s title bar, and on the application’s
button on the Windows taskbar while the application is running. The Name property assigns a name to the
Windows Form object; you use the name to refer to the form in code. The programmer uses the Name
property. The user reads the Text property.
9. A Windows Form object is the form itself. A Windows Form object can be viewed in the designer window
and appears on the screen when the application is run. The form file object is the disk file that contains the
code associated with the Windows Form object.
10. The dot member access operator indicates that the Label class is a member of the Forms namespace, which is
a member of the Windows namespace, which is a member of the System namespace.
Exercises
1.
2.
3.
4.
5.
See the VB2005\Chap01\laCharities Solution files on the Solutions Disk.
See the VB2005\Chap01\laPhoto Solution files on the Solutions Disk.
See the VB2005\Chap01\laYorktown Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap01\laGreenwood Solution files on the Solutions Disk.
d. The ControlBox property determines whether a form has a Control/System menu box in the title bar.
e. Setting the ControlBox property to False removes the icon and the Minimize, Maximize, and Close
buttons from the form’s title bar.
g. The MaximizeBox property determines whether a form has a Maximize button in the title bar.
h. Setting the MaximizeBox property to False dims (grays-out) the Maximize button in the form’s title bar.
j. The MinimizeBox property determines whether a form has a Minimize button in the title bar.
k. Setting the MinimizeBox property to False dims (grays-out) the Minimize button in the form’s title bar.
(Discovery) See the VB2005\Chap01\laGreenwood Solution files on the Solutions Disk.
d. The ShowIcon property determines whether an icon appears in the form’s title bar.
e. The ShowInTaskbar property determines whether the value stored in the form’s Text property appears on
the Windows taskbar when the application is running.
Chapter 1 – Lesson B
Questions
1.
2.
3.
4.
5.
6.
c
d
d
d
a
b
Label
Text
All of the above.
All of the above.
System.Windows.Forms
The executable file that Visual Basic automatically creates when you start an application has the
same name as the solution, but with an .exe extension.
7. a Me.Close
8. Syntax refers to the rules of a programming language.
9. You use the Class Name list box to select the object you want to code. You use the Method Name list box to
select the event you want to code.
10. A keyword is a word that has a special meaning in a programming language.
Programming with VB 2005 3E
0-4188-3674-5
2
Exercises
1.
2.
3.
4.
See the VB2005\Chap01\lbMechanics Solution files on the Solutions Disk.
See the VB2005\Chap01\lbCostello Solution files on the Solutions Disk.
See the VB2005\Chap01\lbTabatha Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap01\lbJerrods Solution files on the Solutions Disk.
Chapter 1 – Lesson C
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
c timer
a Enabled
b Tick
c 10,000
b The user can see a timer control while the application is running.
c MinimizeBox
d FormBorderStyle
a ControlBox
To print a project’s code, open the Code Editor window. Click File on the menu bar, and then click Print.
Click the OK button in the Print dialog box.
10. Delete the control from the form. Open the Code Editor window and delete the code contained in the control’s
event procedures.
Exercises
1.
2.
3.
4.
5.
6.
See the VB2005\Chap01\lcJefferson Solution files on the Solutions Disk.
See the VB2005\Chap01\lcSplash Solution files on the Solutions Disk. The student is instructed to create his
or her own splash screen.
(Discovery) See the VB2005\Chap01\lcOnOff Solution files on the Solutions Disk. (This solution also is used
in Discovery Exercise 4, which teaches the student to display a graphic on each button’s face.)
(Discovery) See the VB2005\Chap01\lcModified OnOff Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap01\lcTooltip Solution files on the Solutions Disk.
(Debugging) See the VB2005\Chap01\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student must remove the label control’s Click event procedure from the Code Editor window, and then
enter the Me.Close() statement in the xExitButton’s Click event procedure.
Programming with VB 2005 3E
0-4188-3674-5
3
Chapter 2 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
b
c
d
c
a
a
c
b
2
4
1
3
10. 5
3
4
6
2
1
label
text box
TOE
upper-left corner
first
book title capitalization
Identifying labels should be entered using book title capitalization.
Sentence capitalization
Identify the objects to which you will assign the tasks.
Draw a sketch of the user interface.
Identify the tasks the application needs to perform.
Identify the events required to trigger an object into performing its assigned tasks.
Test and debug the application.
Build the user interface.
Code the application.
Assemble the documentation.
Plan the application.
Meet with the client.
Exercises
1.
TOE charts and sketches may vary.
Task
Get the following from the user:
name
sales
commission rate
Calculate the commission
Display the following:
name
sales
commission rate
commission
End the application
Clear the screen
Programming with VB 2005 3E
0-4188-3674-5
Object
Event
xNameTextBox
xSalesTextBox
xRateTextBox
xCalcButton
None
None
None
Click
xNameTextBox
xSalesTexBox
xRateTextBox
xCalcButton,
xCommissionLabel
xExitButton
xClearButton
None
None
None
Click, None
4
Click
Click
Task
1. Calculate the commission
2. Display the commission in
the xCommissionLabel
control
Clear the screen
End the application
Display the commission (from
xCalcButton)
Get and display the name, sales,
and rate
Object
xCalcButton
Event
Click
xClearButton
xExitButton
xCommissionLabel
Click
Click
None
xNameTextBox,
xSalesTextBox,
xRateTextBox
None
Sample of a vertical arrangement:
Sample of a horizontal arrangement:
2.
TOE charts and sketches may vary.
Task
Get the following from the user:
current year’s sales for each region
projected increase % for each region
Calculate the projected sales for each
region
Programming with VB 2005 3E
0-4188-3674-5
Object
Event
xNorthSalesTextBox,
xSouthSalesTextBox,
xEastSalesTextBox,
xWestSalesTextBox
xNorthIncreaseTextBox,
xSouthIncreaseTextBox,
xEastIncreaseTextBox,
xWestIncreaseTextBox
xCalcButton
None
5
Click
Display the following:
current year’s sales for each region
xNorthSalesTextBox,
xSouthSalesTextBox,
xEastSalesTextBox,
xWestSalesTextBox
None
projected increase % for each region
xNorthIncreaseTextBox,
xSouthIncreaseTextBox,
xEastIncreaseTextBox,
xWestIncreaseTextBox
None
projected sales for each region
xCalcButton
xNorthSalesLabel, xSouthSalesLabel,
xEastSalesLabel, xWestSalesLabel
xExitButton
xClearButton
Click
None
End the application
Clear the screen
Task
1. Calculate the projected sales
for each region
2. Display the projected sales in
the xNorthSalesLabel,
xSouthSalesLabel,
xEastSalesLabel, and
xWestSalesLabel controls
Clear the screen
End the application
Display the projected sales (from
xCalcButton)
Get and display the projected
increase % for each region
Get and display the current year’s
sales for each region
Object
xCalcButton
Event
Click
xClearButton
xExitButton
xNorthSalesLabel,
xSouthSalesLabel,
xEastSalesLabel,
xWestSalesLabel
xNorthIncreaseTextBox,
xSouthIncreaseTextBox,
xEastIncreaseTextBox,
xWestIncreaseTextBox
xNorthSalesTextBox,
xSouthSalesTextBox,
xEastSalesTextBox,
xWestSalesTextBox
Click
Click
None
Sample of a vertical arrangement:
Programming with VB 2005 3E
0-4188-3674-5
6
None
None
Click
Click
Sample of a horizontal arrangement:
3.
See the VB2005\Chap02\laTime Solution files on the Solutions Disk. Answers may vary.
Programming with VB 2005 3E
0-4188-3674-5
7
Chapter 2 – Lesson B
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
b TabIndex
d both b and c
a dark text on a light background
b x
a sans serif
d BorderStyle
a &
d Text
The first choice for an access key is the first letter of the caption or identifying label, unless another letter
provides a more meaningful association. If you can’t use the first letter and no other letter provides a more
meaningful association, then use a distinctive consonant in the caption or label. The last choices are a vowel
or number in the caption or label.
10. To give keyboard access to a text box, assign an access key to its identifying label control. Then set the label
control’s TabIndex property to a value that is one number less than the text box’s TabIndex value.
Exercises
1.
2.
3.
See the VB2005\Chap02\lbPaper Solution files on the Solutions Disk.
See the VB2005\Chap02\lbRMSales Solution files on the Solutions Disk.
See the VB2005\Chap02\lbTime Solution files on the Solutions Disk.
Chapter 2 – Lesson C
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
a Me.xNameTextBox.Text = ‘’
b Me.xTotalLabel.Text = Val(Me.xSales1Label.Text + Me.xSales2Label.Text)
b Format
d Val
d rectangle
a a logic error
b a syntax error
2.92
2
23
Exercises
1.
2.
3.
4.
See the VB2005\Chap02\lcPaper Solution files on the Solutions Disk. Answer using valid test data: $200.00
commission
See the VB2005\Chap02\lcRMSales Solution files on the Solutions Disk. Answers using valid test data: North
projected sales are 27,500.00; South projected sales are 10,500.00; East projected sales are 10,400.00; West
projected sales are 16,650.00
See the VB2005\Chap02\lcTime Solution files on the Solutions Disk. Answers using valid test data: 30
weekday hours and 2 weekend hours
See the VB2005\Chap02\lcJohnLee Solution files on the Solutions Disk. (The interface might not contain a
Clear button.)
Answer using first set of test data: 4500 ending balance
Answer using second set of test data: 0 ending balance
Task
1. Calculate ending balance
2. Display ending balance in xEndLabel control
Programming with VB 2005 3E
0-4188-3674-5
Object
xCalcButton
8
Event
Click
Clear the screen
End the application
Display the ending balance (from xCalcButton)
Get and display the beginning balance, monthly
earnings, monthly expenses
Pseudocode:
xCalcButton:
xClearButton
xExitButton
xEndLabel
xBeginTextBox,
xEarnTextBox,
xExpTextBox
Click
Click
None
None
Calculate ending balance = beginning balance + monthly earnings – monthly
expenses
Display ending balance in xEndLabel control
xClearButton:
Clear the Text property of the xBeginTextBox, xEarnTextBox, xExpTextBox controls
Clear the Text property of the xEndLabel control
Send the focus to the xBeginTextBox control
xExitButton:
End the application
5.
See the VB2005\Chap02\lcLanaJones Solution files on the Solutions Disk. (The interface might not contain a
Clear button.)
Answer using first set of test data: 18 average
Answer using second set of test data: 0 average
Task
1. Calculate average of three numbers
2. Display average in xAvgLabel control
Clear the screen
End the application
Display the average (from xCalcButton)
Get and display the first number, second
number, and third number
Pseudocode:
xCalcButton:
Object
xCalcButton
Event
Click
xClearButton
xExitButton
xAvgLabel
xNum1TextBox,
xNum2TextBox,
xNum3TextBox
Click
Click
None
None
Calculate average = (first number + second number + third number) / 3
Display average in xAvgLabel control
xClearButton:
Clear the Text property of the xNum1TextBox, xNum2TextBox, xNum3TextBox controls
Clear the Text property of the xAvgLabel control
Send the focus to the xNum1TextBox control
xExitButton:
End the application
6.
See the VB2005\Chap02\lcBookworms Solution files on the Solutions Disk. (The interface might not contain
a Clear button.)
Answers using first set of test data: $4,000.00 paperback value, $3,750.00 hardcover value, 150 total versions,
$7,750.00 total value
Answers using second set of test data: $0.00 paperback value, $0.00 hardcover value, 0 total versions, $0.00
total value
Task
1. Calculate the paperback value, hardcover
value, total number of paperback and
hardcover versions, and total value of the
paperback and hardcover versions
2. Display the calculated amounts in the
Object
xCalcButton
Programming with VB 2005 3E
0-4188-3674-5
9
Event
Click
xPaperValLabel, xHardValLabel,
xTotalNumLabel, and xTotalValLabel
controls
Clear the screen
End the application
Display the paperback value, hardcover value,
total number of paperbacks and hardcover
versions, and total value of paperback and
hardcover versions (from xCalcButton)
Get and display the title, number of paperback
versions, number of hardcover versions, cost of
paperback version, cost of hardcover version
Programming with VB 2005 3E
0-4188-3674-5
xClearButton
xExitButton
xPaperValLabel,
xHardValLabel,
xTotalNumLabel,
xTotalValLabel
xTitleTextBox,
xNumPaperTextBox,
xNumHardTextBox,
xCostPaperTextBox,
xCostHardTextBox
10
Click
Click
None
None
Pseudocode:
xCalcButton:
Calculate paperback value = number of paperback versions * paperback cost
Calculate hardcover value = number of hardcover versions * hardcover cost
Calculate total number of paperback and hardcover versions = number of
paperback versions + number of hardcover versions
Calculate total value of paperback and hardcover versions = paperback value +
hardcover value
Display paperback value, hardcover value, total number of paperback and
hardcover versions, and total value of paperback and hardcover versions in
xPaperValLabel, xHardValLabel, xTotalNumLabel, and xTotalValLabel controls
xClearButton:
Clear the Text property of the xTitleTextBox, xNumPaperTextBox, xNumHardTextBox,
xCostPaperTextBox, and xCostHardTextBox controls
Clear the Text property of the xPaperValLabel, xHardValLabel, xTotalNumLabel, and
xTotalValLabel controls
Send the focus to the xTitleTextBox control
xExitButton:
End the application
7.
See the VB2005\Chap02\lcJackets Solution files on the Solutions Disk. (The interface might contain a Clear
button.)
Answers using first set of test data: 12.50 discount and 37.50 new price
Answers using second set of test data: 0.00 discount and 0.00 new price
Task
1. Calculate the discount and the new price
2. Display the discount and the new price in the
xDiscountLabel and xNewPriceLabel
controls
End the application
Display the discount and new price (from
xCalcButton)
Get and display the original price
Pseudocode:
xCalcButton:
xExitButton:
8.
Object
xCalcButton
Event
Click
xExitButton
xDiscountLabel,
xNewPriceLabel
xOrigPriceTextBox
Click
None
None
Calculate discount = original price * 25%
Calculate new price = original price – discount
Display the discount in the xDiscountLabel control
Display the new price in the xNewPriceLabel control
Send the focus to the xOrigPriceTextBox control
End the application
See the VB2005\Chap02\lcTypingSalon Solution files on the Solutions Disk. (The interface might not contain
a Clear button.)
Answers using first set of test data: $75.00 total due
Answers using second set of test data: $0.00 total due
Task
1. Calculate the total due
2. Display the total due in the xTotalLabel
control
Clear the screen
End the application
Display the total due (from xCalcButton)
Get and display the name, number of typed
envelopes, and number of typed pages
Object
xCalcButton
Event
Click
xClearButton
xExitButton
xTotalLabel
xNameTextBox,
xEnvelopesTextBox,
Click
Click
None
None
Programming with VB 2005 3E
0-4188-3674-5
11
xPagesTextBox
Programming with VB 2005 3E
0-4188-3674-5
12
Pseudocode:
xCalcButton:
Calculate total due = number of typed envelopes * .10 +
number of typed pages * .25
Display the total due in the xTotalLabel control
xClearButton:
Clear the Text property of the xNameTextBox, xEnvelopesTextBox, and xPagesTextBox
controls
Clear the Text property of the xTotalLabel control
Send the focus to the xNameTextBox control
xExitButton:
End the application
Programming with VB 2005 3E
0-4188-3674-5
13
9.
See the VB2005\Chap02\lcSun Solution files on the Solutions Disk. (The interface might not contain a Clear
button.)
Answers using first set of test data: 480.00 gross, 96.00 FWT, 38.40 FICA, 9.60 state tax, 336.00 net
Answers using second set of test data: 0.00 gross, 0.00 FWT, 0.00 FICA, 0.00 state tax, 0.00 net
Task
1. Calculate gross pay, FWT, FICA, state tax,
and net pay
2. Display the calculated amounts in the
xGrossLabel, xFwtLabel, xFicaLabel,
xStateLabel, and xNetLabel controls
Clear the screen
End the application
Display the gross pay, FWT, FICA, state tax, and
net pay (from xCalcButton)
Get and display the name, hours worked, and rate
of pay
Pseudocode:
xCalcButton:
Object
xCalcButton
Event
Click
xClearButton
xExitButton
xGrossLabel,
xFwtLabel, xFicaLabel,
xStateLabel, xNetLabel
xNameTextBox,
xHoursTextBox,
xRateTextBox
Click
Click
None
None
Calculate the gross pay = hours worked * rate of pay
Calculate the FWT = gross pay * 20%
Calculate the FICA = gross pay * 8%
Calculate the state tax = gross pay * 2%
Calculate the net pay = gross pay – FWT – FICA – state tax
Display the gross pay in the xGrossLabel control
Display the FWT in the xFwtLabel control
Display the FICA in the xFicaLabel control
Display the state tax in the xStateLabel control
Display the net pay in the xNetLabel control
xClearButton:
Clear the Text property of the xNameTextBox, xHoursTextBox, and xRateTextBox controls
Clear the Text property of the xGrossLabel, xFwtLabel, xFicaLabel, xStateLabel, and xNetLabel
controls
Send the focus to the xNameTextBox control
xExitButton:
End the application
10. See the VB2005\Chap02\lcModified Skate Away Solution files on the Solutions Disk.
11. (Discovery) See the VB2005\Chap02\lcDiscovery Skate Away Solution files on the Solutions Disk.
12. (Discovery) See the VB2005\Chap02\lcColfax Solution files on the Solutions Disk. (The interface might
contain a Clear button.) Answer using test data: 7 full boxes and 3 remaining
Task
1. Calculate the number of full boxes and the
number remaining
2. Display the number of full boxes and the
number remaining in the xFullLabel and
xRemainLabel controls
End the application
Display the number of full boxes and the number
remaining (from xCalcButton)
Get and display the inventory quantity and the
number that can be packed in a box
Object
xCalcButton
Event
Click
xExitButton
xFullLabel,
xRemainLabel
xQuantityTextBox,
xBoxTextBox
Click
None
Programming with VB 2005 3E
0-4188-3674-5
14
None
Pseudocode:
xCalcButton:
xExitButton:
Calculate the number of full boxes = inventory quantity \ number that can be
packed in a box
Calculate the number remaining = inventory quantity Mod number that can be
packed in a box (Note: the student also could use the following
equation: inventory quantity – number of full boxes * number that can be packed in a
box)
Display the number of full boxes in the xFullLabel control
Display the number remaining in the xRemainLabel control
Send the focus to the xQuantityTextBox control
End the application
13. (Debugging) See the VB2005\Chap02\lcDebug Skate Away Solution files on the Solutions Disk.
Programming with VB 2005 3E
0-4188-3674-5
15
Chapter 3 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
d
a
c
d
d
b
d
a
d
b
Both b and c.
literal constant
Object
Private
Static score As Integer
Dim city As String
Double.TryParse(Me.xSalesTextBox.Text, sales)
Const Rate As Double = .09
None of the above.
Option Strict On
Exercises
In Exercises 1 through 4, the variable’s name and data type may vary.
1. Dim itemName As String
Dim price As Decimal
2. Dim item As String
Dim height As Decimal
Dim weight As Integer
3. Dim item As String
Dim beginStock As Integer
Dim purchased As Integer
Dim sold As Integer
Dim endStock As Integer
4. Private partNumber As String
Private cost As Decimal
5. city = “Miami”
6. itemName = “Desk”
quantityInStock = 40
quantityOnOrder = 20
7. totalSales = northSales + southSales
8. salary = salary * 1.5D
9. Private employeeName As String
The statement should be entered in the form’s Declarations section. The variable is a module-level variable.
10. Const TaxRate As Decimal = .05D
11. Integer.TryParse(Me.xUnitsTextBox.Text, numberOfUnits)
12. Me.xUnitsLabel.Text = Convert.ToString(numberOfUnits)
13. totalSales = Convert.ToString(westSales + eastSales)
14. (Discovery) See the VB2005\Chap03\laScope Solution files on the Solutions Disk.
c. The number 500 appears in the xSalesLabel control. The procedure-level sales variable is removed from
memory.
h. The number zero appears because the assignment statement in the xComm5Button’s Click event
procedure multiplies the contents of the sales variable (0) by .05, and then displays the result (0) in the
xCommissionLabel control. When the xComm5Button’s Click event procedure ends, the sales variable
declared in the procedure is removed from memory.
q. When the application ends, the module-level sales variable is removed from memory.
15. (Debugging) See the VB2005\Chap03\laCount Solution files on the Solutions Disk.
f. You can use either a module-level variable or a static variable. The static variable is the preferred way.
Chapter 3 – Lesson B
Programming with VB 2005 3E
0-4188-3674-5
16
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
d
d
a
c
c
a
a
c
b
b
All of the above.
&
Me.xRegionLabel.Text = region1 & region2
Me.xAddressLabel.Text = cityName & “, ” & stateName
ControlChars.NewLine
AcceptButton
Double.TryParse(InputBox(“Enter a number:”, “Number”), number)
cityName = Inputbox(“Enter the city:”, “City”)
sentence capitalization
Me.xSalesLabel.Text = sales.ToString(“N2”)
Exercises
1.
2.
3.
4.
5.
6.
7.
8.
See the VB2005\Chap03\lbModified Skate Away Solution files on the Solutions Disk.
See the VB2005\Chap03\lbCommission Solution files on the Solutions Disk.
See the VB2005\Chap03\lbMingo Solution files on the Solutions Disk.
See the VB2005\Chap03\lbModified Mingo Solution files on the Solutions Disk.
See the VB2005\Chap03\lbIMY Solution files on the Solutions Disk.
See the VB2005\Chap03\lbModified IMY Solution files on the Solutions Disk.
Me.xAddressLabel.Text = cityName & “, ” & stateName
Me.xAddressLabel.Text = Message & “ ” & stateName & “ is ” & cityName &
“.”
9. Me.xAddressLabel.Text = “My ZIP code is ” & zipCode & “.”
10. (Discovery) See the VB2005\Chap03\lbCancel Solution files on the Solutions Disk.
Chapter 3 – Lesson C
Questions
1.
2.
3.
4.
b static
d Static counter as Integer
d TextChanged
a Private Sub GetNumber(ByVal sender As Object, ByVal e As
System.EventArgs) Handles xNum1TextBox.Click, xNum2TextBox.Click
Exercises
1.
2.
3.
4.
5.
6.
See the VB2005\Chap03\lcName Solution files on the Solutions Disk.
See the VB2005\Chap03\lcPennies Solution files on the Solutions Disk.
See the VB2005\Chap03\lcChange Solution files on the Solutions Disk.
See the VB2005\Chap03\lcCurrency Calculator Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap03\lcConversion Functions Solution files on the Solutions Disk. The
TryParse method can handle invalid data (such as a letter), whereas the conversion functions cannot.
(Debugging) See the VB2005\Chap03\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student must include parentheses around the test1 + test2 + test3 expression.
Programming with VB 2005 3E
0-4188-3674-5
17
Chapter 4 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
d
b
d
4
2
1
3
2
3
1
3
2
b
a
b
b
a
a
c
d
b
b
only the false path in the If…Then…Else statement
cost > 100 AndAlso cost <= 1000
Me.xNameTextBox.Text.ToUpper = “BOB”
Xor
And
Not
Or
AndAlso
OrElse
Arithmetic
Logical
Comparison
False
True
False
False
True
True
180
3000
True
True
Programming with VB 2005 3E
0-4188-3674-5
18
Exercises
1.
start
F
if hours
> 40
T
display
“Overtime pay”
display
“Regular pay”
stop
2.
3.
4.
5.
6.
7.
8.
If Me.xCarTextBox.Text.ToUpper = “GRAND AM” Then
Me.xCarMakeLabel.Text = “Pontiac”
End If
If String.IsNullOrEmpty(Me.xZipTextBox.Text) Then
Me.xMsgLabel.Text = “Please enter your ZIP code”
End If
If isSalesOk Then
Me.xMsgLabel.Text = Convert.ToString(sales * .1)
Else
Me.xMsgLabel.Text = “Please enter a number”
End If
If units < 0 Then
Me.xMessageLabel.Text = “Entry error”
Else
Me.xMessageLabel.Text = “Valid Number”
End If
If quantity < 10 Then
Me.xMessageLabel.Text = “Reorder”
Else
Me.xMessageLabel.Text = “OK”
End If
If sales <= 250 Then
bonus = 10
Else
bonus = 15
End If
If state.ToUpper = “HAWAII” Then
Me.xShippingLabel.Text = “25”
Else
Me.xShippingLabel.Text = “50”
Programming with VB 2005 3E
0-4188-3674-5
19
End If
Programming with VB 2005 3E
0-4188-3674-5
20
9.
start
F
if state is
Colorado
T
display sales *
.03
display sales *
.04
stop
If state.ToUpper = “COLORADO” Then
Me.xSalesTaxLabel.Text = Convert.ToString(.03 * sales)
Else
Me.xSalesTaxLabel.Text = Convert.ToString(.04 * sales)
End If
10. if the hours worked are greater than 40
calculate gross pay = hours worked * pay rate + (hours worked - 40) * pay rate/2
else
calculate gross pay = hours worked * pay rate
end if
display the gross pay
If hours > 40D Then
gross = hours * hourRate + (hours – 40D) * hourRate/2D
Else
gross = hours * hourRate
End If
Me.xGrossLabel.Text = Convert.ToString(gross)
Programming with VB 2005 3E
0-4188-3674-5
21
11.
start
F
if animal
is “D”
T
display “Dog”
display “Cat”
stop
If animal.ToUpper = “D” Then
Me.xAnimalLabel.Text = “Dog”
Else
Me.xAnimalLabel.Text = “Cat”
End If
12. if the item is a desk and the state is Colorado
calculate discount = sales * .1
display discount
end if
If item.ToUpper = “DESK” AndAlso state.ToUpper = “COLORADO” Then
discount = sales * .1
Me.xDiscountLabel.Text = discount.ToString(“C2”)
End If
13. If itemColor.ToUpper = “RED” AndAlso item.ToUpper = “SHIRT” Then
increase = .02D * origPrice
Else
increase = .01D * origPrice
End If
newPrice = origPrice + increase
Me.xOriginalLabel.Text = origPrice.ToString(“N2”)
Me.xIncreaseLabel.Text = increase.ToString(“N2”)
Me.xNewLabel.Text = newPrice.ToString(“N2”)
14. If marySales < jeffSales Then
Dim temp As Decimal
temp = marySales
marySales = jeffSales
jeffSales = temp
End If
15. See the VB2005\Chap04\laModified AddSub Solution files on the Solutions Disk.
Programming with VB 2005 3E
0-4188-3674-5
22
16. See the VB2005\Chap04\laBonus Solution files on the Solutions Disk.
17. See the VB2005\Chap04\laSum Solution files on the Solutions Disk.
18. (Discovery) See the VB2005\Chap04\laCharCase Solution files on the Solutions Disk.
Chapter 4 – Lesson B
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
a
c
d
b
b
c
c
a
d
a
When you delete a group box, the controls contained within the group box remain on the form.
5.0
All of the above.
Financial.Pmt(.09/4, 3 * 4, 6000, 0, DueDate.BegOfPeriod)
-Financial.Pmt(.03/12, 120, 0, 50000, DueDate.BegOfPeriod)
icon
MessageBoxIcon.Exclamation
an OK button and the Information Message icon
None of the above.
Windows.Forms.DialogResult.OK
Exercises
1.
2.
3.
See the VB2005\Chap04\lbWeekly Savings Solution files on the Solutions Disk.
See the VB2005\Chap04\lbMingo Solution files on the Solutions Disk.
(Discovery)
c. In addition to the MessageBoxIcon.Exclamation constant, the MessageBoxIcon.Warning
constant displays the Warning Message icon.
d. The MessageBoxIcon.Asterisk and MessageBoxIcon.Information constants display the
Information Message icon.
e. The MessageBoxIcon.Error, MessageBoxIcon.Hand, and MessageBoxIcon.Stop
constants display the Stop Message icon.
f. The MessageBoxIcon.Question constant displays a symbol consisting of a question mark in a circle.
Chapter 4 – Lesson C
Questions
1.
2.
3.
4.
5.
6.
b
c
d
b
b
a
KeyPress
e.Handled = True
If e.KeyChar = ControlChars.Back Then
If e.KeyChar = “$” Then
Enter
Me.xCityTextBox.SelectAll()
Exercises
1.
2.
3.
4.
5.
6.
7.
8.
9.
See the VB2005\Chap04\lcMicro Solution files on the Solutions Disk.
See the VB2005\Chap04\lcState ID Solution files on the Solutions Disk.
See the VB2005\Chap04\lcAllenton Solution files on the Solutions Disk.
See the VB2005\Chap04\lcSkate Away Solution – Ex4 files on the Solutions Disk.
See the VB2005\Chap04\lcSkate Away Solution – Ex5 files on the Solutions Disk.
See the VB2005\Chap04\lcMessageBox Value Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap04\lcDiscovery Bonus Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap04\lcZip Solution files on the Solutions Disk. (The student will need to set
the text box control’s MaxLength property.)
(Debugging) See the VB2005\Chap04\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student must include parentheses around e.KeyChar < "0" OrElse e.KeyChar > "9" in the
Programming with VB 2005 3E
0-4188-3674-5
23
CancelKeys procedure, and also around code = “1” OrElse code = “2” in the xCalcButton Click
event procedure.
Programming with VB 2005 3E
0-4188-3674-5
24
Chapter 5 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
c 180
d 3000
b 200
c Mark
b Jerry
c Mark
d Sue
c either the true path or the false path
d All of the above.
b Mark
b Mark
d Sue
a If sender Is Me.xNameTextBox Then
d If TypeOf sender Is Label Then
a If partNum Like “??#” Then
a If item.ToUpper = “SHIRT” OrElse item.ToUpper = “SKIRT” Then
c If Me.xRateTextBox.Text Like “*%” Then
The decision regarding the member status is the primary decision. The decision regarding the day of the week
is the secondary decision, because whether it needs to be made depends on the result of the member status
decision.
19. The three errors commonly made when writing selection structures are:
1. Using a logical operator when a nested selection structure is needed
2. Reversing the primary and secondary decisions
3. Using an unnecessary nested selection structure
The “Using an unnecessary nested selection structure” error makes the selection structure inefficient, but not
incorrect.
20. Desk-checking, also called hand-tracing, means that you use sample data to walk through each of the steps in
the algorithm manually, just as though you were the computer.
Programming with VB 2005 3E
0-4188-3674-5
25
Exercises
1.
2.
3.
4.
5.
6.
Dim code As String
Dim sales As Decimal
Dim bonus As Decimal
code = Me.xCodeTextBox.Text
Decimal.TryParse(Me.xSalesTextBox.Text, sales)
bonus = sales * .08D
If code.ToUpper = “X” Then
If sales >= 10000 Then
bonus = bonus + 150D
Else
bonus = bonus + 125D
End If
End If
Me.xMsgLabel.Text = bonus.ToString(“N2”)
If score >= 90 Then
Me.xMsgLabel.Text = "Highest honors"
ElseIf score >= 70 Then
Me.xMsgLabel.Text = “Good job”
Else
Me.xMsgLabel.Text = "Retake the test"
End If
If quantity = 10 Then
Me.xMsgLabel.Text = “Equal”
ElseIf quantity > 10 Then
Me.xMsgLabel.Text = “Over 10”
Else
Me.xMsgLabel.Text = “Not over 10”
End If
Integer.TryParse(Me.xCodeTextBox.Text, code)
Decimal.TryParse(Me.xSalesTextBox.Text, sales)
If code = 1 OrElse code = 2 Then
Me.xMsgLabel.Text = Convert.ToString(sales * .12D)
ElseIf code = 3 Then
Me.xMsgLabel.Text = Convert.ToString(sales * .15D)
ElseIf code = 4 Then
Me.xMsgLabel.Text = Convert.ToString(sales * .2D)
Else
Me.xMsgLabel.Text = “Error”
End If
Integer.TryParse(Me.xCodeTextBox.Text, code)
Decimal.TryParse(Me.xSalesTextBox.Text, sales)
Select Case code
Case 1
Me.xMsgLabel.Text = Convert.ToString(sales *
Case 2 To 4
Me.xMsgLabel.Text = Convert.ToString(sales *
Case 5
Me.xMsgLabel.Text = Convert.ToString(sales *
Case 6 To 7
Me.xMsgLabel.Text = Convert.ToString(sales *
Case Else
Me.xMsgLabel.Text = “Error”
End Select
Select Case state
Case “HAWAII”
shipCharge = 25.0
Programming with VB 2005 3E
0-4188-3674-5
26
.02D)
.05D)
.1D)
.15D)
Case “OREGON”
shipCharge = 30.0
Case “CALIFORNIA”
shipCharge = 32.5
Case Else
shipCharge = 0.0
Me.xMsgLabel.Text = “Incorrect state”
End Select
7. If state = “HAWAII” Then
shipCharge = 25.0
ElseIf state = “OREGON” Then
shipCharge = 30.0
ElseIf state = “CALIFORNIA” Then
shipCharge = 32.5
Else
shipCharge = 0.0
Me.xMsgLabel.Text = “Incorrect state”
End If
8. Select Case seatLoc
Case “BOX”
Me.xPriceLabel.Text = “$75.00”
Case “PAVILION”
Me.xPriceLabel.Text = “$30.00”
Case “LAWN”
Me.xPriceLabel.Text = “$21.00”
Case Else
Me.xPriceLabel.Text = “Incorrect seat location”
End Select
9. If seatLoc = “BOX” Then
Me.xPriceLabel.Text = “$75.00”
ElseIf seatLoc = “PAVILION” Then
Me.xPriceLabel.Text = “$30.00”
ElseIf seatLoc = “LAWN” Then
Me.xPriceLabel.Text = “$21.00”
Else
Me.xPriceLabel.Text = “Incorrect seat location”
End If
10. If zipCode Like “605##” Then
shipCharge = 25.0
ElseIf zipCode Like “606##” Then
shipCharge = 30.0
Else
shipCharge = 35.0
End If
11. Select Case True
Case zipCode Like “605##”
shipCharge = 25.0
Case zipCode Like “606##”
shipCharge = 30.0
Case Else
shipCharge = 35.0
End Select
12. If sender Is xAlabamaButton Then
Me.xCapitalLabel.Text = “Montgomery”
ElseIf sender Is xArizonaButton Then
Me.xCapitalLabel.Text = “Phoenix”
ElseIf sender Is xIllinoisButton Then
Me.xCapitalLabel.Text = “Springfield”
Else
Programming with VB 2005 3E
0-4188-3674-5
27
13.
14.
15.
16.
17.
Me.xCapitalLabel.Text = “Salem”
End If
Select Case True
Case sender Is xAlabamaButton
Me.xCapitalLabel.Text = “Montgomery”
Case sender Is xArizonaButton
Me.xCapitalLabel.Text = “Phoenix”
Case sender Is xIllinoisButton
Me.xCapitalLabel.Text = “Springfield”
Case Else
Me.xCapitalLabel.Text = “Salem”
End Select
See the VB2005\Chap05\laAnimal Solution files on the Solutions Disk.
See the VB2005\Chap05\laMonth Solution files on the Solutions Disk.
See the VB2005\Chap05\laBonus Solution files on the Solutions Disk.
See the VB2005\Chap05\laSeminar Solution files on the Solutions Disk.
Chapter 5 – Lesson B
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
b
b
b
b
d
a
c
b
a
d
two
sentence capitalization
False
two
six
Checked
Dim numberRandom As New Random
number = randomGenerator.Next(1, 26)
Call
Me.xAlaskaRadioButton.PerformClick()
Exercises
1.
2.
3.
4.
5.
See the VB2005\Chap05\lbMath Solution-PerformClick files on the Solutions Disk.
See the VB2005\Chap05\lbCapitals Solution files on the Solutions Disk.
See the VB2005\Chap05\lbJuarez Solution files on the Solutions Disk.
See the VB2005\Chap05\lbFat Calculator Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap05\lbRandom Float Solution files on the Solutions Disk.
Chapter 5 – Lesson C
Questions
1.
2.
3.
4.
d
a
a
b
None of the above.
Checked
True
False
Exercises
1.
2.
3.
4.
5.
6.
7.
See the VB2005\Chap05\lcModified Math Solution files on the Solutions Disk.
See the VB2005\Chap05\lcHealth Solution files on the Solutions Disk.
See the VB2005\Chap05\lcWashington Solution files on the Solutions Disk.
See the VB2005\Chap05\lcBarren Solution files on the Solutions Disk.
See the VB2005\Chap05\lcGolf Pro Solution files on the Solutions Disk.
See the VB2005\Chap05\lcMarshall Solution files on the Solutions Disk.
See the VB2005\Chap05\lcWillow Solution files on the Solutions Disk.
Programming with VB 2005 3E
0-4188-3674-5
28
8.
9.
10.
11.
See the VB2005\Chap05\lcJohnson Solution files on the Solutions Disk.
See the VB2005\Chap05\lcLottery Solution files on the Solutions Disk.
See the VB2005\Chap05\lcFerris Solution files on the Solutions Disk.
(Debugging) See the VB2005\Chap05\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student must modify the Select Case statement as follows:
Select Case total
Case Is < 100.0
shipping = 0
Case Is < 501.0
shipping = 10
Case Is < 1001.0
shipping = 7
Case Else
shipping = 5
End Select
Programming with VB 2005 3E
0-4188-3674-5
29
Chapter 6 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
b
c
c
a
d
a
b
a
a
a
a
c
4
12
either a or b
posttest, pretest
All of the above.
0
1
(sequence) and b (selection)
(sequence) and c (repetition)
(sequence) and b (selection)
(sequence) and b (selection) and c (repetition)
priming
Exercises
Do While quantity > 0
Do Until quantity <= 0
Do Until inStock <= reorder
Do While inStock > reorder
Do While letter.ToUpper = “Y”
Do Until letter.ToUpper <> “Y”
Do While empName.ToUpper <> “DONE”
Do Until empName.ToUpper = “DONE”
quantity = quantity + 2
total = total – 3
totalPurchases = totalPurchases + purchases
sales = sales – salesReturns
For evenNum = 2 To 8 Step 2
Me.xNumbersLabel.Text = _
Me.xNumbersLabel.Text & Convert.ToString(evenNum)
ControlChars.NewLine
Next evenNum
14. Dim evenNum As Integer = 2
Do While evenNum <= 8
Me.xNumbersLabel.Text = _
Me.xNumbersLabel.Text & Convert.ToString(evenNum)
ControlChars.NewLine
evenNum = evenNum + 2
Loop
15. Dim evenNum As Integer = 2
Do
Me.xNumbersLabel.Text = _
Me.xNumbersLabel.Text & Convert.ToString(evenNum)
ControlChars.NewLine
evenNum = evenNum + 2
Loop While evenNum <= 8
16. Dim count As Integer = 10
Do While count < 100
Me.xCountLabel.Text = _
Me.xCountLabel.Text & Convert.ToString(count * 2)
ControlChars.NewLine
count = count + 10
Loop
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Programming with VB 2005 3E
0-4188-3674-5
30
& _
& _
& _
& _
17. For x = 0 To 117 Step 9
Me.xNumbersLabel.Text = _
Me.xNumbersLabel.Text & Convert.ToString(x) & _
ControlChars.NewLine
Next x
18. For x = 2 To 12 Step 2
Me.xiNumbersLabel.Text = _
Me.xNumbersLabel.Text & Convert.ToString(x * x) & _
ControlChars.NewLine
Next x
19. 0, 1,2, 3, 4
20. 0, 1, 2, 3, 4, 5
21. The number = number + 1 instruction is missing and should be entered after the MessageBox.Show
instruction.
22. The number = number - 1 instruction is missing and should be entered after the MessageBox.Show
instruction.
23. 0, 2, 4
24. 1
25. See the VB2005\Chap06\laModified Payment Calculator Solution files on the Solutions Disk.
26. See the VB2005\Chap06\laModified Sales Express Solution files on the Solutions Disk.
27. (Debugging) The salesInput = InputBox(“Enter a sales amount”, “Sales) instruction
is missing and should be entered after the MessageBox.Show instruction.
28. (Debugging) The MessageBox.Show instruction should be entered after the Do instruction.
Chapter 6 – Lesson B
Questions
1.
a
2.
d
***
***
30
Exercises
1.
2.
3.
See the VB2005\Chap06\lbNested Payment Solution-Ex1 files on the Solutions Disk.
See the VB2005\Chap06\lbNested Payment Solution-Ex2 files on the Solutions Disk.
See the VB2005\Chap06\lbGrade Calculator Solution files on the Solutions Disk.
Chapter 6 – Lesson C
Questions
1.
2.
3.
4.
5.
a
a
b
d
c
Add
Items
SelectedIndex
both a and c
SelectedValueChanged
Exercises
1. See the VB2005\Chap06\lcModified Shoppers Haven Solution files on the Solutions Disk.
2. See the VB2005\Chap06\lcPowder Solution files on the Solutions Disk.
3. See the VB2005\Chap06\lcRandom Solution files on the Solutions Disk.
4. See the VB2005\Chap06\lcPhone Solution files on the Solutions Disk.
5. See the VB2005\Chap06\lcModified Phone Solution files on the Solutions Disk.
6. See the VB2005\Chap06\lcFibonacci Solution files on the Solutions Disk.
7. See the VB2005\Chap06\lcMultiplication Solution files on the Solutions Disk.
Programming with VB 2005 3E
31
0-4188-3674-5
8.
9.
10.
11.
12.
13.
See the VB2005\Chap06\lcGPA Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap06\lcMulti Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap06\lcItems Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap06\lcListBox Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap06\lcSonheim Solution files on the Solutions Disk.
(Debugging) See the VB2005\Chap06\lcDebug Solution files on the Solutions Disk. Modifications are
shaded in the following code.
Private Sub xEnterButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles xEnterButton.Click
' displays the number of positive integers, the number of negative integers,
' and the number of zeros entered
Dim
Dim
Dim
Dim
Dim
Dim
inputNumber As String
number As Integer
positiveCounter As Integer
negativeCounter As Integer
zeroCounter As Integer
isConverted As Boolean
inputNumber = InputBox("Enter an integer. Click Cancel to end. ", _
"Number Entry", "0")
Do While inputNumber <> String.Empty
isConverted = Integer.TryParse(inputNumber, number)
If isConverted Then
' update appropriate counter
If number > 0 Then
positiveCounter = positiveCounter + 1
ElseIf number < 0 Then
negativeCounter = negativeCounter + 1
Else
zeroCounter = zeroCounter + 1
End If
Else
MessageBox.Show("Please enter a number", "Number Entry", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
inputNumber = InputBox("Enter an integer. Click Cancel to end. ", _
"Number Entry", "0")
Loop
' display counters
Me.xPositiveLabel.Text = Convert.ToString(positiveCounter)
Me.xNegativeLabel.Text = Convert.ToString(negativeCounter)
Me.xZeroLabel.Text = Convert.ToString(zeroCounter)
End Sub
Programming with VB 2005 3E
0-4188-3674-5
32
Chapter 7 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
a A Function procedure can return one or more values to the statement that called it.
a arguments
c a parameter
b the procedure header
a Call CalcArea(length, width)
d None of the above.
c Private Sub CalcFee(ByVal base As Integer, ByVal rate As Decimal)
a one value only
d All of the above.
c The name of each argument in the Call statement should be identical to the name of its corresponding
parameter in the procedure header.
a Return stateTax
c Private Sub CalcFee(ByVal base As Integer, ByRef rate As Decimal)
d Both a and c.
c by reference
d To pass a variable by reference in Visual Basic, you include the ByRef keyword before the variable’s
name in the Call statement.
a Private Sub CalcEndingInventory(ByVal b As Integer, ByVal s As
Integer, ByVal p As Integer, ByRef final As Integer)
a Call CalcEndingInventory(begin, sales, purchases, ending)
a True
d All of the above.
c grossPay = Calculate(hours, rate)
Unlike a Sub procedure, a Function procedure returns a value when it has completed its task.
When you pass a variable by value, you are passing only the contents of the variable; the receiving procedure
cannot access the variable and cannot change its contents. When you pass a variable by reference, you are
passing the address of the variable in the computer’s internal memory; the receiving procedure can access the
variable and can change its contents. To pass a variable by value, you include the keyword ByVal before the
variable’s name in the procedure header. To pass a variable by reference, you include the keyword ByRef
before the variable’s name in the procedure header.
Exercises
Private Sub HalveNumber(ByVal num As Integer)
Me.xNumLabel.Text = Convert.ToString(num / 2)
End Sub
2. Call HalveNumber(87)
3. Private Sub GetCity(ByRef cityName As String)
cityName = InputBox(“Enter the city name:”, “City Name”)
End Sub
4. Call GetCity(city)
5. Private Sub CalcSumAndDiff(ByVal num1 As Integer, ByVal num2 As Integer,
ByRef sum As Integer, ByRef diff As Integer)
sum = num1 + num2
diff = num1 – num2
End Sub
6. Call CalcSumAndDiff(firstNum, secondNum, sum, difference)
7. Private Sub CalcQuotient(ByVal num1 As Decimal, ByVal num2 As Decimal,
ByRef quotient As Decimal)
quotient = num1 / num2
End Sub
8. Private Function DivideNumber(ByVal num As Integer) As Double
Return num / 2
Programming with VB 2005 3E
33
0-4188-3674-5
1.
End Function
9. answer = DivideNumber(number)
10. Private Function GetState() As String
Dim state As String
state = InputBox(“State name:”, “State Name”)
Return state
End Function
11. MessageBox.Show(GetState())
12. Private Function CalcAverage(ByVal number1 As Integer, ByVal number2 As
Integer, ByVal number3 As Integer, ByVal number4 As Integer) As Decimal
Return (number1 + number2 + number3 + number4) / 4
End Function
13. average = CalcAverage(num1, num2, num3, num4)
14. See the VB2005\Chap07\laPassing Solution files on the Solutions Disk. In Step c, the xDisplayButton’s Click
event procedure does not display your name because the myName variable was passed by value. In Step e, the
xDisplayButton’s Click event procedure displays your name because the myName variable was passed by
reference.
15. See the VB2005\Chap07\laRainfall Solution files on the Solutions Disk.
16. See the VB2005\Chap07\laModified Gross Pay Solution files on the Solutions Disk.
17. See the VB2005\Chap07\laModified Pine Lodge Solution files on the Solutions Disk.
18. See the VB2005\Chap07\laModified Rainfall Solution files on the Solutions Disk.
19. See the VB2005\Chap07\laTemperature Solution files on the Solutions Disk.
20. See the VB2005\Chap07\laModified Temperature Solution files on the Solutions Disk.
21. (Discovery) See the VB2005\Chap07\laOptional Solution files on the Solutions Disk.
Chapter 7 – Lesson B
Questions
1.
2.
3.
4.
5.
6.
7.
8.
a
b
a
d
c
b
d
d
Add
DropDownStyle
Items
All of the above.
Text
Math.Round(number, 3)
Sorted
TextChanged
Exercises
1.
2.
3.
See the VB2005\Chap07\lbSub Harvey Industries Solution files on the Solutions Disk.
See the VB2005\Chap07\lbModified Harvey Industries Solution files on the Solutions Disk.
See the VB2005\Chap07\lbNo Rounding Harvey Industries Solution files on the Solutions Disk.
Chapter 7 – Lesson C
Questions
1.
2.
3.
d
d
c
FormClosing
FormClosing
e.Cancel = True
Exercises
1.
2.
3.
See the VB2005\Chap07\lcFormClosing Gross Pay Solution.
See the VB2005\Chap07\lcFormClosing Pine Lodge Solution files on the Solutions Disk.
(Debugging) See the VB2005\Chap07\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student must add the statement Return result to the GetArea function.
Programming with VB 2005 3E
0-4188-3674-5
34
Chapter 8 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
d
a
a
c
d
c
d
c
d
d
b
c
d
d
c
Both b and c
state = state.Remove(2, 3)
amount = amount.Trim(“$”c, “%”c)
partNum.StartsWith(“A”)
partNum.ToUpper.EndsWith(“B”)
code = partNum.Substring(0, 3)
All of the above.
zip = zip.Replace(“1”, “3”)
All of the above.
None of the above.
word = word.Insert(2, “a”)
10
None of the above.
newMessage = message.PadRight(13, “!”c)
0
Exercises
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
Me.xSizeLabel.Text = Convert.ToString(message.Length)
city = city.TrimStart
number = number.Trim
amount = amount.TrimEnd(“ ”c, “,”c, “.”c)
fullName = fullName.Remove(0, 2)
Mid(word, 4) = “th”
word = word.Insert(0, “a”)
pay = pay.PadLeft(10, “*”c)
inputRate.EndsWith(“%”) Then
inputRate = inputRate.TrimEnd(“%”c)
End If
code = part.Substring(4, 2)
amount = amount.Replace(“,”, “”)
indexNum = address.ToUpper.IndexOf(“ELM STREET”)
isContained = address.ToUpper().Contains(“ELM STREET”)
result = String.Compare(item, itemOrdered)
See the VB2005\Chap08\laCity Names Solution files on the Solutions Disk.
See the VB2005\Chap08\laSocial Security Solution files on the Solutions Disk.
See the VB2005\Chap08\laModified Social Security Solution files on the Solutions Disk.
See the VB2005\Chap08\laPhone Solution files on the Solutions Disk.
See the VB2005\Chap08\laItem Prices Solution files on the Solutions Disk.
See the VB2005\Chap08\laDate Solution files on the Solutions Disk.
See the VB2005\Chap08\laSales Tax Solution files on the Solutions Disk.
See the VB2005\Chap08\laPart Number Solution files on the Solutions Disk.
See the VB2005\Chap08\laCount Solution files on the Solutions Disk.
See the VB2005\Chap08\laName Solution files on the Solutions Disk.
See the VB2005\Chap08\laAlphabet Solution files on the Solutions Disk.
a.
b.
c.
d.
e.
f.
g.
h.
If
Chapter 8 – Lesson B
Programming with VB 2005 3E
0-4188-3674-5
35
Questions
1.
2.
3.
4.
5.
b a separator bar
a an access key
c A shortcut key
c You should assign a shortcut key to commonly used menu titles.
A menu item’s access key can be used only when the menu is open. A menu item’s shortcut key can be used
only when the menu is closed.
Exercises
1.
See the VB2005\Chap08\lbCommission Solution files on the Solutions Disk.
Chapter 8 – Lesson C
Questions
1.
2.
3.
b
d
a
For indexNum As Integer = 0 To name.Length - 1
Mid(name, 1) = “C”
True
Exercises
1.
2.
3.
4.
5.
6.
7.
See the VB2005\Chap08\lcHangman Game Solution-Ex1 files on the Solutions Disk.
See the VB2005\Chap08\lcHangman Game Solution-Ex2 files on the Solutions Disk.
See the VB2005\Chap08\lcPig Latin Solution files on the Solutions Disk.
See the VB2005\Chap08\lcGeorgetown Solution files on the Solutions Disk.
See the VB2005\Chap08\lcJacobson Solution files on the Solutions Disk.
See the VB2005\Chap08\lcBobCat Motors Solution files on the Solutions Disk.
(Debugging) See the VB2005\Chap08\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student must modify the Remove method in the xDisplayButton’s Click event procedure, as shown here:
city = address.Remove(indexNum)
Programming with VB 2005 3E
0-4188-3674-5
36
Chapter 9 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
a
d
b
d
d
a
b
8.
9.
10.
11.
12.
a
c
b
d
d
Dim amounts(4) As Double
Do While x <= 20
replace the 500 amount with 510
If x >= 0 AndAlso x <= 4 Then
None of the above.
Array.Sort(sales)
Do While x < 4
total = total + numbers(x)
x = x + 1
Loop
avg = Convert.ToDecimal(total / x)
0
6
5
8
elements = numbers.Length
Exercises
1.
2.
3.
4.
Dim numbers(19) As Integer
numbers(1) = 7
Private products(9) As String
products(2) = “Paper”
Dim rates As Double = {6.5, 8.3, 4, 2, 10.5}
For x As Integer = 0 To 4
Me.xRatesLabel.Text = Me.xRatesLabel.Text & _
Convert.ToString(rates(x)) & ControlChars.NewLine
Next x
Dim x As Integer
Do While x <= 4
Me.xRatesLabel.Text = Me.xRatesLabel.Text & _
Convert.ToString(rates(x)) & ControlChars.NewLine
x = x + 1
Loop
5.
6.
7.
For Each x As Integer in rates
Me.xRatesLabel.Text = Me.xRatesLabel.Text & _
Convert.ToString(x) & ControlChars.NewLine
Next x
Array.Sort(rates)
Array.Reverse(rates)
For x As Integer = 0 To 4
total = total + rates(x)
Next x
Me.xAverageLabel.Text = Convert.ToString(total / x)
Dim x As Integer
Do While x <= 4
total = total + rates(x)
x = x + 1
Loop
Me.xAverageLabel.Text = Convert.ToString(total / x)
Programming with VB 2005 3E
0-4188-3674-5
37
8.
For Each x As Integer in rates
total = total + x
Next x
Me.xAverageLabel.Text = Convert.ToString(total / rates.length)
Dim x As Integer
Do While x <= 4
rates(x) = rates(x) - 1
x = x + 1
Loop
For x As Integer = 0 To 4
rates(x) = rates(x) - 1
Next x
9.
10.
11.
12.
13.
14.
15.
For Each x As Integer in rates
x = x - 1
Next x
See the VB2005\Chap09\laLowest Solution-ForNext, laLowest Solution-ForEachNext, laLowest SolutionDoLoop files on the Solutions Disk.
See the VB2005\Chap09\laUpdate Prices Solution files on the Solutions Disk.
See the VB2005\Chap09\laModified Update Prices Solution files on the Solutions Disk.
See the VB2005\Chap09\laScores Solution files on the Solutions Disk.
d. 3 students earned a score of 72
4 students earned a score of 88
1 student earned a score of 20
2 students earned a score of 99
See the VB2005\Chap09\laModified Scores Solution files on the Solutions Disk.
d. 6 students earned a score between 70 and 79, inclusive
8 students earned a score between 65 and 85, inclusive
2 students earned a score between 0 and 50, inclusive
See the VB2005\Chap09\laLottery Game Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap09\laReDim Solution files on the Solutions Disk
a. The ReDim statement allows you to reallocate storage space for an array variable. In other words, it
allows you to dynamically change the size of an array. The Preserve keyword allows you to preserve the
data in the existing array when you change the size of only the last dimension.
Chapter 9 – Lesson B
Questions
1.
2.
a
a
True
capital(1)
Exercises
1.
2.
3.
See the VB2005\Chap09\lbCarver Solution files on the Solutions Disk.
See the VB2005\Chap09\lbModified Carver Solution files on the Solutions Disk.
See the VB2005\Chap09\lbLaury Solution files on the Solutions Disk.
Chapter 9 – Lesson C
Questions
1. b Dim letters(3, 1) As String
2. d replace the 800 amount with 810
3. b replace the 2000 amount with 900
4. d If row >= 0 AndAlso row < 2 AndAlso col >= 0 AndAlso col < 5 Then
Programming with VB 2005 3E
38
0-4188-3674-5
5.
6.
d
d
states(4, 2) = “California”
All of the above.
Exercises
1.
2.
3.
4.
5.
6.
7.
8.
9.
Dim balances(3, 5) As Decimal
For row As Integer = 0 To 3
For col As Integer = 0 To 5
balances(row, col) = 10D
Next col
Next row
Dim row As Integer
Dim Col As Integer
Do While row <= 3
Do While col <= 5
balances(row, col) = 10D
col = col + 1
Loop
row = row + 1
Loop
For Each element As Decimal In balances
element = 10D
Next element
answers(2, 0) = True
See the VB2005\Chap09\lcInventory Solution files on the Solutions Disk.
See the VB2005\Chap09\lcConway Solution files on the Solutions Disk.
See the VB2005\Chap09\lcCount Solution files on the Solutions Disk.
See the VB2005\Chap09\lcHighest Solution files on the Solutions Disk.
(Debugging) See the VB2005\Chap09\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student must insert a comma within the parentheses in the Dim statement that declares the names array.
The student also must change the For clause in the For…Next statement to For row As Integer = 0
to 4.
Programming with VB 2005 3E
0-4188-3674-5
39
Chapter 10 – Lesson A
Questions
1.
2.
3.
4.
5.
c
a
b
d
a
Structure
Declarations section
address.street = “Maple”
None of the above.
Dim workers(4) As Employee
Exercises
1.
2.
3.
4.
5.
6.
Structure Book
Public title As String
Public author As String
Public cost As Decimal
End Structure
Private fiction As Book
Structure Tape
Public name As String
Public artist As String
Public songLength As String
Public songNum As Integer
End Structure
Dim blues As Tape
a. Dim homeUse As Computer
b. homeUse.model = “IB-50”
c. homeUse.cost = 2400D
d. Private business(9) As Computer
e. business(0).model = “HPP405”
f. business(0).cost = 3600D
a. Dim school As Friend
b. school.first = Me.xFirstTextBox.Text
c. school.last = Me.xLastTextBox.Text
d. Me.xLastLabel.Text = school.last
e. Me.xFirstLabel.Text = school.first
f. Private home(4) As Friend
g. home(4).first = Me.xFirstTextBox.Text
h. home(4).last = Me.xLastTextBox.Text
See the VB2005\Chap10\laModified Price List Solution-Structure files on the Solutions Disk.
See the VB2005\Chap10\laCarver Solution files on the Solutions Disk.
Chapter 10 – Lesson B
Questions
1.
2.
3.
4.
5.
b My.Computer.FileSystem.WriteAllText(“address.txt”,
Me.xAddressTextBox.Text, False)
d fileContents = My.Computer.FileSystem.ReadAllText(“address.txt”)
c If My.Computer.FileSystem.FileExists(“address.txt”) Then
d All of the above.
c My.Computer.FileSystem.WriteAllText(“msg.txt”, Strings.Space(15),
True)
Programming with VB 2005 3E
0-4188-3674-5
40
Exercises
1.
2.
3.
4.
5.
6.
7.
8.
9.
My.Computer.FileSystem.WriteAllText(“report.txt”, “Employee” &
ControlChars.NewLine & “Name” & ControlChars.NewLine”, False)
My.Computer.FileSystem.WriteAllText(“geography.txt”, capital &
Strings.Space(20) & state & ControlChars.NewLine, False)
text = My.Computer.FileSystem.ReadAllText(“report.txt”)
Me.xReportLabel.Text = My.Computer.FileSystem.ReadAllText(“report.txt”)
If My.Computer.FileSystem.FileExists(“jansales.txt”) Then
Me.xMessageLabel.Text = “File exists”
Else
Me.xMessageLabel.Text = “File does not exist”
End If
See the VB2005\Chap10\lbEmployee List Solution files on the Solutions Disk.
See the VB2005\Chap10\lbMemo Solution files on the Solutions Disk.
See the VB2005\Chap10\lbReport Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap10\lbPay Solution files on the Solutions Disk.
Chapter 10 – Lesson C
Questions
1.
2.
3.
a My.Computer.FileSystem.WriteAllText(“cities.txt”, city &
ControlChars.NewLine, True)
b Me.xCitiesComboBox.Items.Remove(“Paris”)
b My.Computer.FileSystem.DeleteFile(“cities.txt”)
Exercises
1.
2.
3.
4.
5.
6.
7.
8.
See the VB2005\Chap10\lcFriends Solution-Erase files on the Solutions Disk.
See the VB2005\Chap10\lcFriends Solution-ListBox files on the Solutions Disk.
See the VB2005\Chap10\lcGlovers Solution files on the Solutions Disk.
See the VB2005\Chap10\lcFriends Solution-Ignore Case files on the Solutions Disk.
See the VB2005\Chap10\lcFriends Solution-Modified Add files on the Solutions Disk.
See the VB2005\Chap10\lcWKRK Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap10\lcGlovers Solution-Discovery files on the Solutions Disk.
(Debugging) See the VB2005\Chap10\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student will need to change the For clause in the Click event procedures for the xLastButton, xFirstButton,
and xFullButton as follows: For row As Integer = 0 To names.length -1
Programming with VB 2005 3E
0-4188-3674-5
41
Chapter 11 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
d
a
d
a
b
c
c
a
d
c
a
b
c
d
c
c
d
d
c
a
A class is considered an object.
class file whose filename ends with .vb
variables
True
False
SetDate
FirstName
default
item.Price = 45
newPrice = item.CalculateNewPrice()
True
using properties created by Property procedures
Public
None of the above.
signature
a Sub procedure
Both b and c.
Call dog.DisplayBreed()
Set
Get
Exercises
1.
2.
3.
4.
5.
6.
Public Class Book
Public Title As String
Public Author As String
Public Cost As Decimal
End Class
Public Class Tape
Public Name As String
Public Artist As String
Public SongNumber As String
Public Length As String
End Class
Private fiction As Book
fiction = New Book
Dim blues As New Tape
a. Dim homeUse As New Computer
b. homeUse.Model = “IB-50”
c. homeUse.Cost = 2400D
d. newPrice = homeUse.IncreasePrice()
e. Dim companyUse As New Computer(“IBM”, 1236.99D)
Public Class Employee
Private _name As String
Private _salary As Decimal
Public Property EmpName() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Programming with VB 2005 3E
42
0-4188-3674-5
Public Property Salary() As Decimal
Get
Return _salary
End Get
Set(ByVal value As Decimal)
_salary = value
End Set
End Property
Public Sub New()
_name = String.Empty
_salary = 0D
End Sub
7.
Public Sub New(ByVal n As String, ByVal s As Decimal)
EmpName = n
Salary = s
End Sub
End Class
Public Class Employee
Private _name As String
Private _salary As Decimal
Public Property EmpName() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property Salary() As Decimal
Get
Return _salary
End Get
Set(ByVal value As Decimal)
_salary = value
End Set
End Property
Public Sub New()
_name = String.Empty
_salary = 0D
End Sub
Public Sub New(ByVal n As String, ByVal s As Decimal)
EmpName = n
Salary = s
End Sub
Public Function CalculateNewSalary(ByVal percent As Decimal) As
Decimal
Dim newSalary As Decimal
If percent >= 0 Then
newSalary = _salary + _salary _
* (percent / 100D)
Else
newSalary = 0D
Programming with VB 2005 3E
43
0-4188-3674-5
8.
9.
10.
11.
12.
13.
End If
Return newSalary
End Function
End Class
Public ReadOnly Property BonusRate() As Decimal
Get
Return _bonusRate
End Get
End Property
See the VB2005\Chap11\laModified Area Solution files on the Solutions Disk.
See the VB2005\Chap11\laModified Grade Solution files on the Solutions Disk.
See the VB2005\Chap11\laModified Personnel Solution files on the Solutions Disk.
See the VB2005\Chap11\laModified Salary Solution files on the Solutions Disk.
See the VB2005\Chap11\laModified Sweets Solution files on the Solutions Disk.
Chapter 11 – Lesson B
Questions
1. b overloaded
2.
3.
4.
5.
c
a
c
d
Overloads
Inherits Animal
Public Overridable Sub CalcBonus()
Public Overrides Sub CalcBonus()
Exercises
1.
2.
See the VB2005\Chap11\lbModified ABC Solution-Inheritance files on the Solutions Disk.
See the VB2005\Chap11\lbArea Solution-Overloads files on the Solutions Disk.
Chapter 11 – Lesson C
Questions
1.
2.
3.
b
a
b
False
_location = “Unknown”
Capital = capName
Exercises
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
See the VB2005\Chap11\lcModified Kessler Solution files on the Solutions Disk.
See the VB2005\Chap11\lcFence Solution files on the Solutions Disk.
See the VB2005\Chap11\lcPool Solution files on the Solutions Disk.
See the VB2005\Chap11\lcMath Solution files on the Solutions Disk.
See the VB2005\Chap11\lcMayflower Solution files on the Solutions Disk.
See the VB2005\Chap11\lcModified Mayflower Solution files on the Solutions Disk.
See the VB2005\Chap11\lcFranklin Calendars Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap11\lcModified Pool Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap11\lcPennington Solution files on the Solutions Disk.
See the VB2005\Chap11\lcDebug Solution files on the Solutions Disk. To debug the solution, the student will
need to add the Set block in the Id and Price Property procedures. The student will also need to make three
changes in the xCalcButton’s Click event procedure. First, the student will need to change Computer.Price to
computerPurchased.Price. Second, the student will need to change Computer.Id to computerPurchased.Id.
Third, the student will need to change Computer.CalcNewPrice(rate) to
computerPurchased.CalcNewPrice(rate).
Programming with VB 2005 3E
0-4188-3674-5
44
Programming with VB 2005 3E
0-4188-3674-5
45
Chapter 12 – Lesson A
Questions
1.
2.
3.
4.
5.
6.
7.
8.
a
b
d
b
c
d
b
d
foreign key in the child table
binding
TableAdapter
BindingSource object’s Position
MovePrevious()
All of the above are true.
BindingSource
All of the above.
Exercises
1.
2.
3.
4.
5.
See the VB2005\Chap12\laModified Morgan Industries Solution-Labels files on the Solutions Disk.
See the VB2005\Chap12\laCartwright Solution files on the Solutions Disk.
See the VB2005\Chap12\laAddison Playhouse Solution files on the Solutions Disk.
See the VB2005\Chap12\laMorgan Industries Solution-ListBox files on the Solutions Disk.
(Discovery) See the VB2005\Chap12\laMorgan Industries Solution-NoCopy files on the Solutions Disk.
Chapter 12 – Lesson B
Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
d
d
c
b
a
b
d
d
b
b
All of the above.
Structured Query Language
SELECT First, Middle, Last FROM dbo.tblNames
SELECT SocialNum FROM dbo.tblPensionInfo ORDER BY SocialNum DESC
SELECT Id, Name, Status FROM dbo.Worker WHERE Status = ‘A’
SELECT State, Capital, Population FROM dbo.tblState
None of the above.
None of the above.
used in a WHERE clause in a SELECT statement
False
Exercises
1.
2.
3.
4.
See the VB2005\Chap12\lbModified Morgan Industries Solution-DataGrid-Query files on the Solutions Disk.
See the VB2005\Chap12\lbCartwright Solution-Query files on the Solutions Disk.
See the VB2005\Chap12\lbCollege Courses Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap12\lbMorgan Industries Solution-DataGrid-ToolStrip files on the Solutions
Disk.
Chapter 12 – Lesson C
Questions
1.
2.
a
a
recordPtr = Me.tblStateBindingSource.Position
numRecords = Me.ProductDataSet.Products.Count
Exercises
1.
2.
3.
4.
See the VB2005\Chap12\lcTrivia Game Solution-Ex1 files on the Solutions Disk.
See the VB2005\Chap12\lcTrivia Game Solution-Ex2 files on the Solutions Disk.
See the VB2005\Chap12\lcSports Action Solution files on the Solutions Disk.
(Discovery) See the VB2005\Chap12\lcTrivia Game Solution-Disc files on the Solutions Disk.
Programming with VB 2005 3E
0-4188-3674-5
46
5.
6.
(Discovery) See the VB2005\Chap12\lcFiction Bookstore Solution files on the Solutions Disk.
(Debugging) See the VB2005\Chap12\lcDebug Solution files on the Solutions Disk. To debug this solution,
the student will need to change Me.FriendsDataSet to Me.FriendsDataSet.tblFriends in the xFillButton’s Click
event procedure. The student will also need to change Me.TblFriendsBindingSource.MoveLast() to
Me.TblFriendsBindingSource.MoveNext() in the xNextButton’s Click event procedure.
Programming with VB 2005 3E
0-4188-3674-5
47
Download