Programming – IGCSE Computer Science (0478)
270 questions · page 4 of 18 · Clear filters
Question text
4
A telephone number with 13 characters is input. The first character is a ‘+’, followed by a 2-digit
country code, for example:
+20xxxxxxxxxx where 20 is the country code and x is a digit between 0 and 9 inclusive.
The algorithm includes checks for the country codes: 44 for the UK and 20 for Egypt.
(a) Write an algorithm using pseudocode to:
•
input the telephone number
•
extract the 2-digit country code
•
output the matching country
•
output ‘Unknown’ if there is no matching country.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
ĬÍĊ®Ġ´íÈõÏĪÅĊÝù·Ā×
,
,
(b) Explain how you could change the algorithm to repeatedly prompt for the telephone number
until the number entered is 13 characters in length.
Any code used must be fully explained.
…
…
…
…
Question text
5
Two library routines used in programming are MOD and DIV.
State the purpose of each of the library routines.
Give one example pseudocode statement for each of the library routines.
MOD purpose …
…
Example pseudocode …
…
DIV purpose …
…
Example pseudocode …
…
[4]
ĬÏĊ®Ġ´íÈõÏĪÅĊÝû·Ā×
Question text
6
An algorithm has been written in pseudocode to generate a random integer between 1 and 100
inclusive and store the value in N. The user enters a guess for the number and the algorithm
indicates whether the guess is higher or lower than the random number. The algorithm outputs
the number of guesses when the user has correctly guessed the random number.
0
01
Counter
ROUND(RANDOM() * 99, 1) + 1
02
N
03
REPEAT
04
OUTPUT "Please enter a guess"
05
INPUT G
06
IF G > N
07
THEN
08
OUTPUT "The number is lower than your guess"
09
ELSE
10
IF G < N
11
THEN
12
OUTPUT "The number is lower than your guess"
13
ENDIF
Counter + 1
14
Counter
15
ENDIF
16
UNTIL G = N
17
OUTPUT "Well done, you took ", Guess, " attempts"
(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) Identify one method to make the algorithm maintainable.
Give an example.
…
…
…
… [2]
ĬÑĊ®Ġ´íÈõÏĪÅĊàû¶þ×
Question text
9
The variables A and B are used in a program. A holds a whole number and B holds text.
(a) Write pseudocode statements to declare the variables A and B
…
…
… [2]
(b) The function Odds(X) returns ‘Odd’ if the value of X is an odd number and returns ‘Even’ if
the value of X is an even number.
Write pseudocode statements to:
•
define the function
•
call the function using parameter A and store the return item in variable B
Function definition …
…
…
…
…
…
…
…
…
…
…
Function call …
…
[6]
ĬÓĊ®Ġ´íÈõÏĪÅĊÞù¶Ā×
Question text
11
The one-dimensional (1D) array CompetitorName[] contains the names of 25 competitors in a
tournament that includes five events.
Another two-dimensional (2D) array CompetitorScore[] contains the points scored by each
competitor in the five events. The first dimension of this array contains the index of the competitor
from CompetitorName[] and the second dimension contains their scores.
Each competitor receives a score out of 100 for each event. These scores are manually entered
into CompetitorScore[]
Medals are awarded to the competitor or the competitors who have:
•
the highest points scored in each of the five events
•
the highest total points scored for all five events.
The one-dimensional (1D) array Points[] stores the total number of points scored for each
competitor.
Write a program that meets the following requirements:
•
takes as input, valid scores (between 0 and 100), for each competitor in each of the five
events
•
calculates the highest points scored for each event
•
outputs the names of the competitors who receive a medal for the highest points scored
•
calculates the highest total points scored for the five events
•
outputs the names of the competitors with the highest total points scored for the five events.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays or variables.
All inputs and outputs must contain suitable messages.
…
…
…
…
…
…
…
…
…
…
…
…
ĬÑĊ®Ġ´íÈõÏĪÅĊÝû¸Ā×
,
,
…
…
…
…
…
Question text
2
A fence measuring 2 metres in height and 20 metres in length needs painting. The area of the
fence needs to be calculated so that enough paint for the job is purchased.
After the task is decomposed, there are three component parts: input, process and output.
Three component parts and four example descriptions are shown.
Draw one line from each component part to the most appropriate relevant description.
Not all descriptions will be used.
Component part
Description
the height of the fence
the length of the fence
process
The amount of paint required is
40 square metres.
output
the colour of the paint
input
The area of fence is calculated as
40 square metres.
[3]
Question text
4
(a) State one reason for using a verification check when inputting data.
…
… [1]
(b) Write the pseudocode for an algorithm to perform a double entry verification check, using the
following criteria:
•
Input 10 numbers and store them in the array Numbers[]
•
Input the same 10 numbers again; as each number is input, compare it with its
corresponding number in the array Numbers[]
◦
if the numbers match, move on to the next number
◦
if the numbers do not match, display both numbers and ask for the number to be
re-entered
◦
store the re-entered number in the corresponding array location and move on to the
next number.
•
When all the numbers have been checked, display a message to say the check has
been completed.
You do not need to declare any arrays or variables for this algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
ĬÏĊ®Ġ´íÈõÏĪÅĊßù¸þ×
Question text
5
This pseudocode algorithm should allow 500 names of people and their heights to be entered and
stored in two one-dimensional (1D) arrays. The name of a person and the height of that person
are in the same index in both the Names[] and the Heights[] arrays.
The algorithm performs as follows:
•
at the start, the following data is entered:
◦
name of person
◦
height of person in cm
•
the data is stored in the relevant arrays
•
the heights of the people are totalled
•
the shortest person is found
•
at the end, the following is output:
◦
name of shortest person
◦
height of shortest person
◦
average height of all 500 people.
01
DECLARE Names : ARRAY[1:500] OF REAL
02
DECLARE Heights : ARRAY[1:500] OF REAL
03
DECLARE Shortest : REAL
04
DECLARE Total : REAL
05
DECLARE Counter : INTEGER
06
DECLARE Index : INTEGER
500
07
Shortest
0
08
Index
100
09
Total
1 TO 500
10
FOR Counter
11
INPUT Names[Index]
12
INPUT Heights[Counter]
Counter + Heights[Counter]
13
Total
14
IF Heights[Counter] < Shortest
15
THEN
Heights[Counter]
16
Shortest
Counter
17
Index
18
ENDIF
19
NEXT Counter
20
OUTPUT "The shortest height is ", Heights
21
OUTPUT "The shortest person is ", Names[Index]
22
OUTPUT "The average height is ", Total / 500
ĬÍĊ®Ġ´íÈõÏĪÅĊÝû¸Ā×
,
,
(a) Identify the line numbers of five 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 …
…
Error 5 line number …
Correction …
…
[5]
(b) Write the pseudocode statement that will output the average height rounded to one decimal
place.
…
… [2]
(c) Explain how you could change the corrected algorithm so that it will also:
•
find the height of the tallest person.
•
output the height of the tallest person at the end of the algorithm.
Any program statements used must be fully explained.
…
…
Question text
6
This pseudocode is an algorithm.
DECLARE Word : STRING
DECLARE V1 : INTEGER
DECLARE V2 : INTEGER
DECLARE Number : INTEGER
DECLARE Index : INTEGER
DECLARE L1 : CHAR
DECLARE L2 : CHAR
DECLARE Continue : BOOLEAN
INPUT Number
1 TO Number
FOR Index
INPUT Word
TRUE
Continue
1
V1
LENGTH(Word)
V2
WHILE Continue = TRUE AND V1 < V2 DO
SUBSTRING(Word, V1, 1)
L1
SUBSTRING(Word, V2, 1)
L2
IF L1 <> L2
THEN
FALSE
Continue
ELSE
V1 + 1
V1
V2 – 1
V2
ENDIF
ENDWHILE
IF Continue = TRUE
THEN
OUTPUT "Successful"
ELSE
OUTPUT "NOT successful"
ENDIF
NEXT Index
ĬÑĊ®Ġ´íÈõÏĪÅĊàùµþ×
,
,
(a) Complete the trace table for the algorithm, using the input data:
2, RACECAR, TREAT
Number
Index
Word
Continue
V1
V2
L1
L2
OUTPUT
[6]
(b) State the purpose of the algorithm on page 6.
…
… [1]
(c) Explain how the algorithm knows when all the letters in the word have been checked so that it
can stop checking.
…
…
…
…
…
… [3]
ĬÓĊ®Ġ´íÈõÏĪÅĊàûµþ×
Question text
10 A program is required to allow students to calculate the volume of a number of standard
three-dimensional shapes. It will use functions to allow other shapes to be added in the future.
Cuboid
height
volume = base × depth × height
depth
base
Triangular prism
volume = 1 2 × base × depth × height
height
depth
base
Sphere
volume = 4 3 × Pi × radius × radius × radius
radius
Pi is a constant with value 3.142
Write a program that meets the following requirements:
•
Output a menu to ask the user for an input to indicate the shape for which a volume needs to
be calculated, from the three shapes given or if they want to stop the program. The program
must validate the input.
•
Input the data needed to calculate the volume of the chosen shape, based on the given
formulae.
•
Create one function for each shape to calculate and return the volume using the given
formulae. Each function uses the input data as parameters.
•
Output the volume in the main program, rounded to two decimal places.
The program continues until the user inputs the stop option from the menu.
You must use pseudocode or program code and add comments to explain how your code works.
All variables and constants used must be declared for this algorithm.
All inputs and outputs must contain suitable messages.
…
…
…
ĬÍĊ®Ġ´íÈõÏĪÅĊÞü¶Ă×
,
,
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
The flowchart shows an algorithm used for quality control on a biscuit production line.
The weight of each biscuit is entered into the variable Weight. If the weight of the biscuit is
between 16.2 and 17.2 grammes, inclusive, the pass counter is incremented by 1. Otherwise,
the reject counter is incremented by 1. The process continues until –1 is entered, after which, the
totals for pass and reject counters are output.
(a) Complete this flowchart.
START
PassCount
0
RejectCount
0
Yes
No
No
Yes
STOP
[6]
ĬÍĊ®Ġ´íÈõÏĪÅĊÝü·þ×
,
,
(b) Explain how you would alter the flowchart in 1(a) so that it calculates and outputs the average
weight of only the biscuits that passed the weight check.
You may include program statements or flowchart symbols in your answer, but they must be
fully explained.
…
…
…
…
…
…
…
…
…
… [4]
Question text
2
Three uses of arithmetic operators and four results are shown.
Draw one line from each use of arithmetic operator to the correct result.
Not all results will be used.
Use of arithmetic operator
Result
5
355 DIV 10
355
355 / 10
35
355 MOD 10
35.5
[3]
ĬÏĊ®Ġ´íÈõÏĪÅĊÝú·þ×
Question text
3
The purpose of this pseudocode algorithm is to carry out a bubble sort to sort, in descending
order, 1000 numbers stored in a one-dimensional (1D) array.
01
DECLARE Values : ARRAY[1:1000] OF REAL
02
DECLARE Index : CHAR
03
DECLARE Stop : BOOLEAN
04
DECLARE Hold : REAL
FALSE
05
Stop
06
WHILE NOT Stop DO
FALSE
07
Stop
1 TO 50
08
FOR Index
09
IF Values[Index + 1] > Values[Index]
10
THEN
Values[Index]
11
Hold
Values[Index + 1]
12
Values[Index]
Hold
13
Values[Index + 1]
FALSE
14
Stop
15
ENDIF
16
NEXT Index
17
NEXT Stop
(a) Identify the line numbers of 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) The swap section in lines 11 to 13 of the existing code are to be changed to a call statement
for a procedure. This procedure will include two parameters representing the indexes of the
array elements to be swapped.
(i)
Complete the pseudocode for PROCEDURE Swap
PROCEDURE Swap( … )
DECLARE Hold : REAL
Values[ … ]
Hold
…
…
ENDPROCEDURE
[4]
(ii)
Write the pseudocode to transfer control to PROCEDURE Swap
…
… [2]
(c) Explain the difference between global variables and the variable declared in 3(b)(i).
…
…
…
… [2]
ĬÏĊ®Ġ´íÈõÏĪÅĊßú·Ā×
Question text
5
(a) A computer store uses a database table COMPONENT to store the stock details of a range of
components needed to build computer systems.
Complete the table by giving appropriate data types for each field.
Only the data types: text, character, Boolean, integer, real, date/time are available in this
database.
Field
Data type
Description
ID
unique identifier
Name
component name
Description
component description
selling price of component to
Price
2 decimal places
NumberAvailable
number in stock
level at which the component
MinimumLevel
is reordered
whether or not the component
ReOrdered
has been reordered
the date the component was
DateOrdered
reordered
[4]
(b) Complete the structured query language (SQL) statement to list only the unique identifier,
component name and reorder date of all the components that have been reordered.
SELECT …
FROM …
WHERE … ;
[4]
ĬÓĊ®Ġ´íÈõÏĪÅĊÞü¶þ×
Question text
6
This pseudocode represents an algorithm.
DECLARE Store : ARRAY[1:100] OF CHAR
DECLARE Word : STRING
DECLARE Index : INTEGER
DECLARE Letter : CHAR
INPUT Word
1 TO LENGTH(Word)
FOR Index
SUBSTRING(Word, Index, 1)
Letter
CASE OF Letter
""
'A' : Letter
""
'E' : Letter
""
'I' : Letter
""
'O' : Letter
""
'U' : Letter
ENDCASE
Letter
Store[Index]
NEXT Index
1 TO LENGTH(Word)
FOR Index
IF Store[Index] <> ""
THEN
OUTPUT Store[Index]
ENDIF
NEXT Index
ĬÑĊ®Ġ´íÈõÏĪÅĊàú¶Ā×
,
,
(a) Complete the trace table for the algorithm, using input data: COMPUTER
Store[]
Word
Index
Letter
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
OUTPUT
[5]
(b) Describe the processes in the algorithm.
…
…
…
…
…
… [3]
ĬÓĊ®Ġ´íÈõÏĪÅĊàü¶Ā×