You are on page 1of 4

Chapter 7 Debugging and Testing Question Bank

Chapter 7 Debugging and Testing


Multiple Choice Questions

(U03C07L01Q001)
Which of the following statements have syntax errors? (x, y and z are integer variables.)
(1) x; y; z := 0;
(2) x := y := z := 0;
(3) x := 0; y := 1; z := 2;
A. (1) and (2) only
B. (1) and (3) only
C. (2) and (3) only
D. (1), (2) and (3)
Answer
A

Computer & Information Technology for HKCEE 1 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 7 Debugging and Testing Question Bank

Conventional Questions

(U03C07L02Q001)
A program Coins changes the input amount of money to $5, $1, 50-cent and 10-cent coins such
that the number of coins is the least.

Sample output:
Enter an amount of money ($0.1-$49.9):$22.8
$22.8 can changed to :
$5 coin × 4
$1 coin × 2
50-cent coin × 1
10-cent coin × 3

A student writes the following program to do the above job.

1 program Coins;
2 var
3 Amount : integer;
4 begin
5 write(‘Enter an amount of money ($0.1-$49.9): $’);
6 readln(Amount);
7 writeln(‘$’, Amount, ‘ can changed to:’);
8 writeln(‘$5 coin x ’, Amount / 5:0:0);
9 writeln(‘$1 coin x ’, Amount mod 5);
10 writeln(‘50-cent coin x ’, (Amount * 10) div 5);
11 writeln(‘10-cent coin x ’, (Amount * 10) mod 5)
12 end.

However, there are several errors in the program. Find out the errors and correct them. (5 marks)
Answers
Line number Corrected statements
3 Amount : real;
7 writeln(‘$’,Amount:0:1, ‘ can change to:’);
8 writeln(‘$5 coin x ’, trunc(Amount) div 5);
9 writeln(‘$1 coin x ’, trunc(Amount) mod 5);
10 writeln(‘50-cent coin x ’, trunc(Amount * 10) mod 10 div
5);
11 writeln(‘10-cent coin x ’, trunc(Amount * 10) mod 5)

Computer & Information Technology for HKCEE 2 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 7 Debugging and Testing Question Bank

(U03C07L02Q002)
Complete the dry run table of the following program segments. (Assume X = -1, Y = 0 and Z = 2.)
= (a) (b) (c) (d) (e)
...... ...... ...... ...... ......

Z := X; X := X + 2; X := X+Y; X := Y+Z; X := Z-Y;


X := Y; Y := Y * 3; Y := Y+Z; Y := X+Z; Y := X-Z;
Y := Z; Z := X + Y; Z := Z+X; Z := X+Y; Z := Y-X;
...... ...... ...... ...... ......

(a) (b) (c) (d) (e)


X Y Z X Y Z X Y Z X Y Z X Y Z
-1 0 2 -1 0 2 -1 0 2 -1 0 2 -1 0 2

(15 marks)
Answers
(a) (b) (c) (d) (e)
X Y Z X Y Z X Y Z X Y Z X Y Z
-1 0 2 -1 0 2 -1 0 2 -1 0 2 -1 0 2
-1 1 -1 2 2
0 0 2 4 0
-1 1 1 6 -2

Computer & Information Technology for HKCEE 3 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 7 Debugging and Testing Question Bank

(U03C07L02Q003)
There are several mistakes in the following program. Identify and correct them.
Line Number Statement
1. CircleArea;
2. const
3. Pi = 3.14
4. variable
5. Radius = integer;
6. Area = real;
7. begin
8. write(Enter the radius: );
9. Readln Radius;
10. Area = Radius * Radius * Pi;
11. write(The area is );
12. writeln(Area)
13. end;

(12 marks)
Answers
Line Number Statement
1. program CircleArea;
3. Pi = 3.14;
4. var
5. Radius : integer;
6. Area : real;
8. write(‘Enter the radius: ’);
9. readln(Radius);
10. Area := Radius * Radius * Pi;
11. write(‘The area is ’);
13. end.

Computer & Information Technology for HKCEE 4 © Pearson Education Asia Limited 2004
(Module A2)

You might also like