Programming – IGCSE Computer Science (0478)

270 questions · page 6 of 18 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
76
0478/22/O/N/24 · Question 12Oct/Nov 2024Paper 2215 marks
Loading question…
Question text

12 A one-dimensional (1D) array Rooms[] contains the names of up to 20 rooms in a house.
A two-dimensional (2D) array Dimensions[] is used to store the length, width and area of each
room.
The position of any room’s data is the same in both arrays. For example, the data in index 5 of
Dimensions[] belongs to the room in index 5 of Rooms[]
The variable Number stores the number of rooms for which data is to be input. There must be at
least 3 rooms but no more than 20.
Write a program that meets the following requirements:
•
allows the number of rooms for which data is required to be input, stored and validated
•
allows the name of the room and the length and width of the room, in metres, to be entered
and stored
•
allows the area of each room to be calculated as length multiplied by width and stored as
square metres rounded to two decimal places
•
calculates the average size of all the rooms by area, in square metres, rounded to two decimal
places
•
finds the largest room and smallest room by area
•
outputs the names of all rooms with their dimensions and area
•
outputs the names of the largest room and smallest room by area
•
outputs the total area of the house and the average size of all the rooms by area.
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; you may assume that this has already been
done.
All inputs and outputs must contain suitable messages.
…
…
…
…
…
…
…
…
…
…
…
…
…
ĬÑĊ®Ġ´íÈõÏĪÅĊßû¸Ā×
,
,
…
…
…
…

77
0478/23/O/N/24 · Question 6Oct/Nov 2024Paper 2310 marks
Loading question…
Question text

6
An incomplete algorithm has been written in pseudocode to count the number of values stored in
an array and to find their average.
Values have been stored in the array starting at A[1]
All the values to be counted are non-zero.
A value of zero in the array indicates there are no more values stored.
01 DECLARE A : ARRAY[1:50] OF INTEGER
02 DECLARE C : INTEGER
03 DECLARE W : INTEGER
04 DECLARE X : INTEGER
0
05 W
…
06 C
07 WHILE A[C] <> 0
…
08
W
C + 1
09
C
10 ENDWHILE
…
11 X
(a) Complete the given pseudocode algorithm.
[3]
(b) Write pseudocode to display, with suitable messages:
•
the number of values stored in the array
•
the average of those values stored.
…
…
…
…
…
… [3]
ĬÍĊ®Ġ´íÈõÏĪÅĊÞû¸Ā×
,
,
(c) Meaningful identifiers have not been used in this algorithm.
Suggest suitable meaningful identifiers for:
The array
A …
The variables
C …
X …
W …
[3]

78
0478/23/O/N/24 · Question 10Oct/Nov 2024Paper 239 marks
Loading question…
Question text

10 An algorithm has been written in pseudocode to check that a password meets a set of rules.
01
OUTPUT "Please enter password "
02
INPUT Password
TRUE
03
Accept
04
IF LENGTH(Password) < 8 OR LENGTH(Password) > 20
05
THEN
FALSE
06
Accept
07
ENDIF
08
IF LCASE(Password) = Password OR UCASE(Password) = Password
09
THEN
FALSE
10
Accept
11
ENDIF
1
12
Index
FALSE
13
Found
14
WHILE NOT Found AND Accept AND Index < LENGTH(Password)
15
IF SUBSTRING(Password, Index, 1) = '!'
16
THEN
TRUE
17
Found
18
ENDIF
Index + 1
19
Index
20
ENDWHILE
21
IF NOT Found
22
THEN
FALSE
23
Accept
24
ENDIF
25
IF Accept
26
THEN
27
OUTPUT "Accepted"
28
ELSE
29
OUTPUT "Rejected"
30
ENDIF
(a) Complete the three trace tables using the data shown for each one.
Data: MYWORD
Password
Accept
Index
Found
OUTPUT
ĬÑĊ®Ġ´íÈõÏĪÅĊÝùµĀ×
,
,
Data: M!word
Password
Accept
Index
Found
OUTPUT
Data: My!Hidden
Password
Accept
Index
Found
OUTPUT
[6]
(b)
State the rules that the password must meet.
…
…
…
…
…
… [3]
ĬÓĊ®Ġ´íÈõÏĪÅĊÝûµĀ×

Advertisement
79
0478/23/O/N/24 · Question 12Oct/Nov 2024Paper 2315 marks
Loading question…
Question text

12 Members of a litter picking group complete a litter pick every month. Members’ names are stored
in one-dimensional (1D) array PickerName[]
Each member stores the weight of the litter they have picked in another one-dimensional (1D)
array PickedWeight[]
The weights are in kilograms with one decimal place, for example 8.4
The position of each member’s data in the two arrays is the same. For example, the member
stored at index 10 in PickerName[] and at index 10 in PickedWeight[] is the same.
Every month, there is a small prize awarded to the members of the group who have the two
heaviest weights. Certificates are awarded to all members with a pick weight of over three
kilograms.
Write a program that meets the following requirements:
•
allows the weight of members’ picks to be input and validated
•
sorts the arrays PickedWeight[] and PickerName[] in descending order of weight
•
outputs the member names and the pick weights of the members with the two heaviest picks
and identifies them as “Best in Group” and “Second best in Group”
•
stores the names of all the members who will receive a certificate in the array
PickerCertificate[]
•
outputs a message stating the number of certificates to be printed.
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; you may assume that this has already been
done.
All inputs and outputs must contain suitable messages.
You do not need to initialise the data in the array PickerName[]
…
…
…
…
…
…
…
…
…
…
…
…
ĬÑĊ®Ġ´íÈõÏĪÅĊÞù·Ā×
,
,
…
…
…
…

80
0478/21/M/J/24 · Question 2May/June 2024Paper 219 marks
Loading question…
Question text

2
Four descriptions of programming concepts and five programming concepts are shown.
(a) Draw one line to link each description to the most appropriate programming concept.
Not all programming concepts will be used.
Description
Programming concept
function
a subroutine that may not return a value
procedure
a value that is declared and used within a
specific procedure
parameter
a value that a procedure expects you to
supply when it is called
global variable
a subroutine that will always return a value
local variable
[4]
(b) Write the pseudocode to use a procedure named Average that passes the values 25 and 50
to the procedure.
…
… [2]
(c) Outline the role of procedures and functions in creating a program that is easier to maintain.
…
…
…
…
…
… [3]

81
0478/21/M/J/24 · Question 3May/June 2024Paper 214 marks
Loading question…
Question text

3
State what is meant by the data types integer and real.
Give an example of each.
Integer …
…
Example …
Real …
…
Example …
[4]

82
0478/21/M/J/24 · Question 4May/June 2024Paper 2110 marks
Loading question…
Question text

4
This pseudocode algorithm is intended to allow, at random, between 1 and 20 values to be entered
and totalled. The total and average of the entered values are output at the end of the algorithm.
01
DECLARE Loop : STRING
02
DECLARE Limit : INTEGER
03
DECLARE Value : REAL
04
DECLARE Total : REAL
0
05
Total
ROUND(RANDOM() * 19,0) + 1
06
Limit
1 TO Limit
07
IF Loop
08
OUTPUT "Enter a number"
09
INPUT Loop
Total * Value
10
Total
11
NEXT Loop
12
OUTPUT "The total of the numbers entered is ", Total
13
OUTPUT "The average of the numbers entered is ", Total / Limit
(a) Identify the line numbers of four errors in the pseudocode and suggest corrections.
Error 1 line number …
Correction …
…
Error 2 line number …
Correction …
…
Error 3 line number …
Correction …
…
Error 4 line number …
Correction …
…
[4]
(b) Write the pseudocode statement that would output the average calculated in line 13 of the
algorithm rounded to one decimal place.
…
…
…
… [2]
(c) Explain how you should alter the original corrected algorithm to make sure that all the
numbers entered are between 1 and 500 inclusive. If any numbers fall outside these limits, a
replacement value is requested and entered.
You do not need to re-write the algorithm.
…
…
…
…
…

83
0478/21/M/J/24 · Question 7May/June 2024Paper 216 marks
Loading question…
Question text

7
(a) Outline why it is useful to store data in a file.
…
…
…
… [2]
(b) The function LENGTH(X) calculates the length of a string X
Write the pseudocode statements to:
•
read the contents of the text file Quotation.txt into an appropriate string variable that
has been declared
•
output the string in upper case and the length of the string.
…
…
…
…
…
…
…
… [4]

Advertisement
84
0478/21/M/J/24 · Question 10May/June 2024Paper 2115 marks
Loading question…
Question text

10 The one-dimensional (1D) array Clubs[] is used to store the names of 12 cricket clubs in a local
sports league.
The two-dimensional (2D) array Statistics[] is used to store, for each cricket club, the number
of:
•
matches won
•
matches drawn
•
matches lost.
The 1D array Points[] is used to store the total number of points each cricket club has been
awarded.
The position of any cricket club’s data is the same in all three arrays. For example, the data in
index 2 of Statistics[] and index 2 of Points[] belongs to the cricket club in index 2 of
Clubs[]
The variable Matches stores the number of matches played by each team. Each team plays the
same number of matches.
Points are awarded for:
•
a win – 12 points
•
a draw – 5 points
•
a loss – 0 points.
Write a program that meets the following requirements:
•
allows the number of matches played to be input and stored, with a maximum of 22 matches
•
validates the number of matches played
•
allows the names of the cricket clubs to be input and stored
•
allows the number of matches won, drawn and lost to be input and stored for each team
•
validates the number of matches won, drawn or lost against the number of matches played
•
asks the user to re-enter the number of matches won, drawn or lost if the total does not match
the number of matches played
•
calculates and stores the total number of points for each club
•
finds the cricket club or clubs with the highest number of points
•
outputs the name or names of the winning club or clubs, the number of wins and the total
number of points awarded.
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; you may assume that this has already been
done.
All inputs and outputs must contain suitable messages.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

85
0478/22/M/J/24 · Question 4May/June 2024Paper 2210 marks
Loading question…
Question text

4
A program needs to make sure the characters input for a product code meet these rules:
•
The product code is six characters in length.
•
The first two characters must be “PD”.
•
The last four characters must be a number in the range 1000 to 9999 inclusive.
(a) Identify three validation checks and state how each check would make sure the product code
met one of these rules.
Check 1 …
…
…
Check 2 …
…
…
Check 3 …
…
…
[6]
(b) The program design will include a pseudocode algorithm. Assume that the product code is
stored in the variable Product
(i)
Write the pseudocode to make sure that the product code is six characters in length.
…
…
…
…
… [2]
(ii)
Write the pseudocode to make sure that the first two characters of the product code are
“PD”.
…
…
…
…
… [2]

86
0478/22/M/J/24 · Question 5May/June 2024Paper 226 marks
Loading question…
Question text

5
A high-level programming language makes use of arithmetic, Boolean and logical operators.
State how each type of operator is used.
Give an example statement, in pseudocode, for each one.
Arithmetic …
…
Example …
…
Boolean …
…
Example …
…
Logical …
…
Example …
…
[6]

87
0478/22/M/J/24 · Question 7May/June 2024Paper 228 marks
Loading question…
Question text

7
An algorithm has been written in pseudocode to find and display the maximum and minimum
values in an array of 1000 positive numbers. The array List[] starts at index 1
List[1]
01
Max
List[1]
02
Min
2 TO 1000
03
FOR Counter
04
IF List[Counter] < Max
05
THEN
List[Counter]
06
Max
07
ENDIF
08
IF List[Count] ˂ Min
09
THEN
List[Counter]
10
Min
11
ENDWHILE
12
NEXT Counter
13
OUTPUT "Maximum value is ", Max
14
OUTPUT "Minimum value is ", Min
(a) Give a line number for each of these types of statement:
Assignment statement …
Selection statement …
Iteration statement …
[3]
(b) Identify the line numbers of the three 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 …
…
[3]

88
0478/22/M/J/24 · Question 11May/June 2024Paper 2215 marks
Loading question…
Question text

11
A one-player game uses the two-dimensional (2D) array Grid[] to store the location of a secret
cell to be found by the player in 10 moves. Each row and column has 5 cells.
Start
Grid[1,1]
At the start of the game:
•
The program places an ‘X’ in a random cell (not in Grid[1,1]) and empties all the other
cells in the grid.
•
The player starts at the top left of the grid.
•
The player has 10 moves.
During the game:
•
The player can move left, right, up or down by one cell and the move must be within the grid.
•
“You Win” is displayed if the player moves to the cell with ‘X’ and has played 10 moves or
less.
•
“You Lose” is displayed if the player has made 10 moves without finding the ‘X’.
Write a program that meets these requirements.
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; you may assume that this has already been
done.
All inputs and outputs must contain suitable messages.
…
…
…
…
…
…
…
…
…
,
,
…
…
…
…
…
…
…
…
…
…
…

Advertisement
89
0478/23/M/J/24 · Question 3May/June 2024Paper 234 marks
Loading question…
Question text

3
Describe the characteristics of the string and char data types and give an example of each.
String …
…
Example …
Char …
…
Example …
[4]

90
0478/23/M/J/24 · Question 4May/June 2024Paper 2312 marks
Loading question…
Question text

4
This pseudocode algorithm is intended to allow data for up to 50 people to be entered and stored
in a two-dimensional (2D) array. The data is their last name, first name and the city in which they
live.
01
DECLARE
People : ARRAY[1:50, 1:3] OF REAL
02
DECLARE
Count : INTEGER
03
DECLARE
Response : CHAR
04
DECLARE
Continue : BOOLEAN
05
FOR I
1 TO 50
06
FOR
J
1 TO 3
07
People[I, J]
""
08
NEXT J
09
NEXT I
10
Count
100
11
Continue
TRUE
12
CASE OF
13
OUTPUT "Enter the last name"
14
INPUT People[Count, 1]
15
OUTPUT "Enter the first name"
16
INPUT People[Count, 2]
17
OUTPUT "Enter the city"
18
INPUT People[Count, 3]
19
OUTPUT "Do you want to enter another name (Y or N)?"
20
INPUT Response
21
IF Response = 'N'
22
THEN
23
Continue
FALSE
24
ELSE
25
Count
Count + 1
26
ENDIF
27
UNTIL NOT Count
(a) Identify the line numbers of the four errors in the pseudocode and suggest corrections.
Error 1 line number …
Correction …
…
Error 2 line number …
Correction …
…
Error 3 line number …
Correction …
…
Error 4 line number …
Correction …
…
[4]
(b) Write the pseudocode that you could add to the end of this algorithm to output the contents of
the array. Make sure that the output ends when the data in the array ends.
…
…
…
…
…
…
…
… [4]
(c) Explain how you could alter the orig

Advertisement