Tutorial Week 13 - Revision


Home


Meet in the class room NOT a lab.

Question 1

State the order of precedence of the following Visual Basic operators:

-, *, +, (), /

Question 2

Evaluate the following Visual Basic expressions, showing all working. Only one operation is to be performed at a time. After an operation is performed, rewrite the whole expression including the result of the previous operation on a new line, as shown in the example below.

Use: a = 10, b = 2, c = 12.3

Example

Expression:

a / 2 +  b * 4 

Working:

10 / 2 + 2 * 4 
5 + 2 * 4 
5 + 8 
13

  1. a - b + 4
  2. a + b * 2
  3. b + (a + 2) / 4
  4. c * 10 - a / 5 / b

Question 3

State the order of precedence of the following Visual Basic operators:

And, Not, Or,  =, <=, <, <>, >, >=

Question 4

Complete the following Result column in the following tables:

e.g. True Or True (the result is True)

Or

Compound Condition Result
True Or True  
True Or False  
False Or True  
False Or False  

And

Compound Condition Result
True And True  
True And False  
False And True  
False And False  

Not

Compound Condition Result
Not True  
Not False  

Question 5

Evaluate the following Visual Basic expressions, showing all working. Only one operation is to be performed at a time. After an operation is performed, rewrite the whole expression including the result of the previous operation on a new line, as shown in the example below.

Use: a = 10, b = 2, c = 12.3

Example

Expression

a > 5 Or b < 3 

Working

10 > 5 Or 2 < 3
True Or 2 < 3
True Or True
True

  1. a <> 10
  2. c > 12.3 Or b <= 3
  3. a < 0 Or a > 10
  4. b >= 1 And b <= 7
  5. Not c > 7 And c > 7

Question 6

Show what would be displayed by the following Visual Basic statements.

Use: a = 10, b = 2, c = 12.3

  1. Debug.Print  "a = "; a; " b:"; b
  2. Debug.Print Format(c, "0.000"); "**b ="; a; "days"
  3. Debug.Print  a; "-"; b; "="; c

Question 7

Perform a Desk Check (as specified in lectures) on the logic shown below.

Pseudo Code

1  taxation()
2      totalTax = 0
3      Input income
4      WHILE income >= 0 DO
5          calcTax()
6          Display tax
7          totalTax = totalTax + tax
8          Input income
9      ENDWHILE
10     Display totalTax
11 STOP

12 calcTax()
13     IF income <= 10000 THEN
14         tax = 0
15     ELSE
16         IF income <= 30000 THEN
17             tax = (income - 10000) * 0.10
18         ELSE
19             IF income <= 50000 THEN
20                 tax = 2000 + (income - 30000) * 0.20
21             ELSE
22                 tax = 6000 + (income - 50000) * 0.30
23             ENDIF
24         ENDIF
25     ENDIF
26 EXIT

Data Dictionary

Name Data Type Description
income Integer The net income of the employee
tax Double The tax payable on the net income
totalTax Double The total tax payable for all workers

Data to use: 20000, 50000, -1

Question 8

Perform a Desk Check (as specified in lectures) on the logic shown below.

Pseudo Code

1  compareNumbers()
2      Input number1, number2, number3
3      getLargestNumber()
4      Display largest   
5  STOP
6  getLargestNumber()
7      largest = number1
8      IF number2 > largest THEN
9          largest = number2
10     ENDIF
11     IF number3 > largest THEN
12         largest = number3
13     ENDIF
14 EXIT
        

Data Dictionary

Name Data Type Description
largest Integer The largest of the three numbers input
number1 Integer The first number to be compared
number2 Integer The second number to be compared
number3 Integer The third number to be compared

Data to use: 20, 2, 19
Data to use: 1, 6, 10


Written by Tim Whitfort.