s.3 computer literacy 2015-16 first test · s.3 c.p. 1st test q&a pp.9/12 part e: select case...
TRANSCRIPT
Hong Kong Taoist Association Tang Hin Memorial Secondary School
S.3 Computer Literacy
2015-16
First Test
Question-Answer Book
Date: 28nd October 2015
Time: 8.40 – 9.20
Instructions:
1. Full mark of this paper is 100.
2. There are 12 pages in this Question-Answer Book.
3. Attempt ALL questions.
4. Put ALL your answer in this Question-Answer Book.
Class:
Name:
Class Number:
A 32
B 10
C 6
D 10
E 8
F 14
G 11
H 9
100
S.3 C.P. 1ST TEST Q&A pp.2/12
Part A: Multiple Choices [32M, 2M@] Put a “” in the box of the most suitable answer.
1. Which of the following is true for console application?
A. The interface is text only.
B. Button can be used.
C. It is easier to use by mouse.
D. Clear method cannot be used.
2. Which of the following cannot be found in timer control?
A. Timer1.enabled
B. Timer1.interval
C. Timer1.Tick
D. Timer1.Exit
3. Which of the following is an error for select…case statement?
A. Case 1 to 100
B. Case >=1 and <=100
C. Case Is <=100
D. Case 100
4. How many output numbers can be displayed for the following part?
For i = 10 To -10 Step -5
Console.WriteLine(i)
Next
A. 4
B. 5
C. 6
D. 7
5. What is the output of the following part?
For i = 10 To 0 Step 2
Console.Write(i)
Next
A. 1086420
B. 109876543210
C. No output
D. 101214161820
6. What is the range of random numbers produced for the expression
Int(Rnd() * 5 - 5)?
A. 5 to 10
B. 0 to 1
C. -5 to -1
D. -4 to 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
A
B
C
D
S.3 C.P. 1ST TEST Q&A pp.3/12
7. What is the final value of variable i for the following part?
For i = 1 To 10
Console.WriteLine(i)
Next
Console.WriteLine(i)
A. 9
B. 10
C. 11
D. 12
8. Which of the following can always produce a number from 2 to 9? ( n is an integer )
A. n Mod 8 + 2
B. (n+2) Mod 9
C. n Mod 8
D. 1+(n+1) Mod 8
9. Which of the following is can be a name of a variable in Visual Basic?
A. Class
B. Exit
C. Private
D. __234
10. Which of the following operators is calculated first?
A. &
B. +
C. And
D. Or
11. Which of the following returns the value False?
A. True Or False
B. Not True Or Not False
C. True Or Not False
D. Not True Or False
12. Which of the following code segment will create the result below?
A. For i As Integer = 1 To 4
For j As Integer = 5 To 9
Console.Write(j - i)
Next
Console.WriteLine()
Next
B. For i As Integer = 4 To 1 Step -1
For j As Integer = 9 To 5 Step -1
Console.Write(j - i)
Next
Console.WriteLine()
Next
S.3 C.P. 1ST TEST Q&A pp.4/12
C. For i As Integer = 4 To 1 Step -1
For j As Integer = 5 To 9
Console.Write(j - i)
Next
Console.WriteLine()
Next
D. For i As Integer = 1 To 4
For j As Integer = 9 To 5 Step -1
Console.Write(j - i)
Next
Console.WriteLine()
Next
13. Which of the following statement is TRUE?
A. -17 Mod 2 ^ 3 <> 14 - 5 * 3
B. 3 ^ 2 \ 7 > 8 ^ (1 / 3)
C. 4 * 5 \ 3 < 13 * 2 Mod 3
D. 6 \ 3 * 2 = 11 Mod 2 * 5
14. Study these 3 code segments:
I. For i As Integer = 1 To 4
For j As Integer = 1 To i
Console.Write(" ")
Next
Console.WriteLine("*")
Next
Console.ReadLine()
II. For i As Integer = 4 To 1 Step -1
For j As Integer = i To 1 Step -1
Console.Write(" ")
Next
Console.WriteLine("*")
Next
Console.ReadLine()
III. For i As Integer = 1 To 4
For j As Integer = i To 1 Step -1
Console.Write(" ")
Next
Console.WriteLine("*")
Next
Console.ReadLine()
Which of the code segments will create same results?
A. I, II B. II, III
C. I, III D. All of the above
S.3 C.P. 1ST TEST Q&A pp.5/12
15. To create the following output, what should be the code segment?
A. Console.Write("Enter a word: ")
Dim s As String = Console.ReadLine()
Dim t As Integer = Len(s)
Dim u As String = ""
For i As Integer = 1 To t
u &= Mid(s, i, 1)
Console.WriteLine(u)
Next
B. Console.Write("Enter a word: ")
Dim s As String = Console.ReadLine()
Dim t As Integer = Len(s)
Dim u As String = ""
For i As Integer = t To 1 Step -1
u &= Mid(s, i, 1)
Console.WriteLine(u)
Next
C. Console.Write("Enter a word: ")
Dim s As String = Console.ReadLine()
Dim t As Integer = Len(s)
Dim u As String = ""
For i As Integer = 1 To t
u &= Mid(s, 1, i)
Console.WriteLine(u)
Next
D. Console.Write("Enter a word: ")
Dim s As String = Console.ReadLine()
Dim t As Integer = Len(s)
Dim u As String = ""
For i As Integer = t To 1 Step -1
u &= Mid(s, 1, i)
Console.WriteLine(u)
Next
S.3 C.P. 1ST TEST Q&A pp.6/12
16. Which of the following will create a result that is different from the other 3?
A. For i As Integer = 1 To 4
Console.Write("$ |")
Next
Console.WriteLine()
B. For i As Integer = 1 To 4
Console.WriteLine("$ |")
Next
C. For i As Integer = 1 To 4
Console.WriteLine("$ |")
Next
D. For i As Integer = 4 To 1 Step -1
Console.WriteLine("$ |")
Next
Part B: Write down the outputs of the following parts: [10M]
1 For i = 1 To 10 Step 2
Console.Write(i & "!")
Next
2 For i = 1 To 3
For j = 1 To 5
Console.Write("*")
Next
Console.WriteLine()
Next
3 For i = 1 To 2
For j = 1 To 3
Console.Write(i & "-" & j & "-")
Next
Console.WriteLine()
Next
4 For i = 1 To 3
For j = i To 4
Console.Write(j)
Next
Console.WriteLine()
Next
5 For i = 1 To 4
For j = 1 To i
Console.Write("*")
Next
Console.WriteLine()
Next
S.3 C.P. 1ST TEST Q&A pp.7/12
Part C: Console Programming. [6M]
Write a program that calculates the value of f in the formula below:
vu
uvf
The program should be able to produce the sample outputs shown below, where the shaded texts in the sample outputs are the user inputs.
Sample Output 1
Enter the value of u: 1
Enter the value of v: 2
The value of f is 0.666666666666667
Sample Output 2
Enter the value of u: 5.5
Enter the value of v: 2.5
The value of f is 1.78175
Program
Sub Main()
Dim u, v As Double
End Sub
S.3 C.P. 1ST TEST Q&A pp.8/12
Part D: Programming [10M]
Q1 Read the following program:
Sub Main()
Dim i, k, sum As Integer
Console.Write("Enter the value of k: ")
k = Val(Console.ReadLine())
sum = 0
line A: For i = 1 To k
line B: sum += i
Next
Console.WriteLine("sum = " & sum)
Console.ReadLine()
End Sub
a) Write down the screen output when the user inputs 10 for the value of the variable k.
(2M)
______________________________________________________________
______________________________________________________________
b) Change line A only to get the sum of even numbers from 2 to 30 (user’s input) by
using keyword step. (2M)
______________________________________________________________
c) Change line B only to get the sum of even numbers from 2 to 30 (the user inputs 15)
without using keyword step. (1M)
______________________________________________________________
d) What is the final value of sum if k is 10 and the following 3 lines are inserted between
lines A and B? (1M)
If i Mod 5 = 0 Then
Exit For
End If
______________________________________________________________
e) What is the final value of sum if k is 10 and the following 3 lines are inserted
between lines A and B? (1M)
If i Mod 5 = 0 Then
Continue For
End If
______________________________________________________________
f) What is the meaning of i Mod 5 = 0? (1M)
______________________________________________________________
______________________________________________________________
g) What is the use of the above program? (1M)
______________________________________________________________
______________________________________________________________
h) What is the meaning of sum+=i? (1M)
______________________________________________________________
______________________________________________________________
S.3 C.P. 1ST TEST Q&A pp.9/12
Part E: Select Case [8M]
Sammy has written a program that gives comments on an odds on winning. Odds on winning is
calculated by
losses of no.
winsof no.on winning odds
The comment given by Sammy is as follows:
Odds on winning Comment
< 0.5 Very unlucky!
≥ 0.5 but < 1 Unlucky!
≥ 1 but ≤ 2 Lucky!
> 2 Very lucky!
Otherwise Error...
Peter has got a copy of the code. Unfortunately some code has been missing. Please complete the
missing code.
Console.Write("Enter the number of wins: ")
Dim wins As Double = Val( _____________________ )
Console.Write("Enter the number of losses: ")
Dim losses _____________ = Val(Console.ReadLine())
______________________________
Case ______________
Console.WriteLine("Very unlucky!")
Case ______________
Console.WriteLine("Unlucky!")
Case ______________
Console.WriteLine("Lucky!")
Case ______________
Console.WriteLine("Very lucky!")
Case ______________
Console.WriteLine("Error...")
End Select
S.3 C.P. 1ST TEST Q&A pp.10/12
Part F: Write down the output of the following: [14M, 2M@]
Codes Output
1. 2 ^ InStr(3, "opportunities", "o")
2. Dim s As String = "opaque"
Dim t As Integer = InStr(s, "a")
Console.WriteLine(Mid(s, t, t) & mid(s, 3,1))
3. 28 \ InStr("equality", "i") * 2
4. Strings.Left("volcano", 3) & Strings.Right("pulley", 3)
5. Dim u As String = "consultation"
Console.WriteLine(InStr(Len(u) - 4, u, "t"))
6. Dim v As String = "transparent"
Console.WriteLine(Mid(v, 6, 6) & Mid(v, 5, 1))
7. Dim w As Integer = 26726820
Console.WriteLine(Strings.Right(w, 3) Mod 17)
Part G: Programming [11M]
The following programme helps customer to find out the amount to be paid at the “Fun Fun
Catering”. There are two meals (sandwiches and chicken wings) and two drinks (soya milk and
lemon tea) for the customer to choose. [11M]
Firstly, customer will see this display:
After entering all choices, customer will see this display:
S.3 C.P. 1ST TEST Q&A pp.11/12
Complete the programme by filling up the blanks:
Line Code
1 Sub Main()
2 Console.WriteLine(________________________________________ )
3 Console.WriteLine("Please choose your meal and drink.")
4 Console.Write("Select Meal A (Sandwiches) or Meal B (Chicken wings): (Use A or B only) ")
5 Dim meal As String = ____________________ (Console.ReadLine())
6 Console.Write("Select Drink X (Soya milk) or Drink Y (Lemon tea): (Use X or Y only) ")
7 Dim drink As String = ____________________ (Console.ReadLine())
8 Dim total As String
9 Select Case ____________________
10 Case ____________________
11 ____________________
12 Case "X"
13 total = "Sandwiches + Soya milk = $10.5"
14 Case "Y"
15 total = "Sandwiches + Lemon tea = $12.5"
16 End Select
17 Case ____________________
18 Select Case drink
19 Case "X"
20 total = "Chicken wings + Soya milk = $13.5"
21 Case "Y"
22 total = "Chicken wings + Lemon tea = $15.5"
23 End Select
24 ____________________
25 ____________________
26 Console.WriteLine("***** Thanks for your purchase *****")
27 Console.Write("Your meal: " & ____________________)
28 ____________________
29 End Sub
S.3 C.P. 1ST TEST Q&A pp.12/12
Part H: Programming [9M]
Rachel writes a program to find the information of a string. Here is a sample output:
Enter a string: This is a testing string...
The string contains 20 letters, 0 digits, 4 spaces and 3 symbols.
Now write the program below:
Console.Write("Enter a string: ")
Dim s As String = ____________________
Dim letters, digits, spaces, symbols As Integer
For i As Integer = 1 To _________
' Do operations on a character
Select Case _________________
' Both capital and small letters
Case _____________________
letters += 1
Case _____________________
digits += 1
Case " "
__________________
Case Else
symbols += 1
End Select
________
' Output the result
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
* * * End of S.3 C.P. Paper * * *