Gomes_Ch4_KnowledgeCheck_Etc_EventPlanningDocument

advertisement
Brainetics
Knowledge Check Questions
1.
Decimal, Double, and Single are three numeric data types that can contain a decimal
point.
2.
Dim statements for given variables:
a.
b.
c.
d.
e.
f.
3.
Dim strPopulationOfTheUnitedStates As String
Dim decYourWeeklyPay As Decimal
Dim intAge As Integer
Dim decMinimumWage As Decimal
Dim strCity As String
Dim blnTrueFalse As Boolean
Rules for naming variables in Visual Basic 2008:




Variable names must begin with an underscore or a letter.
The variable name can contain letters, numbers and underscores; but it cannot contain other symbols.
No Visual Basic reserved words (they appear in blue in the code) can be used in variable names.
Ideally variable names should reflect the information that they will contain, so that other people will
understand your code more easily.
1. This name would be valid since it follows the rules stated above, however
a radian should be a numeric data type that can contain a decimal, since
radian's are based on Pi (3.14), such as;
_decRadian
The underscore character declares the variable for use throughout a class.
2. This name would be invalid since it does not follow the rules stated
above. This variable needs to be renamed, since it contains a symbol and
only underscores, numbers and letters are allowed. I would use a string
variable, in case the user enters the % symbol as well as a number. Then, I
would convert this variable to an integer, if I needed the code to do
arithmetical operations. I would also add a prefix to signify the data type
to anyone reading the code. This is how I would rename this variable:
strPercentOfSales
3. This name would be valid since it follows the rules stated above.
However, even though underscores are allowed in variable names, for
consistency I would rename this variable without the underscore
characters. I would also add a prefix to signify the data type to anyone
reading the code. This is how I would rename this variable:
strFirstInputValue
4. This name is invalid since it does not follow the rules stated above. This
variable (R743-L56) needs to be renamed, since it contains a dash symbol
and only underscores, numbers and letters are allowed. It should also
contain a prefix have a name that is more intuitive and explanative of the
information it holds. If I had more information about what this variable
represented I would have tried to rename it, but there's not enough
information to make the variable name more descriptive.
5. This name is invalid since it does not follow the rules stated above. This
variable (3BZT477) starts with a number, which is not allowed, and it also
does not give the reader a clue as to what information it contains. It
should also have a prefix for clarity of data type. If I had more information
about what this variable represented I would have tried to rename it, but
there's not enough information to make the variable name more
descriptive.
6. This name appears to be valid since the word "close" does not appear in
blue in the Windows Form Object code (F7), and it meets the other valid
naming criteria. However, for added clarity in reading the code, I would
avoid using the word "close", so as not to confuse it as a part of a btnExit
subroutine [Me.Close()], even though according to the criteria the
following would be correct (prefix added).
strClose
7. This name is invalid since it contains spaces, which are not allowed in
variable names. I would rename this variable as follows (prefix added):
strNameOfClient
4.



Select the first text box that you want the other text boxes to be aligned with (by
clicking left mouse button over that text box).
Select other text boxes that need to be aligned (by clicking the ctrl + left mouse
buttons).
To align with the left edge of the selected text boxes with the left edge of the first
text box selected, use the following drop-down menu: Format → Align → Lefts
5.
Decimal data types are best use for currency amounts.
6.
Hierarchy of operations:
1.
2.
3.
4.
5.
Exponentiation (^) is performed first
Multiplication (*) and division (/) are performed next
Integer division (\) is next
MOD then occurs
Addition (+) and subtraction (-) are performed last
6. Within these five steps, calculations are performed left to right.
Precedence for the order of operations
7.
a.
b.
c.
d.
e.
f.
g.
8.
5 + 8 * 3 +1 = 30
16 / 2 * 4 –3 =
40 – 6 ^ 2 / 3 =
74 Mod 8
9/4+3
2 ^ 3 + (8 +5)
(15 Mod 2) – 1+ 4* (16 \ 5)
Difference Between
A method
A procedure
9.
Dfff btwn
A variable
A literal does not vary and has the same name as the value that will be used in equations
10.
a.
b.
c.
d.
Dim itAge As Integr
Dim dblDiscountRate As Dbl
Constant cstrCollege As String = "CVCC"
Dim strLastName As String
strLastName = 'McNamara'
e. 1.5 * decHourlyPay = decOverTimePayRate
Dim intAge As Integer
Dim dblDiscountRate As Double
11.
This statement sets the focus on the TextBox object txtLastName:
12.
This statement removes the contents of the txtAge TextBox object:
13.
This statement blanks the Text property of the lblEligibilityAge Label object:
14.
This statement converts the String variable strWaistSize to an integer value and places
the interger value in a variable named intWaistSize:
15.
This statement converts the String variable named strHourlyPay to a Decimal value and
places the Decimal value in a variable named decWage:
16.
This statement closes a form that is currently open:
17.
This statement declares a constant named decInsuranceDeductible as a Decimal data
type and sets its value to 250.00:
18.
This Windows Form property allows the user to press the enter key while th eor is active
and activates a button's event handler:
19.
A local variable is…
Local variables differ from a global variable, since global variable can be used by other
subroutines
20.
Debugging Exercises
1.
Option Strict On
Dim intDistance As Integer
IntDistance = 17.5
Integers cannot have decimals. So, it could be fixed by changing the type to Decimal:
Option Strict On
Dim decDistance As Decimal
decDistance = 17.5
2.
Dim dblRegularPay As Double
Dim dblOvertimePay As Double
IntRegularPay = 783.87
IntOvertimePay = 105.92
lbl.TotalPay + (dblRegularPay + dblOvertimePay).ToString('C')
The data types should be Decimal not Double or Integer, since pay amounts typically
have decimals and are not large numbers like Doubles. It could be fixed by changing the
type to Decimal as follows:
Dim decRegularPay As Decimal
Dim decOvertimePay As Decimal
decRegularPay = 783.87
decOvertimePay = 105.92
lbl.TotalPay = (decRegularPay + decOvertimePay).ToString('C')
3.
Debugging Exercises
Program Analysis Exercises
-->
->
--->
Back Your location: Home Page › Chapter Four › Edit Submission
Edit Submission: Chapter Four Assignments Part III (Attempt 1 )
Due Date: July 16, 2010 11:00 AM
Type: Work individually
Grading Criteria: out of 50
Status: In Progress (Attempt 1)
Instructions:
Complete the Programming Assignments:
#6 Convert Currency
Submit completed programs through this assignment tool
Attachments:
Event Planning Document
Program Name:
Developer:
Object:
Date:
Toy Selection
Alicia Gomes
frmToySelection.vb
July 17, 2010
Object
Event Trigger
btnDoll
Click
Event Processing
 Display Doll Picture
 Hide Airplane Picture
 Hide Ball Picture
 Enable Select Toy Button
btnAirplane
Click
 Display Airplane Picture
 Hide Doll Picture
 Hide Ball Picture
 Enable Select Toy Button
btnBall
Click
 Display Ball Picture
 Hide Doll Picture
 Hide Airplane Picture
 Enable Select Toy Button
btnSelectToy
Click
 Disable Doll Button
 Disable Airplane Button
 Disable Ball Button
 Disable Select Toy Button
 Hide View Toy Options Label
 Hide Select Toy Label
 Display Exit Window Label
 Enable Exit Window Button
btnExitWindow
Click
 Close window and terminate the program
This is a long and complicated chapter. You will more than likely, need to re-read sections of
this chapter in order to really understand the information presented.
For this chapter, I will be requiring that you complete and submit all of the:
Knowledge Check Questions
Debugging Exercises
Program Analysis Exercises
Complete and submit in a Word document through this assignment tool
7. This name is invalid since it does not follow the rules stated above. This variable
(Close) is one of the protected words in Visual Basic 2008, since it appears in blue
in the code and is used to close a FormObject.
Download