Programming – IGCSE Computer Science (0478)
270 questions · page 11 of 18 · Clear filters
Question text
5
The pseudocode represents an algorithm.
The pre-defined function DIV gives the value of the result of integer division.
For example, Y = 9 DIV 4 gives the value Y = 2
The pre-defined function MOD gives the value of the remainder of integer division.
For example, R = 9 MOD 4 gives the value R = 1
←
0
First
←
0
Last
INPUT Limit
←
1 TO Limit
FOR Counter
INPUT Value
IF Value >= 100
THEN
IF Value < 1000
THEN
←
Value DIV 100
First
←
Value MOD 10
Last
IF First = Last
THEN
OUTPUT Value
ENDIF
ENDIF
ENDIF
NEXT Counter
(a) Complete the trace table for the algorithm using this input data:
8, 66, 606, 6226, 8448, 642, 747, 77, 121
Counter
Value
First
Last
Limit
OUTPUT
[5]
(b) Describe the purpose of the algorithm.
…
…
…
… [2]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one constant that you could have used for Task 1.
Give the value and use of the constant.
Constant …
Value …
Use …
…
[3]
(ii)
Identify one variable that you could have used for Task 2.
Give the data type and use of the variable.
Variable …
Data type …
Use …
…
[3]
(b) Explain how your program showed the days available for booking in Task 1.
…
…
…
…
…
… [3]
(c) Explain how your program made sure that each booking number allocated in Task 2 was
unique.
…
…
…
… [2]
(d) Write an algorithm for the part of Task 2 that inputs the tickets and extra attractions required
then calculates the total cost of the booking.
Assume that the booking is for a single day.
Use pseudocode, programming statements or a flowchart.
…
…
…
…
…
Question text
2
An algorithm allows a user to input their password and checks that there are at least eight
characters in the password. Then, the user is asked to re-input the password to check that both
inputs are the same. The user is allowed three attempts at inputting a password of the correct
length and a matching pair of passwords. The pre-defined function LEN(X) returns the number of
characters in the string, X
←
0
01
Attempt
02
REPEAT
←
TRUE
03
PassCheck
04
OUTPUT "Please enter your password "
05
INPUT Password
06
IF LEN(Password) < 8
07
THEN
←
TRUE
08
PassCheck
09
ELSE
10
OUTPUT "Please re-enter your password "
11
INPUT Password2
12
IF Password <> Password
13
THEN
←
FALSE
14
PassCheck
15
ENDIF
16
ENDIF
←
Attempt + 1
17
Attempt
18
UNTIL PassCheck OR Attempt <> 3
19
IF PassCheck
20
THEN
21
OUTPUT "Password success"
22
ELSE
23
OUTPUT "Password fail"
24
ENDIF
(a) Identify the three errors in the pseudocode and suggest a correction to remove each error.
Error 1 …
Correction …
Error 2 …
Correction …
Error 3 …
Correction …
[3]
(b) The algorithm includes two types of check on the data input.
Identify and describe each type of check.
Type of check 1 …
Description …
…
Type of check 2 …
Description …
…
[4]
(c) Give two sets of test data for this algorithm and a reason for choosing each set.
Each set of test data and its reason must be different.
Set 1 …
Reason …
…
Set 2 …
Reason …
…
[4]
Question text
3
(a) Describe a one-dimensional array. Include an example of an array declaration.
…
…
…
…
…
… [3]
(b) Explain how indexing could be used to search for a value stored in a one-dimensional array.
…
…
…
… [2]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) Identify one variable and one array you could have used for Task 1 or Task 2.
Give the use for the variable and array.
Variable …
Use …
…
Array …
Use …
… [4]
(b) Describe how you could test if the validation of the input to choose a meeting room works
(Task 2).
…
…
…
… [2]
(c) Explain how your program in Task 2 could be altered to allow a 30% discount on bookings for
the same meeting room of two to six days, inclusive.
…
…
…
…
…
…
…
… [4]
(d) Write an algorithm to show how your program completes the following parts of Task 2:
•
output the booking details and cost of the booking
•
take confirmation from the client
•
generate a unique booking code
•
store the booking details.
Assume that Task 1 and the first part of Task 2 have been completed.
Assume that the booking is for a single day and that the requested booking day is available.
Use pseudocode, programming statements or a flowchart.
…
…
…
Question text
3
Describe what is meant by the terms variable and constant and give an example of each in your
answer.
Variable …
…
…
…
Constant …
…
…
…
[4]
Question text
4
The pseudocode represents an algorithm.
The pre-defined function DIV gives the value of the result of integer division.
For example, Y = 11 DIV 4 gives the value Y = 2
←
0
Count
←
INPUT Limit
←
1 TO Limit
FOR In
←
TRUE
Logic
2
Test
INPUT Number
REPEAT
IF Number / Test = Number DIV Test
←
THEN
FALSE
Logic
←
ELSE
Test + 1
Test
ENDIF
UNTIL NOT Logic OR Test >= Number DIV 2
IF Logic
←
THEN
←
Number
Store[Count]
Count + 1
Count
ENDIF
←
NEXT In
0 TO Count - 1
FOR Out
OUTPUT Store[Out]
NEXT Out
(a) Complete the trace table for the algorithm using this input data:
5, 9, 5, 8, 10, 7
Store
In
Logic
Test
Number
Count
Limit
Out
OUTPUT
[Count]
[7]
(b) State the purpose of this algorithm.
…
…
…
… [2]
(c) This algorithm only works for numbers that are 3 or greater.
Describe how you could change this algorithm to make sure that only numbers that are
3 or greater are entered. Any pseudocode statements used in your answer must be fully
described.
…
…
…
…
…
…
…
…
…
… [3]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) State one constant and one variable that you could have used for Task 1. Give the value
that would be assigned to the constant. Give the data type for the variable. Explain why the
constant was used rather than a variable and explain why the variable was used rather than a
constant.
Constant name …
Value …
Why a constant was used …
…
…
Variable name …
Data type …
Why a variable was used …
…
…
[6]
(b) Describe how your program set the scores to zero before each round for Task 1.
…
…
…
…
…
…
…
… [4]
(c) Write an algorithm for Task 2, using pseudocode, programming statements or a flowchart.
…
…
…
…
…
…
Question text
2
An algorithm has been written to:
•
input the ages of 100 students
•
count and output the number of students aged 7 and under 12
•
count and output the number of students aged 12 and under 18
•
count and output the number of students aged 18 and over.
(a) Complete the pseudocode algorithm:
←
0
01
Count7to12
←
0
02
Count12to18
←
0
03
CountOver18
←
1 TO …
04
FOR Student
05
OUTPUT "Please enter student's age in years "
06
INPUT Age
07
IF Age >= 7 …
08
THEN
←
Count7to12 + 1
09
Count7to12
10
ENDIF
11
IF Age >= 12 AND Age < 18
12
THEN
←
…
13
Count12to18
14
ENDIF
15
IF Age >= 18
16
THEN
←
CountOver18 + 1
17
CountOver18
18
ENDIF
19
NEXT Student
20
OUTPUT "There are ", Count7to12, " students aged 7 and under 12."
21
OUTPUT "There are ", Count12to18, " students aged 12 and under 18."
22
OUTPUT "There are ", … , " students aged 18 and over."
[4]
(b) Write the extra pseudocode statements that are needed to count and output the number of
students under the age of 7. Use the variable CountUnder7; assume CountUnder7 has
already been set to zero.
…
…
…
…
…
…
… [4]
Question text
4
This flowchart inputs a whole number. The function INT returns the integer value of a number. For
example, INT (7.5) is 7
An input of -1 ends the routine.
START
INPUT Number
Yes
IS Number
END
= –1?
No
C
0
D
INT(Number/2)
IS
Yes
INT(Number/D)
= Number/D?
No
C
C + 1
D
D – 1
No
IS D =
1?
Yes
Yes
IS C =
0?
No
OUTPUT C
(a) Complete the trace table for the given algorithm using this input data:
7, 6, 5, 4, –1, 12, 34
Number
C
D
OUTPUT
[6]
(b) Describe the purpose of this algorithm.
…
…
…
… [2]
(c) (i)
Describe the problem that occurs if a whole number smaller than 4 and not equal to –1
is input.
…
…
…
… [2]
(ii)
Explain how to change the flowchart to prevent this problem occurring.
…
…
…
… [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
2
An algorithm has been written in pseudocode to generate 50 positive random integers with values
less than or equal to 100. These random integers are stored in the array RandNum[ ]
The function Rand(X, Y) generates a random integer greater than or equal to X and less than Y.
For example, Rand(1, 4) generates 1 or 2 or 3.
0
1 Count
2 REPEAT
Rand(1, 100)
3
RandNum[Counter]
Count + 2
4
Count
5 UNTIL Count <= 50
(a) Find the four errors in the pseudocode and write a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
…
[4]
(b) The pseudocode for this algorithm could be shortened by the use of a FOR … NEXT loop.
Rewrite the algorithm using a FOR … NEXT loop.
…
…
…
… [3]
(c) Identify another loop structure available in pseudocode.
… [1]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one variable you could have used for Task 2 and state its use.
Variable …
Use …
…
…
[2]
(ii)
Describe the arrays you could have used in Task 1. Include the name, data type, use
and sample data for each array.
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) Describe how you could validate the data entry for the input of the codes for the different
stages of the journey in Task 2.
…
…
…
…
…
… [3]
(c) Write an algorithm to show how your program carries out Task 3, using either pseudocode,
programming statements or a flowchart. Assume Tasks 1 and 2 have already been completed.
…
…
Question text
4
The pseudocode algorithm should work as a calculator and output the result.
1
1 Continue
2 WHILE Continue = 0
3
OUTPUT "Enter 1 for +, 2 for -, 3 for * or 4 for /"
4
INPUT Operator
5
OUTPUT "Enter the first value"
6
INPUT Value1
7
OUTPUT "Enter the second value"
8
OUTPUT Value2
9
IF Operator
Value1 + Value2
10
1: Answer
Value1 - Value2
11
2: Answer
Value1 * Value2
12
3: Answer
Value1 / Value2
13
4: Answer
14
ENDCASE
15
OUTPUT "The answer is ", Value1
16
OUTPUT "Do you wish to enter more values (Yes or No)?"
17
INPUT MoreValues
18
IF MoreValues = "No"
19
THEN
1
20
Continue
21
ENDIF
22 UNTIL Continue = 0
(a) Find the five errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
Error 5 …
Correction …
…
[5]
(b) The algorithm needs changing to allow only the numbers 1, 2, 3, or 4 to be entered for the
input variable Operator.
Write the pseudocode to perform this task and state where in the algorithm it would be
located.
Pseudocode …
…
…
…
…
…
…
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 restaurant
tables.
…
…
…
…
…
…
…
… [4]
(c) Sometimes the restaurant has fewer tables available for a session.
Explain how you would change your Task 1 program to allow input of the number of tables
available for a session.
…
…
…
…
…
… [3]
(d) Part of Task 2 is to check if a table is available. Write an algorithm to do this, using either
pseudocode, programming statements or a flowchart. Assume that Task 1 has been
completed.
…
…
…
…
…