Thursday, February 26, 2009

Review Questions CHAPTER 3


1. Assume a procedure needs to store an item’s name and its price. The price may have a decimal place. Write the appropriate Dim statements to create the necessary procedure-level variables.

**Dim itemName As String
Dim priceName As Decimal

2. Assume a procedure needs to store the name of an item in inventory and its height and weight. The height may have decimal places; the weight will be whole numbers only. Write the appropriate Dim statements to create the necessary procedure-level variables.

***Dim ItemHeight As Decimal
Dim ItemWeight As Integer

3. Write an assignment statement that assigns Miami to an existing String variable named city.

*** Dim city As String
city = “Miami”

4. Write an assignment statement that adds the contents of the sales1 variable to the contents of sales2 variable, and then assigns the sum to an existing variable named totalSales. All of the variables have the Decimal date type.

***Dim totalSales As Decimal
Dim sales1 As Decimal
Dim sales2 As Decimal
totalSales = (sales1 + sales2)

5. Write an assignment statement that multiplies the contents of the salary variable by the number 1.5, and then assigns the results to the salary variable. The salary variable has the Decimal data type.

***Dim Salary As Decimal
Salary = 1.5D

6. Assume a form contains two buttons named salaryButton and bonusButton. Both buttons’ Click event procedures need to use the same variable, which is a String variable named employeeName. Write an appropriate statement to declare the employeeName variable. Also specify where you will need to enter the statement and whether the variable is a procedure-level or module-level variable.

*** Dim employeeName As String

9. Write the statement to convert the contents of the unitsTextBox to an integer. Store the Integer is an Integer Variable named numberofunits. Use isConverted as the name of the Boolean.

***Dim numberofunits As Integer
Dim isConverted As Boolean
isConverted = Integer.TryParse(unitsTextBox.Text, numberofunits)

15. What is a static variable?

***A special type of produce-level variable that retains its value even when the procedure ends.


Review Questions CHAPTER 4

7. Write an If...Then...Else statement that displays the string "Pontiac" in the carmakerLabel when the carTextBox contains the string "Grand Am".

***If carTextBox.text = "Grand Am"
ThencarMakeLabel.text = "Pontiac"End If

8.
***If variable < 0
ThenMessageBox.Show("Entry Error", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseMessageBox.Show("Valid Number", "Valid Number", MessageBoxButtons.OK, MessageBoxIcon.Information)End If9)
If quantity < 10
thenMessageBox.Show("Reorder", "Reorder", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseMessageBox.Show("OK", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If


13) If hours are less than or equal to 40 then multiply hours by hoursRate. Else, subtract forty, multiple the remainder by hoursRate and 1.5. Add 40 time by hourRate.

***If hours < 40
Thengross = hours*hourRate
Elsegross = (hours - 40) * hourRate * 1.5 + 40 * hourRate
End If

No comments: