Download ICT Programming Pre

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Addition wikipedia , lookup

Law of large numbers wikipedia , lookup

Halting problem wikipedia , lookup

Expected value wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
ICT Programming Pre-test 1
Name:
(
)
ICT No.:
Section A: MC Questions
1. Which line of the following pseudocode segment can be deleted without affecting the result?
Line number
A.
Line 10
Statement
10
C = 60
20
E = 70
30
M = 80
40
T = 95
50
M=M–T
60
INPUT C
70
C=C+E
80
OUTPUT (C + E)
90
OUTPUT M
B.
Line 20
C.
Line 30
D.
Line 40
2.
Which of the following errors is less likely to happen while the program is running?
A. Run-time error
B. Logic error
C. Syntax error
D. Overflow
3.
Which of the following is/are advantage(s) of breaking a problem into smaller tasks?
A.
C.
4.
(1) Programs are easier to develop.
(3) Programs are faster.
(1) only
B.
(2) and (3) only
D.
(2) Programs are easier to debug.
(1) and (2) only
(1), (2) and (3)
Y=5*x-5
Given that X is a number between 0 and 1 inclusively. What is the range of Y?
A. between 0 and 1 inclusively
B. between -5 and 0 inclusively
C. between 0 and 5 inclusively
D. between 5 and 10 inclusively
1991 1A#37
5.
var X, Y: integer;
begin
X:= 5;
Y:= 10;
if (X <= 7) and (Y >= 8) then X:= 7;
if (X < 7) or (Y < 8) then Y:= 7;
end.
What is the value of Y after the execution of the above Pascal program segment?
P.1
A.
D.
5
10
B.
E.
7
undetermined
C.
8
1998 1A#15
6. Below are different stages in software development:
1
problem analysis
2
program coding
3
program testing
4
algorithm design
5
problem definition
Which of the following gives the correct order of stages?
A. 5 2
4
1
3
B.
C.
D.
E.
7.
5
3
3
4
l
1
2
1
4
4
5
3
2
2
4
2
3
5
1
5
An algorithm is
A. a computer program.
C. a definition of problem.
B.
D.
a set of ordered steps used to solve a problem.
a graphical representation of the steps.
1992 1A#42(modified)
8. Which of the following program segment(s) interchange(s) the contents of variables A and B?
(1) A := B;
(2) A := A - B;
(3) C := A;
B := A;
B := A + B;
A := B;
A := B - A;
B := C;
A. (1) only
B. (2) only
C. (1) and(3)only
D. (2) and(3) only
E. (1), (2) and(3)
1996 1A#21
9. Which of the following would increase the readability of a program?
(1) use of comment statements
(2) use of indentation
(3) use of subprograms
A. (1) only
B. (2) only
C. (1) and (2) only
D. (2) and (3) only
E. (1), (2) and (3)
1993 1A#37
10.
...
P.2
if not((x=1 and y=0) or (x=0 and y=1)) then x:= x + 1;
if x>0 then y:= y – 1;
...
If x = 0 and y = 0, then the values of x and y after the execution of the above program segment are
respectively
A. 0 and –1.
B. 1 and 0.
C. 0 and 0.
D. 1 and –1.
E. 1 and 1.
1994 1A#40 (modified)
11.
var x,a,n:integer;
begin
a:=0;
n:=3;
for x:=1 to 10 do
begin
if x>n then
begin
n:=n+2;
a:=a+1;
end;
end;
output a;
end.
What is the output of the above program segment?
A. 2
B. 3
D. 5
E. 6
C.
4
1994 1A#42 (modified)
12.
begin
if ‘computer’<’COMPUTER’ then output (‘LESS
’);
if ‘advisers’<’COMPUTER’ then output (‘LESS
’);
if ‘computer’<’advisers’ then output (‘LESS
’);
if ‘computer’>’advisers’ then output (‘MORE
end.
What is the output of the above program segment?
A. LESS
LESS
LESS
B. LESS
C. LESS
LESS
D. LESS
E. MORE
’);
LESS
MORE
MORE
1995 1A#33
13.
var X,Y,Z:real;
…
P.3
input (X);
if X>=0 then Y := 1;
if X<0 then Y := -1;
Z := X*Y;
After executing the above program segment, the value of Z
A. will be a positive integer.
B. will be a negative real number.
C. will be equal to the absolute value of X.
D. will have the opposite sign to X.
E. will have the same sign as X.
1995 1A#34
14. Which of the following logical expression has a false value?
A. NOT(5<=2) AND ((2*3<=4+2) OR (3<-4))
B.
C.
D.
E.
NOT((5<=2) AND (2*3<=4+2)) OR (3<-4)
((2<3+1) AND (5<4+2)) OR (7<2)
(3<20-2) AND ((2*3<8+1) OR (2<-1))
NOT(5<20) OR NOT(1<>3)
1995 1A#37
15.
var k,x,y,z:integer;
…
x:=1; y:=2; z:=3;
for k:=1 to 2 do
begin
z:=x; x:=y; y:=z
end;
output (x,’ ’,y,’ ’,z);
What is the output of the above program segment?
A. 2 1
2
B. 2
1
1
D. 1 2
2
E. 1
2
3
Refer to the flow chart below to answer Q.16 - 20,
C.
3
2
1
P.4
(1992 CE 1A)
16. If the input value of X is 6, what is the value of X when the flowchart reaches END?
A. -4
B. 0
C. 6
D. 16
E. 20
17. If the input value of X is –2, what is the value of C when the flowchart reaches END?
A. 0
B. 1
C. 2
D. 3
E. 4
18. If the input value of X is 28, what is the value of C when the flowchart reaches END?
A. 0
B. 1
C. 2
D. 3
E. 4
19. Which of the following values is not a possible output value of X?
A. -2
B. 0
C. 2
D. 5
E. 7
20. Which of the following input values of X will give rise to an infinite loop?
A. -20
B. 27
C. 29
D. 300
E. None of the above
P.5
Answer of Section A:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Section B: Conventional Questions:
1. Calculate the sum of a set of numbers:
1
2
3
program summation;
var NoOfNumber, Count, Number, Sum : integer;
begin
4
5
6
output (‘How many numbers?’);
input (NoOfNumber);
sum := 0;
7
8
9
10
11
12
13
for count := 1 to NoOfNumber do
begin
output (‘Enter a number:’);
input (Number);
sum := sum + number
end;
input (‘Sum of ‘, NoOfNumber, ‘ numbers is ‘, sum)
14
end.
(a) Suppose the following five numbers are to be added:
15, 17, 11, 21, 29
Write down the value of Sum after the execution of line 11 for each pass.
Number
Sum
st
1 pass
2nd pass
3rd pass
4th pass
5th pass
(b) What is wrong if we put “Sum := 0” in the loop between line 8 and 9?
____________________________________________________________________
____________________________________________________________________
P.6
2.
(a) (i)
You are going to develop a program such that it will let you input a number and then it
will find the all the common factor for you. e.g. When you input 12 it will output 2, 2, 3.
START
(i)
(v)
(ii)
(iv)
(iii)
YES
(vii)
YES
(vi)
END
Fill the following statements in the appropriate boxes.
A
Count = 2
B
Count = Count + 1
C
If Num is divisible by Count?
D
Input Num
E
count < Num?
F
Num = Num / Count
G
Output Count
(i)
(ii)
(iii)
(iv)
(v)
(vi)
(vii)
(7 marks)
(a) (ii) For the above flowchart, apart from non-integer input, can you think of any situation that
the system will not work properly?
(2 mark)
P.7
2003 CE 1B #8
3. The algorithm below displays all prime numbers that lie between two numbers inclusively.
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Declare NUM, COUNT, LOWER and UPPER to be integer variables.
Read in the lower limit and upper limit into variables LOWER and UPPER respectively.
Assign the value of variable LOWER to variable NUM.
As long as the value of variable NUM is less than or equal to the value of variable
UPPER, do steps 5 to 9.
Assign 2 to the variable COUNT.
As long as the value of variable NUM is not divisible by the value of variable
COUNT, do step 7.
Increase the value of variable COUNT by 1.
if the value of variable NUM equals the value of variable COUNT, display the value
of variable NUM.
Step 9:
Increase the value of variable NUM by 1.
Convert the algorithm into a flowchart.
P.8
P.9