Programming – O Level Computer Science (2210)

174 questions · page 11 of 12 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
151
2210/23/O/N/17 · Question 2Oct/Nov 2017Paper 2384 marks
Loading question…
Question text

2
This section of program code asks for 80 numbers between 100 and 1000 to be entered. It checks
that the numbers are in the correct range, and stores them in an array. It counts how many of the
numbers are larger than 500 and then outputs the result when the program is finished.
1 Count = 0
2 FOR Index = 1 TO 80
3
INPUT 'Enter a number between 100 and 1000', Number
4
WHILE Number = 99 AND Number = 1001
5
INPUT 'This is incorrect, please try again', Number
6
ENDWHILE
7
Num[80] = Number
8
IF Number > 500 THEN Count = Count + 1
9 UNTIL Index = 80
10 PRINT Index
11 PRINT ' numbers were larger than 500'
There are four lines of code that contain errors.
State the line number for each error and write the correct code for that line.
Error 1 Line Number …
Correct Code …
Error 2 Line Number …
Correct Code …
Error 3 Line Number …
Correct Code …
Error 4 Line Number …
Correct Code …
[4]

152
2210/23/O/N/17 · Question 4Oct/Nov 2017Paper 237 marks
Loading question…
Question text

4
(a) Four pseudocode descriptions and five pseudocode statements are shown. Draw one line to
link each pseudocode description to the correct pseudocode statement. Not all pseudocode
statements will be used.
Pseudocode description
Pseudocode statement
A loop that will iterate at least
once.
FOR…TO…NEXT
A conditional statement to deal
IF…THEN…ELSE…ENDIF
with many possible outcomes.
WHILE…DO…ENDWHILE
A loop that will iterate a set
number of times.
CASE…OF…OTHERWISE…ENDCASE
REPEAT…UNTIL
A conditional statement with
different outcomes for true
and false.
[4]
(b) Write an algorithm in pseudocode, using a single loop, to print 50 names that have been
stored in an array.
…
…
…
…
…
…
…
…
…
… [3]

153
2210/21/M/J/17 · Question 1May/June 2017Paper 2120 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
Name two constants you used for Task 1 and state the value of each one.
Constant 1 …
Value …
Constant 2 …
Value …
[2]
(ii)
Name two arrays you used for Task 2 and state the purpose of each one.
Array 1 …
Purpose …
…
Array 2 …
Purpose …
…
[2]
(b) Write an algorithm to complete Task 1, using either pseudocode, programming statements
or a flowchart.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
154
2210/21/M/J/17 · Question 2May/June 2017Paper 214 marks
Loading question…
Question text

2
This section of program code asks for 50 numbers to be entered. The total and average of the
numbers are calculated.
1
Total = 0
2
Counter = 50
3
PRINT ′When prompted, enter 50 numbers, one at a time′
4
REPEAT
5
PRINT ′Enter a number′
6
INPUT Number
7
Total + Number = Total
8
Number = Number + 1
9
UNTIL Counter = 50
10
Average = Number * Counter
11
PRINT ′The average of the numbers you entered is ′, Average
There are four errors in this code.
State the line number for each error and write the correct code for that line.
Error 1 Line number …
Correct code …
Error 2 Line number …
Correct code …
Error 3 Line number …
Correct code …
Error 4 Line number …
Correct code …
[4]

155
2210/21/M/J/17 · Question 6May/June 2017Paper 215 marks
Loading question…
Question text

6
This flowchart inputs a range of temperatures in degrees Fahrenheit.
As each temperature is input, it is compared with the previous highest temperature. If it is higher
than the current highest, it replaces the previous highest temperature and then it is converted to
degrees Celsius.
For ease of calculation, the final step of the Fahrenheit to Celsius conversion has been
approximated as division by 2.
When –1 is entered, the input process stops and the highest temperature (in both Fahrenheit and
Celsius) is output.
START
HighF
-100
HighC
-100
INPUT TempF
No
No
Is TempF
Is TempF
> HighF?
= -1?
Yes
Yes
HighF
TempF
HighC
(TempF-32)/2
OUTPUT 'The highest temperature is, ',
HighF, ' Fahrenheit, ',
HighC, ' Celsius.'
END
Complete the trace table for the input data:
68, 46, 50, 86, 65, 50, 40, 30, –1
HighF
HighC
TempF
OUTPUT
[5]

156
2210/22/M/J/17 · Question 1May/June 2017Paper 2220 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
For a variable that you have used to record information about the cost of the outing in
Task 1, state the name, data type and its use.
Variable name …
Data type …
Use …
[3]
(ii)
State two constants that you could have used for Task 1. Give the value that would be
assigned to each one and explain what it is used for.
Constant 1 name …
Value 1 …
Use 1 …
Constant 2 name …
Value 2 …
Use 2 …
[6]
(b) Explain how you would need to change your calculation in Task 1 if each carer were paid
$20.00 for coming on the outing.
…
…
…
…
…
… [2]
(c) Write an algorithm to complete Task 2, using either pseudocode, programming statements
or a flowchart. You can assume that Task 1 has been completed. You do not need to produce
the list of people on the outing.
…
…
…
…
…
…
…
…

157
2210/22/M/J/17 · Question 4May/June 2017Paper 225 marks
Loading question…
Question text

4
An algorithm has been written in pseudocode to input 100 numbers and print out the sum.
A REPEAT … UNTIL loop has been used.
Count ← 0
Sum ← 0
REPEAT
INPUT Number
Sum ← Sum + Number
Count ← Count + 1
UNTIL Count > 100
PRINT Sum
(a) Find the error in the pseudocode and suggest a correction.
Error …
Correction …
…
[2]
(b) Rewrite the correct algorithm using a more suitable loop structure.
…
…
…
…
…
…
… [3]

158
2210/22/O/N/16 · Question 1Oct/Nov 2016Paper 2220 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
For three of the variables that you have used in Task 1, state the name, type and its use.
Variable 1 name …
Type …
Use …
Variable 2 name …
Type …
Use …
Variable 3 name …
Type …
Use … [3]
(ii)
Name and describe the data structure(s) that you have used to store the donation totals
for each charity. Explain why you chose your data structure(s).
Name of data structure(s) …
Description …
…
Reason …
… [3]
(b) Write an algorithm to complete Task 2, using either pseudocode, programming statements
or a flowchart. You can assume that Task 1 has been completed.
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
159
2210/22/O/N/16 · Question 2Oct/Nov 2016Paper 228 marks
Loading question…
Question text

2
Read this section of program code that inputs positive numbers, discards any negative numbers
and then outputs the average. An input of zero ends the process.
1
Total = 0
2
Counter = 100
3
REPEAT
4
REPEAT
5
INPUT Num
6
UNTIL Num < 0
7
Total = Total + 1
8
Counter = Counter + Num
9
UNTIL Num = 0
10
Average = Total / (Counter - 1)
11
Print Average
There are four errors in this code.
Locate these errors and suggest a correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
… [8]

160
2210/22/O/N/16 · Question 3Oct/Nov 2016Paper 224 marks
Loading question…
Question text

The flowchart below inputs an integer. The predefined function DIV gives the value of the division,
3
for example Z ← 11 DIV 3 gives the value Z = 3. The predefined function MOD gives the value
of the remainder, for example Z ← 11 MOD 3 gives the value Z = 2.
67$57
,1387 ;
1R
Is X >
"
<HV
$
; ',9
287387 ;
%
; 02'
(1'
287387 %
;
$
Complete a trace table for each of the two input values 33 and 75.
Trace table for input value 33
X
A
B
OUTPUT
Trace table for input value 75
X
A
B
OUTPUT
[4]

161
2210/22/O/N/16 · Question 4Oct/Nov 2016Paper 226 marks
Loading question…
Question text

IF ... THEN ... ELSE ... ENDIF and CASE ... OF ... OTHERWISE ... ENDCASE
4
are two different conditional statements that you can use when writing pseudocode.
Explain, using examples, why you would choose to use each conditional statement.
Example 1 …
…
…
…
…
…
Reason for choice …
…
…
Example 2 …
…
…
…
…
…
Reason for choice …
…
… [6]
Question 5 begins on page 10.

162
2210/23/O/N/16 · Question 1Oct/Nov 2016Paper 2320 marks
Loading question…
Question text

1
(a) All variables, constants and other identifiers should have meaningful names.
For four of the variables, constants or arrays that you used in Task 1, state the name, data
structure, data type and its use.
Name 1 …
Data structure …
Data type …
Use …
Name 2 …
Data structure …
Data type …
Use …
Name 3 …
Data structure …
Data type …
Use …
Name 4 …
Data structure …
Data type …
Use … [8]
(b) Write an algorithm to complete Task 2, using either pseudocode, programming statements
or a flowchart. You can assume that Task 1 has been completed and that there are three
candidates for class captain.
…
…
…
…
…
…
…
…
…

163
2210/23/O/N/16 · Question 2Oct/Nov 2016Paper 238 marks
Loading question…
Question text

2
Read this section of program code that:
•
inputs 10 numbers
•
checks whether each number is within a specified range
•
totals the numbers within the range and outside the range
1
InRange = 0
2
OutRange = 1000
3
FOR Count = 1 TO 10
4
INPUT Num
5
IF Num > 10 AND Num < 20 THEN InRange = InRange + 1
6
ELSE OutRange = OutRange - 1
7
Count = Count + 1
8
NEXT X
9
PRINT InRange, OutRange
(a) There are four errors in this code.
Locate these errors and suggest a correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
… [4]
(b) Decide, with reasons, whether the numbers 10 and 20 are within or outside the range.
Within
Outside
Number
Reason
range (✓)
range (✓)
10
… ..
… ..
20
… ..
… ..
[4]

Advertisement
164
2210/23/O/N/16 · Question 3Oct/Nov 2016Paper 235 marks
Loading question…
Question text

3
The flowchart below inputs the price of an item under $10. The change from a $10 note is output.
Any amount less than 5 cents is rounded up to 5 cents.
The predefined function INT rounds a number down to the nearest whole number; for example
Z ← INT(5.7) gives the value Z = 5
START
INPUT Price
Change
10 – Price
Is
Yes
Change
Dollars
INT(Change)
>= 1?
No
Change
Change – INT(Change)
OUTPUT Dollars,
" dollars"
Is
Yes
Change
Change
Change – 0.5
>= 0.5?
No
OUTPUT "One 50
cent coin"
TenCents
INT(Change * 10 + 0.5)
OUTPUT TenCents,
" ten cent coins"
Is Change*10 –
OUTPUT "One 5
Yes
TenCents
cent coin"
> 0?
No
END
Complete the trace table for the input data: 6.29
Price
Change
Dollars
TenCents
OUTPUT
[5]

165
2210/23/O/N/16 · Question 5Oct/Nov 2016Paper 236 marks
Loading question…
Question text

REPEAT ... UNTIL
WHILE ... DO ... ENDWHILE are two different loop
5
and
structures you can use when writing pseudocode.
Explain, using examples, why you would choose to use each type of loop.
Example 1 …
…
…
…
Reason for choice …
…
…
Example 2 …
…
…
…
Reason for choice …
…
… [6]

Advertisement