S3 First Test - HKTA Tang Hin Memorial Secondary School

advertisement
Hong Kong Taoist Association Tang Hin Memorial Secondary School
S.3 Computer Literacy (2014-15)
First Test
Question-Answer Book
Date: 24 October 2014
Time: 8:40-9:20 (40 min)
Section
Instruction:
1. The full mark for this paper is 90.
2. Attempt ALL questions.
3.
4.
Write down ALL the answers in this
Question-Answer Book.
The Question-Answer Book consists of 15 pages.
Name:
Class:
Class Number:
Mark:
/ 90
P. 1
Marks
Full
A
30
B
5
C
10
D
8
E
5
F
7
G
10
H
15
Multiple Choice Questions (30 marks, 2@)
Section A:
Put a “” in the box of the most suitable answer.
1
2
3
4
5
6
7
8
9
10
11
12
A
B
C
D
1.
What is the range of random numbers produced for the expression
Int(Rnd() * 11)?
0 to 10
1 to 10
0 to 11
1 to 11
2.
Which of the following can always produce a number from 1 to 6?
( n is an integer )
1 + n Mod 5
(n+1) Mod 7
n Mod 7
1+(n+1) Mod 6
3.
Which of the following is NOT a reserved keyword in Visual Basic?
Class
End
Public
Value
4.
Which of the following operators is calculated last?
Or
\
^
Mod
P. 2
13
14
15
5.
Which of the following returns the value TRUE?
TRUE and FALSE
FALSE and FALSE
Not(TRUE)
FALSE or not(FALSE)
6.
In the program below, what should be the data type of variable y?
Select Case y
Case True
Timer1.Enabled = False
Case False
Timer1.Enabled = True
End Select
Integer
String
Boolean
Single
7.
Which of the following statement about Timer is FALSE?
Timer1.Tick is the most common event for Timer control.
Unit of Interval for Timer control is in seconds.
Normally, Timer control is not visible on a Form.
Timer control is used when a task is supposed to be completed within a
specific time.
8.
With this “For” statement, how many times will the statement
“Console.WriteLine()” be executed?
For i = -4 To 2
Console.WriteLine()
Next
5
6
7
8
P. 3
9.
What is the result of the following program segment?
For i As Integer = 47 To 76 Step 5
Console.WriteLine("7")
Next
7777777
7777777
7777777
7777777
7777777
47
54
61
68
75
7
7
7
7
7
7
76
69
62
55
48
10. Study the following program:
Dim i As Integer
Dim x As Integer = 0
For i = 10 To 1 Step 2
x = x + i
Next i
Console.WriteLine(i)
What is the output of the program?
0
10
30
55
11. What will be the result if the user enters “John” and “Tai Tong” to this program
segment?
Console.Write("Enter your first name: ")
Dim s As String = Console.ReadLine()
Console.Write("Where will you go for your picnic? ")
Dim p As String = Console.ReadLine()
Console.WriteLine(UCase(s) & ", you are going to " & LCase(p) & ".")
Console.ReadLine()
john,
John,
John,
JOHN,
you
you
YOU
you
are
are
ARE
are
going
going
GOING
going
to
to
TO
to
tai
Tai
TAI
tai
P. 4
tong.
Tong.
TONG.
tong.
12. Which of the following code segment will create the result below?
@
@
@
@
@
For i As Integer = 1 To 5
For j As Integer = 1 To i
Console.Write("@")
Next
Console.WriteLine()
Next
For i As Integer = 5 To 1 Step -1
For j As Integer = 1 To i
Console.Write("@")
Next
Console.WriteLine()
Next
For i As Integer = 5 To 1 Step -1
For j As Integer = 1 To i - 1
Console.Write(" ")
Next
Console.Write("@")
Console.WriteLine()
Next
For i As Integer = 1 To 5
For j As Integer = 1 To i - 1
Console.Write(" ")
Next
Console.Write("@")
Console.WriteLine()
Next
P. 5
13. Which of the following statement is FALSE?
7
8
6
5
^ 2 - 4 <= 2 ^ 5
Mod 3 - 4 = -5 \ 2
* (3 + 7) <> 1000 ^ 1 / 3
* 7 Mod 2 < 79 Mod 16
14. Which of the following is a possible result with the following program segment?
Console.Write("Please enter a word: ")
Dim s As String = Console.ReadLine()
Dim sLen As Integer = Len(s)
Dim x As String = ""
For i As Integer = 1 To sLen
x = x & Mid(s, 1, i)
Console.WriteLine(x)
Next
Please enter a word: dog
g
gog
gogdog
Please enter a word: dog
dog
dog
dog
Please enter a word: dog
d
ddo
ddodog
Please enter a word: dog
d
do
dog
P. 6
15. What will be the result with the following program segment?
For i As Integer = 1 To 50
Console.Write(2 * i - 1 & " ")
If Strings.Right(2 * i - 1, 1) = 9 Then
Console.WriteLine()
End If
Next
For i As Integer = 1 To 50
Console.Write(2 * i & " ")
If Strings.Right(2 * i, 1) = 0 Then
Console.WriteLine()
End If
Next
For i As Integer = 1 To 100 Step 2
Console.Write(i & " ")
If Strings.Right(i, 1) = 9 Then
Console.WriteLine()
End If
Next
For i As Integer = 50 To 1 Step -1
Console.Write(2 * i & " ")
If Strings.Right(2 * i, 1) = 2 Then
Console.WriteLine()
End If
Next
For i As Integer = 1 To 50
Console.Write(i ^ 2 & " ")
If Strings.Right(i, 1) = 0 Then
Console.WriteLine()
End If
Next
P. 7
Section B:
True or False. Circle the correct answers. (5 Marks, 1@)
Question
1.
2.
3.
4.
5.
Strings.Left("Hong Kong",4) <> Strings.Right("Hong Kong",4)
Strings.Mid("Hong Kong",2,3) = Strings.Mid("Hong Kong",7,3)
Strings.InStr(1, "Hong Kong","ng") > Strings.Len("Happy")
"Hong Kong" < "HAPPY"
In the picture below, the box next to “Username” is similar to a text
box.
Section C:
1.
Write down the output of the following.
Code / Statements
Dim i As Integer
For i = 1 To 5 Step 2
Console.WriteLine(i * i)
Next i
2.
Dim s As Integer
For s = 3 To 10 Step 3
Console.Write("#")
Next
3.
Dim p As Integer
For p = 5 To 1 Step -1
Console.Write(p)
Next
4.
Dim a, b As Integer
For a = 1 To 2
For b = 1 To 2
Console.WriteLine(a)
Next b
Console.Write("A")
Next
5.
Dim k, m As Integer
m = 1
For k = 1 To 4
m = m * 3
Next
Console.WriteLine(m)
P. 8
Answer
T / F
T / F
T / F
T / F
T / F
(10 Marks , 2@)
Answer
Section D:
Select Case (8 Marks, 1@)
Consider the following table of Air Pollution Index:
API
0-50
51-100
101-200
output
Low
High
Very high
otherwise
Invalid entry
Complete the following program:
Dim _____________________ As Integer
Console.Write("What is the Air Pollution Index today?")
api = Val(____________________________)
Select Case _____________________
Case _____________________
Console.writeline("Low")
Case _____________________
Console.writeline("High")
Case _____________________
Console.writeline("Very high")
Case _____________________
Console.writeline("Invalid entry")
End _____________________
P. 9
Section E:
Console Programming. (5 Marks)
Write a program that calculates the area of a circle with a given radius. The program should
be able to produce the sample outputs shown below, where the shaded texts in the sample
outputs are the user inputs.
(The area of the circle A can be calculated by the formula A   r 2 . Take  = Math.PI)
Sample Output 1
Enter the radius r: 5.5
The area of the circle is 95.0331777710912
Sample Output 2
Enter the radius r: 1
The area of the circle is 3.14159265358979
Program
Sub Main()
Dim r As Double
End Sub
P. 10
Section F:
Programming (7 Marks, 1@)
The following program generates an addition problem and asks the user to solve it. In each
question, two numbers from 10 to 99 are generated. Here is a sample output of the program:
Sample Output 1
Addition Problem
97 + 25 = 122
You are right!
Sample Output 2
Addition Problem
41 + 92 = 130
You are wrong!
Complete the program below:
__________________ 'Required to generate random numbers.
Dim a, b, _____________ As Integer
Console.WriteLine("Addition Problem")
Console._________________
a = ____________________________
b = ____________________________
Console.Write(a & " + " & b & " = ")
ans = Val(Console.ReadLine())
If ans = ________ Then
Console.WriteLine(______________)
Else
Console.WriteLine("You are wrong!")
End If
Console.ReadLine()
P. 11
Section G:
For…Next (10 Marks)
1. Consider the following program:
Line no.
Statement
1
2
3
4
5
6
Dim k, sum As Integer
sum = 0
For k = 1 To 4
sum += k
Console.writeline("K=" & k & “ sum=” & sum)
Next
(a) Write down the output.
4M
(b) What is the expression of the above addition program? 1M
Sum = ___ + ___ + ___ + ___
(c) Complete the following table to produce this sample output:
K=1 sum=2
K=2
K=3
K=4
K=5
Line no.
sum=6
sum=12
sum=20
sum=30
Statement
3
4
P. 12
2M
(d) Complete the following table to produce this sample output:
1M
K=1 sum=1
K=2
K=3
K=4
K=5
sum=4
sum=9
sum=16
sum=25
Line no.
Statement
3
Same as the answer in part (c)
4
2. Consider the following program segment:
product = 2
For k = 3 To 7
product = product * k
Next
Console.Writeline(product)
(a) What is the expression of the above multiplication program?
1M
Product = ___ *___ *___ *___ *___ *___
(b) What is the final value of product if product= 2 is changed to product= -2? (1M)
_______________________________________________
P. 13
Section H:
Programming (15 marks, 1@)
This programme is to find out the numbers of odd and even digits in a phone number. When
the programme runs, the console appears like this:
As user enters “26726820”, the console becomes:
If the user enters a longer phone number like this, the programme responses as:
P. 14
Complete the programme by filling the blanks: (Each [ ] represents a blank.)
Module Module1
Sub Main()
Dim i, a, odd, even As [1], pNum As [2]
Console.WriteLine("*** SEARCHING FOR ODD AND EVEN DIGITS IN A PHONE NUMBER ***")
Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
Console.Write("[3]")
pNum = [4]
odd = [5]
even = [6]
For i = 1 To Len(pNum)
a = Mid([7], [8], [9])
If a Mod 2 = [10] Then
Even[11]
Else
Odd[12]
End If
Next
Console.WriteLine("Number of digits: " & [13])
Console.WriteLine("Odd digit(s): " & [14])
Console.WriteLine("Even digit(s): " & [15])
Console.ReadLine()
End Sub
End Module
Write down the code represented by “[1]” to “[15]” in the table below.
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]
[11]
[12]
[13]
[14]
[15]
-- End of Paper -P. 15
Download