Programming – IGCSE Computer Science (0478)
270 questions · page 17 of 18 · Clear filters
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]
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
For one variable that you have used to record the information about a single boat in
Task 1, state the name, data type and its use.
Variable name …
Data type …
Use …
[3]
(ii)
State one constant and its value that you could have used for Task 1.
Constant name …
Value …
[2]
(b) Give two different validation checks you could have used for data entry in Task 1. For each
check explain why it could be used and provide a set of data for testing.
Validation check 1 …
…
Reason for choice …
…
Set of test data …
…
Validation check 2 …
…
Reason for choice …
…
Set of test data …
…
[6]
(c) Write an algorithm to complete Task 3, using either pseudocode, programming statements
or a flowchart. You may assume Task 2 has been completed.
…
…
…
…
…
…
…
Question text
3
The following diagram shows four data structures and four descriptions.
Draw a line to connect each data structure to the correct description.
Data structure
Description
A collection of related data
Constant
A value that can change whilst a
Array
program is running
A value that never changes whilst a
Table
program is running
A series of elements of the same
Variable
data type
[3]
Question text
4
IF … THEN … ELSE … ENDIF is one type of conditional statement used when writing
pseudocode.
Identify and describe another type of conditional statement that you could use when writing
pseudocode. Give a reason why you would use this type of conditional statement.
Conditional statement …
…
…
…
Description …
…
…
…
Reason …
…
[4]
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.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
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]
Question text
5
(a) Describe the purpose of each statement in this algorithm.
1 TO 300
FOR I
INPUT Name[I]
NEXT I
…
…
…
…
… [2]
(b) Identify, using pseudocode, another loop structure that the algorithm in part (a) could have
used.
…
… [1]
(c) Write an algorithm, using pseudocode, to input a number between 0 and 100 inclusive. The
algorithm should prompt for the input and output an error message if the number is outside
this range.
…
…
…
…
…
…
…
…
…
… [3]
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.
…
…
…
…
…
…
…
…
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]
Question text
1
(a) All variables and other identifiers should have meaningful names.
(i)
Declare the array used to store the reaction times for the whole school.
… [1]
(ii)
Change this declaration so the array can only hold records for a sample of 50 students.
… [1]
(iii)
Explain why an array is an effective data structure for storing the reaction time records.
…
…
…
… [2]
(b) Write an algorithm to complete Task 1 for the whole school, using either pseudocode,
programming statements or a flowchart. DO NOT include any validation routines.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [3]
(c) Identify three different types of test data you used to test the validation checks on the age
input in Task 1. For each type, give an example of appropriate data.
Type of test data
Example data
[6]
(d) Explain how you calculated and outputted the average reaction time based on the user
inputs of age and school house, as part of Task 3. Any programming statements used in your
answer must be fully explaine
Question text
2
Read this section of code that inputs the ages of people entering an event. The input sequence is
ended by inputting a negative value for age. The code outputs the number of people at the event
over the age of 18.
01
Num18 = 0
02
INPUT Age
03
WHILE Age >= 0 DO
04
IF Age >= 18 THEN
05
Num18 = Num18 + Age
06
ENDIF
07
ENDWHILE
08
PRINT Num18 - Age
There are four errors in this code.
Locate these errors and suggest code correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
Question text
3
There is a program that stores the following data:
•
EmployeeID, an employee ID which must be two letters followed by 4 numbers, e.g. TY4587
•
Manager, whether the employee is a manager or not
•
AnnualHoliday, number of whole days’ annual holiday
•
PayGrade, the employee’s pay grade which must be a single letter A–F
Complete the following table to identify:
•
The most appropriate data type for each variable
•
An appropriate validation check for each variable. You must use a different validation check
for each variable.
Variable
Data type
Appropriate validation check
EmployeeID
Manager
AnnualHoliday
PayGrade
[8]
Question text
5
(a) Rewrite the following pseudocode algorithm using a WHILE … DO … ENDWHILE loop.
INPUT Num
FOR Counter ← 1 TO 12
Num ← Num * Counter
A[Counter] ← Num
NEXT
…
…
…
…
…
…
…
…
…
… [4]
(b) Explain the differences between a WHILE … DO … ENDWHILE and a REPEAT … UNTIL
loop.
…
…
…
…
…
…
…
… [4]
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.
…
…
…
…
…
…
…
…
…
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]