Programming – IGCSE Computer Science (0478)
282 questions · page 11 of 19
Question text
2
An algorithm has been written to:
•
set all 50 elements of the array Reading[1:50] to zero
•
input values between 35 and 50 inclusive
•
end the process when an input of –1 is made or 50 valid numbers have been entered
•
reject all other values
•
count the number of times each valid value is input
•
output the number of times each value has been input, starting with the lowest value.
(a) Complete the pseudocode algorithm:
1 TO …
01
FOR Count
0
02
Reading[Count]
03
NEXT Count
1
04
Count
05
OUTPUT "Please enter next reading "
06
INPUT Value
07
REPEAT
IF Value < 35 OR …
08
09
THEN
10
OUTPUT "Reading out of range"
11
ELSE
…
12
Reading[Value]
13
Count = Count + 1
14
ENDIF
15
IF Count <= 50
16
THEN
17
OUTPUT "Please enter next reading "
…
18
19
ENDIF
20
UNTIL Value = -1 OR Count > 50
35
21
Count
22
REPEAT
OUTPUT "There are ", … ,
23
" readings of ", Count
…
24
Count
[6]
25
UNTIL Count > 50
(b) Describe how the algorithm could be changed to output the number of times each value has
been input, starting with the highest value.
…
…
…
…
…
… [3]
Question text
1
(a) Describe the data structures you could have used in Task 1. Your description should include
types of data structure, names used for data structures, their uses and examples of sample
data.
…
…
…
…
…
…
…
…
…
… [5]
(b) Explain how you could change your program in Task 1 to total all the money collected from
new members who have paid.
…
…
…
…
…
… [3]
(c) Describe how data input in Task 1 could be validated to find out if a new member wants to
work as a volunteer.
…
…
…
…
…
… [3]
(d) Write an algorithm to show how your program completes Task 3 assuming the option to
sponsor a wooden plank has been chosen, using pseudocode, programming statements or a
flowchart. Details completed in Task 1 are not required.
…
Question text
Tick ( ü ) one box in each row to identify the most appropriate data type for each description. Only
2
one tick ( ü ) per column.
Data type
Description
Boolean
Char
Integer
Real
String
a single character from the keyboard
multiple characters from the keyboard
only one of two possible values
only whole numbers
any number
[4]
Question text
4
The flowchart shows an algorithm that should allow 60 test results to be entered into the variable
Score. Each test result is checked to see if it is 50 or more. If it is, the test result is assigned to the
Pass array. Otherwise, it is assigned to the Fail array.
(a) Complete this flowchart:
START
PassCount
0
FailCount
0
Count
0
Yes
No
Count
Count + 1
No
Yes
END
[6]
(b) Write a pseudocode routine that will check that each test result entered into the algorithm is
between 0 and 100 inclusive.
…
…
…
…
…
…
…
…
…
… [4]
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
8
Victoria develops a computer game to sell on a gaming website. She writes her program using
English-like statements.
(a) State which type of programming language Victoria is using.
… [1]
(b) Victoria uses two different types of translator when creating the program for the computer
game.
State which translator is the most suitable for the given tasks.
Give the benefits of using that translator for the task.
You must choose a different translator for each task.
(i)
To translate the code during development of the game.
Translator …
Benefits …
…
…
…
…
…
[3]
(ii)
To translate the final program and upload to the website for distribution, without the
source code.
Translator …
Benefits …
…
…
…
…
…
[3]