Programming – IGCSE Computer Science (0478)
Quick quiz: 10 random questions from this topic. Answer them all, then open the Summary.
Question text
5
An algorithm has been written in pseudocode to check if a new password is in a list of previously
used passwords OldList[]
If the password is not found, the new password will be stored at the end of the list to replace
"XXXX" already stored there.
01
OUTPUT "Enter your new password "
02
INPUT NewPassword
1
03
Posn
FALSE
04
Found
05
REPEAT
06
IF Password = OldList[Posn]
07
THEN
TRUE
08
Found
Posn + 1
09
ELSE Posn
10
ENDIF
11
UNTIL Found AND OldList[Posn] = "XXXX"
12
IF Found
13
THEN
14
OUTPUT "Password has been used before"
15
ELSE
16
INPUT "New password accepted"
NewPassword
17
OldList[Posn]
18
ENDIF
(a) Identify the three errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
[3]
(b) Complete this flowchart for the corrected algorithm:
START
STOP
[6]
Question text
6
An algorithm has been written in pseudocode.
01 DECLARE A[1:10] : STRING
02 DECLARE T : STRING
03 DECLARE C, L : INTEGER
10
04 L
1 TO L
05 FOR C
06
OUTPUT "Please enter name "
07
INPUT A[C]
08 NEXT C
1 TO L
09 FOR C
1 TO 9
10
FOR L
11
IF A[L] > A[L + 1]
12
THEN
A[L]
13
T
A[L + 1]
14
A[L]
T
15
A[L + 1]
16
ENDIF
17
NEXT L
18 NEXT C
1 TO L
19 FOR C
20
OUTPUT "Name ", C, " is ", A[C]
21 NEXT C
(a) State the purpose of this pseudocode algorithm.
…
… [1]
(b) State four processes in this algorithm.
1 …
…
2 …
…
3 …
…
4 …
…
[4]
(c) Meaningful identifiers have not been used in this algorithm.
Suggest suitable meaningful identifiers for:
The array:
A …
The variables:
T …
C …
L …
[3]
(d) State two other ways the algorithm can be made easier to understand and maintain.
1 …
…
2 …
…
[2]
Question text
10 A weather station takes temperature readings once an hour for a week. These temperatures are
stored in a two-dimensional (2D) array Temperatures[]
Each column contains 24 readings for a single day. The first temperature is recorded at 00:00 and
the final temperature at 23:00. There are seven columns, one for each day of the week, starting
with Monday and ending with Sunday.
The variables MaxDay, MinDay and AvDay are used to store the maximum, minimum, and
average temperatures for a day. The variables MaxWeek, MinWeek and AvWeek are used to store
the maximum, minimum, and average temperatures for the week.
The array has already been set up and the data stored.
Write a program that meets the following requirements:
•
finds the maximum and minimum temperatures for each day
•
calculates the average temperature for each day
•
outputs for each day:
–
name of the day, for example Monday
–
maximum temperature
–
minimum temperature
–
average temperature
•
finds the maximum and minimum temperatures for the week
•
calculates the average temperature for the week
•
outputs:
–
maximum temperature for the week
–
minimum temperature for the week
–
average temperature for the week.
All temperatures output must be rounded to two decimal places.
You must use pseudocode or program code and add comments to explain how your code works.
All inputs and outputs must contain suitable messages.
You do not need to declare any arrays or variables; you may assume that this has already been
done.
You do not need to initialise the data in the array Temperatures[]
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
7
The string operation SUBSTRING(Quote, Start, Number) returns a string from Quote
beginning at position Start that is Number characters long. The first character in Quote is in
position 1.
Write pseudocode statements to:
•
store the string "Learning Never Exhausts The Mind" in Quote
•
extract and display the words "The Mind" from the string
•
output the original string in lower case.
…
…
…
…
…
…
…
…
…
…
…
… [5]
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
The flowchart represents an algorithm.
The predefined function DIV gives the value of the result of integer division,
←
9 DIV 4 gives y a value of 2
for example, y
An input value of –1 ends the algorithm.
START
INPUT
Value
IS
Yes
Value =
-1 ?
No
Calc1
Value DIV 2
Calc2
Value DIV 3
IS
No
Calc1 =
Value / 2 ?
Yes
IS
No
Calc2 =
Value / 3 ?
Yes
OUTPUT
Value
END
(a) Complete the trace table for the input data:
50, 33, 18, 15, 30, –1, 45, 12, 90, 6
Value
Calc1
Calc2
OUTPUT
[4]
(b) Describe the purpose of the algorithm.
…
…
… [2]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) Identify one constant that you could have used for Task 1. Give the value that would be
assigned to this constant. State the use of this constant.
Constant …
Value …
Use …
…
[3]
(b) Describe the arrays that you have set up in Task 1 to record today’s data about the squash
courts.
…
…
…
…
…
…
…
… [4]
(c) Explain how your program generates a unique 4-digit code for each booking.
…
…
…
…
…
… [3]
(d) Write an algorithm for Task 2. You do not need to display updated court availability. Use
either pseudocode, programming statements or a flowchart. Assume that Task 1 has been
completed.
…
…
…
…
…
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.
…
…
…
…
…
…
…
…
…
…
…
…
Question text
6
A check digit is one method to validate a 5-digit number.
The check digit for a 5-digit number is calculated as follows:
•
Each digit is multiplied by its position (the first digit on the left is in position 1).
•
The result of each multiplication is totalled.
•
MOD(Total, 11) is used to calculate the check digit.
•
If the result of the MOD function is 10, the check digit is ‘X’.
For example:
The calculation of the check digit for the 5-digit number 30475 is as follows:
Multiply each digit by its position and total the results:
(3 * 1) + (0 * 2) + (4 * 3) + (7 * 4) + (5 * 5) = 68
Calculate the check digit with MOD(Total, 11)
MOD(68, 11) = 2
The check digit for 30475 is 2
This pseudocode algorithm should calculate and output the check digit of a 5-digit number:
01
DECLARE Total : INTEGER
02
DECLARE Digit : INTEGER
03
DECLARE CheckDigit : CHAR
0
04
Total
1 TO 10
05
FOR Count
06
OUTPUT "Please enter digit ", Count
07
INPUT Digit
Total + (Digit / Count)
08
Total
09
NEXT Count
MOD(Total, 11)
10
CheckDigit
11
IF CheckDigit = 10
12
THEN
13
OUTPUT "The check digit is X"
14
ELSE
15
OUTPUT "The check digit is ", Count
16
ENDIF
ĬÙĊ®Ġ´íÈõÏĪÅĊÞüµþ×
,
,
(a) Identify the line numbers of the four errors in the pseudocode and suggest a correction for
each error.
Error 1 line number …
Correction …
…
Error 2 line number …
Correction …
…
Error 3 line number …
Correction …
…
Error 4 line number …
Correction …
…
[4]
(b) Explain how you could modify the pseudocode to validate that each input is a single digit.
Any code must be fully explained.
…
…
…
…
… [3]
(c) The 5-digit number needs to be entered as a single input.
Describe one verification method that could be applied to the input of the 5-digit number.
…
…
Question text
Tick ( ü ) one box to show the name of the data structure used to store a collection of data of the
2
same data type.
A
Array
B
Constant
C
Function
D
Variable
[1]