Sie sind auf Seite 1von 22

Chapter 14 Using High-Level Programming Language Question Bank

Chapter 14 Using High-Level Programming Language


Multiple Choice Questions

(U01C14L01Q001)
What kind of control structure can carry out a step repeatedly?
A. sequence control structure
B. selection control structure
C. iteration control structure
D. none of the above
Answer
C

(U01C14L01Q002)
What kind of control structure is employed in the following flowchart?

Input

False Passwo
Password
rd correct

True

A. sequence control structure


B. selection control structure
C. iteration control structure
D. none of the above
Answer
C

Computer & Information Technology for HKCEE 1 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L01Q003)
What kind of control structure does the following conditional statement belong to?
If Final >= 50 then
Set Status to Pass
Else Set Status to Fail
A. sequence control structure
B. selection control structure
C. iteration control structure
D. none of the above
Answer
B

(U01C14L01Q004)
A program used to find the mean of two numbers is shown below.
Input A
Input B
Mean = (A + B) / 2
What kind of control structure is used in the program?
A. sequence control structure
B. selection control structure
C. iteration control structure
D. none of the above
Answer
A

Computer & Information Technology for HKCEE 2 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L01Q005)
What is the output of the following program?
Assign 5 to A
Assign 2 to B
Assign 1 to C
While A > 0 Do
Assign C × B to C
Decrease A by 1
Print C
A. 2
B. 16
C. 32
D. 64
Answer
C

(U01C14L01Q006)
Study the condition below.
If you are a full-time student or your age is over 60, you can get a discount of
30%.
Which of the following cases can get the discount?
(1) Tom is a full-time student. He is 18 years old.
(2) Mary is not a full-time student. She is 65 years old.
(3) Peter is a part-time student. He is 61 years old.
A. (1) only
B. (2) only
C. (3) only
D. (1), (2) and (3)
Answer
D

Computer & Information Technology for HKCEE 3 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L01Q007)
Arrange the following program lines in the correct order, so that the program can
swap the values of variables A and B.
(1) Assign the value of A to B
(2) Assign the value of B to C
(3) Assign the value of C to A
A. (1) → (2) → (3)
B. (1) → (3) → (2)
C. (2) → (1) → (3)
D. (2) → (3) → (1)
Answer
C

(U01C14L01Q008)
The algorithm of a program is shown below:

1 Assign Q − 2 to P
2 Assign P + 2 to Q

Which of the following statements is/are correct?


(1) After executing the program, P and Q must have the same value.
(2) After executing the program, the value of Q remains unchanged.
(3) After executing the program, the value of P remains unchanged.
A. (1) only
B. (2) only
C. (3) only
D. (2) and (3) only
Answer
B

Computer & Information Technology for HKCEE 4 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L01Q009)
The algorithm of a program is shown below:

1 X= 3
2 Y=5
3 IF 2Y > 10
4 THEN Print Y + X
5 ELSE Print Y

What is the output of this program?


A. 5
B. 8
C. 10
D. 13
Answer
A

(U01C14L01Q010)
The algorithm of a program is shown below:

1 Y = –3
2 Z = 10
3 WHILE Z ≥ 0 DO
4 END

Which of the following statements should be inserted between the 3rd and 4th lines of
the algorithm in order to prevent endless looping?
A. Z= Z – Y
B. Z = 100 – Z
C. Z = Z + Y
D. Z = 0
Answer
C

Computer & Information Technology for HKCEE 5 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L01Q011)
Which of the following is NOT a logic error?
A. A wrong condition is used.
B. A misspelled variable is defined.
C. A wrong algorithm is used.
D. Variable has a wrong initial value.
Answer
B

(U01C14L01Q012)
Dry run
A. is used in problem analysis.
B. can produce object program.
C. can examine the logic and codes of a program.
D. means that no value is assigned to the variables when executing the program.
Answer
C

(U01C14L01Q013)
The algorithm of a program is shown below:

1 Input N
2 X=2
3 WHILE X < N
4 IF X is a prime number
5 THEN Print X
6 X=X+1
7 END

The purpose of the above program is to find out


A. whether N is a prime number.
B. whether X is a prime number.
C. all the prime numbers which are less than N.
D. all the prime numbers which are less than X.
Answer
C

Computer & Information Technology for HKCEE 6 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L01Q014)
The algorithm of a program is shown below:

1 Input X
2 Input Y
3 X=Y
4 Y=X
5 Output X
6 Output Y

Which of the following statements is/are correct?


(1) The above program can interchange the values of X and Y.
(2) The above program includes a sequence control structure.
(3) The above program includes a selection control structure.
A. (2) only
B. (3) only
C. (1) and (2) only
D. (1) and (3) only
Answer
A

(U01C14L01Q015)
Study the grouping algorithm below.
John is a S4 student
If John is studying in S2 or lower form
Then John is in group C
Else John is in group B
If John is studying in S5 or upper forms
Then John is in group A
Which group does John belong to?
A. A
B. B
C. C
D. none of the above
Answer
B

Computer & Information Technology for HKCEE 7 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L01Q016)
Study the condition of the iteration control structure below.
While X > 10 and X <= 20
Begin

End
Which of the following values of X will STOP the iteration?
(1) X = 10
(2) X = 20
(3) X = 30
A. (1) only
B. (2) only
C. (1) and (3) only
D. (1), (2) and (3)
Answer
C

Computer & Information Technology for HKCEE 8 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

Conventional Questions

(U01C14L02Q001)
Mr. Chin wants to design a program to find the highest mark of 5A class students in a
mid-term examination. The following shows the pseudocode of the program:

10 Input N
20 Maximum = 0
30 WHILE N > 0 DO
40 N=N−1
50 Input X
60 If X > Maximum
70 THEN Maximum = X
80 END
90 Print Maximum

In the above pseudocode, N is the number of students and X is the examination mark
of a student. Suppose all the marks of students are positive.

(a) State the outputs if Mr Chin enters the following values:


(i) N = 0
(ii) N = 6,X = 20,X = 90,X = 50,X = 90,X = 10,X = 20
(2 marks)
(b) (i) What is the use of pseudocode?
(ii) According to the above pseudocode, sketch the flowchart of the program.
(5 marks)
(c) (i) Revise the above algorithm so that it can still find out the highest mark of
5A class students in an examination under the following conditions:
Condition 1: Do not input N. Input students’ marks directly.
Condition 2: After input the last mark of the students, input “−1”.
Condition 3: After input “−1”, output the highest mark.
(Show your answer using pseudocode.)
(ii) Comparing with the original algorithm, what is the advantage of using the
algorithm in (c) (i)?
(5 marks)

Computer & Information Technology for HKCEE 9 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

Answers
(a) (i) 0 (1)
(ii) 90 (1)
(b) (i) It is used to demonstrate the algorithm. (1)
(ii)

BEGIN

Input N

Maximum = X
N-1

False
N>0?

True
(4 )
N=N−1 Print Maximum

Input X
END

True
X > Maximum?

Maximum = X
False
N-1

(c) (i)
10 Input X
20 Maximum = 0
30 WHILE X ≠ −1 DO
40 IF X > Maximum
50 THEN Maximum = X
60 Input X
70 END
80 Print Maximum
(iteration structure: 1, IF X > Maximum: 1, others: 2)
(ii) It is no need to know the number of students at the beginning. (1)
Computer & Information Technology for HKCEE 10 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L02Q002)
Mary invented a number conversion machine It can perform conversion between
binary and denary numbers and the results are then displayed on the screen.
There are two buttons on the conversion machine: Button A and Button B. The
functions of the buttons are as follows:

Butto Function
n
A Convert binary number into denary number
B Convert denary number into binary number

The operation of the conversion machine is as follows:


1. Select the required conversion by pressing Button A or Button B.
2. Input the number to be converted.
3. Press Enter key to start the conversion.

Example: After pressing Button A, inputting 11001 and pressing Enter key, the
conversion machine will convert 110012 to 2510. “25” will be displayed on the screen.

(a) What will the screen display if Mary input the following data?
(i) A, 11111
(ii) B, 101
(2 marks)

Before constructing this conversion machine, Mary has made a structure diagram to
divide the problem into different modules:

Conversion machine

Module A Module B Module C

Module D Module E

Computer & Information Technology for HKCEE 11 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(b) (i) Match the following items with the Modules A to E of the above diagram:
(1) Perform conversion
(2) Input the required conversion
(3) Output result
(4) Input data
(5) Input number
(ii) Which step of problem solving procedure does the making of structure
diagram belong to?
(iii) State TWO advantages of using modular approach.
(6 marks)
(c) Use pseudocode to demonstrate the algorithm of conversion machine. (In the
pseudocode, you are not required to describe how the number is converted from
denary to binary, or from binary to denary.)
(4 marks)
Answers
(a) (i) 31 (1)
(ii) 1100101 (1)
(b) (i)
Module Item
Module A 4
Module B 1
Module C 3
Module D 2
Module E 5

(Each item: 0.5, all correct: 3)


(ii) problem analysis (1)
(iii) The smaller and easier modules are processed one by one. /
Each module may be tested and debugged individually. /
Different modules may be processed by different people at the same time. /
Modules may be re-used in another program. (Any 2 × 1)
(c) 10 Input Option
20 Input X
30 IF Option = A
40 THEN Convert X to Denary
50 ELSE Convert X to Binary
60 Assign Result to Y
70 Output Y
Computer & Information Technology for HKCEE 12 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(input / output: 1, selection structure: 1, others: 2)

Computer & Information Technology for HKCEE 13 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L02Q003)
(a) Design an algorithm to find the middle number among the inputs X, Y and Z.
(4 marks)
(b) Briefly describe the term ‘Selection control structure’. (2 marks)
Study the following algorithm carefully.
Step Algorithm
… ……
1 IF Mark < 30 THEN Grade = D
2 IF Mark >= 30 and Mark < 50 THEN Grade = C
3 IF Mark >= 50 and Mark < 75 THEN Grade = B
4 IF Mark >= 75 and Mark <= 100 THEN Grade = A
… ……

(c) Write down the step that will be executed and the output of the algorithm if Mark
is (6 marks)
(i) 55
(ii) 90
(iii) –10
Answers
(a) IF X > Y THEN
IF Z > X THEN
X is the middle number
ELSE IF Y > Z THEN
Y is the middle number
ELSE Z is the middle number (2)
ELSE IF Z > Y THEN
Y is the middle number
ELSE IF X > Z THEN
X is the middle number
ELSE Z is the middle number (2)
(b) The selection control structure directs the flow of the algorithm to one of the
many alternate processes based on a condition. (2)
(c) (i) Step 3 will be executed (1) and the output is B. (1)
(ii) Step 4 will be executed (1) and the output is A. (1)
(iii) Step 1 will be executed (1) and the output is D. (1)

Computer & Information Technology for HKCEE 14 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L02Q004)
(a) Briefly describe the term ‘Iteration control structure’. (2 marks)
Study the following algorithm carefully.
Step Algorithm
……
1 Input a number X
2 WHILE X >= 0
3 BEGIN
4 Output X
5 Decrease the value of X by 2
6 END
……
(b) Write down the number of times Step 4 will be executed, the corresponding
output(s) and the final value of X, if the input number X is (10 marks)
(i) 5
(ii) 11
(iii) 14
(iv) –5
Answers
(a) The iteration control structure will carry out one or more steps repeatedly. (1) A
condition is used to control the number of iterations. (1)
(b) (i) Step 4 will be executed for 3 times, (0.5) outputs are 5, 3 and 1, (1) final
value of X is –1. (0.5)
(ii) Step 4 will be executed for 6 times, (0.5) outputs are 11, 9, 7, 5, 3 and 1, (2)
final value of X is –1. (0.5)
(iii) Step 4 will be executed for 8 times, (0.5) outputs are 14, 12, 10, 8, 6, 4, 2, 0,
(2) final value of X is –2. (0.5)
(iv) Step 4 will not be executed, (0.5) there is no output, (1) final value of X is –
5. (0.5)

Computer & Information Technology for HKCEE 15 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L02Q005)
(a) Arrange the following program lines in the correct order, so that the program can
be used to find the average score of 40 students. (3 marks)
(1) Add the score of this test paper to variable TOTAL
(2) Calculate AVERAGE by dividing TOTAL by 40
(3) DoWhile there is another test paper
(4) EndDo
(5) Output AVERAGE
(6) Read the score of this test paper
(7) Set variable TOTAL to 0
(8) Skip this test paper
Study the following algorithm.

Step Algorithm
… ……
1 X=1
2 DoWhile X < 50
3 Output X
4 X=X+X
5 EndDo
… ……

(b) Write down the outputs of the algorithm. (6 marks)

Study the following algorithm.


……
M=1
N = 10
C=0
DoWhile N > M
M=M+2
N=N–1
C=C+1
EndDo
……

(c) Trace the values of variables M, N and C after the execution of the above
algorithm. (3 marks)
Answers
Computer & Information Technology for HKCEE 16 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(a) (7) → (3) → (6) → (1) → (8) → (4) → (2) → (5) (All correct: 3)
(b) 1, 2, 4, 8, 16, 32 (@1 mark)
(c) M = 7; N = 7; C = 3 (@1 mark)

(U01C14L02Q006)
(a) Arrange the following steps in the correct order, so that the algorithm can be
used to find out the maximum score of 40 students. (4 marks)
(1) If SCORE is greater than variable MAXIMUM then
(2) DoWhile there is another score
(3) EndDo
(4) Output MAXIMUM
(5) Read the SCORE
(6) Set variable MAXIMUM to –1
(7) Assign value of SCORE to variable MAXIMUM

(b) Draw a flowchart to represent the algorithm in (a). (4 marks)


Answers
(a) (6) → (2) → (5) → (1) → (7) → (3) → (4) (All correct: 4 marks)
(b)

Start

MAXIMUM = – 1

False
Another score?

True

Input SCORE (4)

Output MAXIMUM
False
SCORE > MAXIMUM

True End

MAXIMUM = SCORE

Computer & Information Technology for HKCEE 17 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L02Q007)
Study the following algorithm carefully.

Step Algorithm
1 Input A
2 Input B
3 Set C to 2
4 DoWhile C < A
5 If A is divisible by C and B is divisible by C
6 Then output C
7 Increment C by 1
8 EndDo

(a) (i) Identify the steps using the selection control structure. (2 marks)
(ii) What is the condition of the selection control structure? (1 mark)

(b) (i) Identify the steps using the iteration control structure. (2 marks)
(ii) What is the condition of the iteration control structure? (1 mark)

(c) What are the outputs if the inputs A and B are (4 marks)
(i) 6 and 12 respectively?
(ii) 8 and 12 respectively?
(iii) 18 and 24 respectively?

(d) What is the objective of the algorithm? (2 marks)


Answers
(a) (i) steps 5 and 6 (1 +1)
(ii) A is divisible by C and B is divisible by C (1)
(b) (i) steps 4 to 8 (2)
(ii) C < A (1)
(c) (i) 2, 3 and 6 (0.5 + 0.5 + 0.5)
(ii) 2 and 4 (0.5 + 0.5)
(iii) 2, 3 and 6 (0.5 + 0.5 + 0.5)
(d) To find the common factors of two input numbers. (2)

Computer & Information Technology for HKCEE 18 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L02Q008)
The table below shows the price list of a concert.

Age Time Price ($)


0 to 10 At or before 17:00 25
After 17:00 40
11 or above At or before 17:00 50
After 17:00 90

A student designs the following algorithm to determine the price.

If AGE < 10
Then If TIME < 17
Then PRICE = 40
Else PRICE = 25
Else If TIME < 17
Then PRICE = 50
Else PRICE = 90
Output PRICE

(a) What are the actual output and the expected output of the algorithm if AGE and
TIME are (3 marks)
(i) 5 and 18 respectively?
(ii) 10 and 11 respectively?
(iii) 20 and 17 respectively?
(b) Correct and rewrite the algorithm. (5 marks)
(c) Suggest different sets of test data to test the algorithm amended in (b) by
completing the table below. (4 marks)
Test data Expected output Objective of test data
Age Time

Computer & Information Technology for HKCEE 19 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

Answers
(a) (i) Actual output is 25. (0.5) Expected output is 40. (0.5)
(ii) Actual output is 50. (0.5) Expected output is 25. (0.5)
(iii) Actual output is 90. (0.5) Expected output is 50. (0.5)
(b) IF AGE <= 10 (1)
Then IF TIME <= 17 (1)
Then PRICE = 25 (1)
Else PRICE = 40 (1)
Else IF TIME <= 17 (1)
Then PRICE = 50
Else PRICE = 90
Output PRICE
(c)
Test data Expected Objective of test data
Age Time output
5 10 25 To test the case of price $25
5 18 40 To test the case of price $40
15 10 50 To test the case of price $50
15 18 90 To test the case of price $90
(1 mark per row, any reasonable answers)

Computer & Information Technology for HKCEE 20 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

(U01C14L02Q009)
A student designs the following algorithm to find out the minimum score of 40
students.

Set variable X to 100


Set variable Y to 0
DoWhile Y < 40
Input Z
If Z < X then
Assign the value of Z to variable X
Increment Y by 1
EndDo
Output X

(a) Suggest TWO ways to improve the readability of the algorithm. (2 marks)
(b) Rewrite the algorithm according to your suggestions in (a). (3 marks)
(c) Amend the algorithm in (b), so that it can be used to find the maximum score of
40 students. (6 marks)

Computer & Information Technology for HKCEE 21 © Pearson Education Asia Limited 2004
(Core Module)
Chapter 14 Using High-Level Programming Language Question Bank

Answers
(a) Use meaning names for variables. (1) Use indentation to indicate a block of
statements. (1) (any reasonable answers)
(b) Set variable MINIMUM to 100
Set variable COUNTER to 0
DoWhile COUNTER < 40
Input SCORE
If SCORE < MINIMUM then
Assign the value of SCORE to variable MINIMUM
Increment COUNTER by 1
EndDo
Output MINIMUM
(change variable X to MINIMUM; (1) change variable Y to COUNTER; (1) change
variable Z to SCORE (1))
(c) Set variable MAXIMUM to –1
Set variable COUNTER to 0
DoWhile COUNTER < 40
Input SCORE
If SCORE > MAXIMUM then
Assign the value of SCORE to variable MAXIMUM
Increment COUNTER by 1
EndDo
Output MAXIMUM
(Set variable MAXIMUM to –1; (2) If SCORE > MAXIMUM; (2) Assign the value
of SCORE to variable MAXIMUM (2))

Computer & Information Technology for HKCEE 22 © Pearson Education Asia Limited 2004
(Core Module)

Das könnte Ihnen auch gefallen