Programming – IGCSE Computer Science (0478)
282 questions · page 9 of 19
Question text
4
Explain the purpose of the library routines DIV and ROUND
DIV …
…
…
…
ROUND …
…
…
…
[4]
Question text
5
An algorithm has been written in pseudocode to allow some numbers to be input. All the positive
numbers that are input are totalled and this total is output at the end.
An input of 0 stops the algorithm.
←
1
01
Exit
02
WHILE Exit <> 0 DO
03
INPUT Number
04
IF Number < 0
05
THEN
←
Total + Number
06
Total
07
ELSE
08
IF Number = 0
09
THEN
←
1
10
Exit
11
ENDIF
12
ENDIF
13
ENDIF
14
OUTPUT "The total value of your numbers is ", Number
(a) Identify the four errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Describe how you could change the corrected algorithm to record and output how many
positive numbers have been included in the final total.
You do not need to rewrite the algorithm.
…
…
…
…
…
…
…
… [4]
Question text
6
State two features that should be included to create a maintainable program.
Give a reason why each feature should be used.
1 …
…
…
…
2 …
…
…
…
[4]
Question text
7
The flowchart represents an algorithm.
START
Pointer
1
INPUT
Letter
IS
No
Word[Pointer, 1]
Pointer
Pointer
+ 1
= Letter ?
Yes
OUTPUT "Letter ", Letter,
" is represented by ",
Word[Pointer, 2]
OUTPUT "Another Letter?
(Y or N)"
INPUT Choice
IS
No
Yes
Choice =
STOP
'Y' ?
The table represents the two-dimensional (2D) array Word[] which stores the first half of the
phonetic alphabet used for radio transmission. For example, Word[10,1] is ‘J’.
Index
1
2
1
A
Alpha
2
B
Bravo
3
C
Charlie
4
D
Delta
5
E
Echo
6
F
Foxtrot
7
G
Golf
8
H
Hotel
9
I
India
10
J
Juliet
11
K
Kilo
12
L
Lima
13
M
Mike
(a) Complete the trace table for the algorithm by using the input data: F, Y, D, N
Pointer
Letter
Choice
OUTPUT
[4]
(b) Identify the type of algorithm used.
…
… [1]
(c) Describe one problem that could occur with this algorithm if an invalid character was input.
…
…
…
… [2]
Question text
8
The function LENGTH(Phrase) calculates the length of a string Phrase
(a) Write the pseudocode statements to:
•
store the string "The beginning is the most important part" in Phrase
•
calculate and output the length of the string
•
output the string in upper case.
…
…
…
…
…
… [3]
(b) Write the output your pseudocode should produce.
…
…
…
… [2]
Question text
11
A one-dimensional (1D) array Days[] contains the names of the days of the week. A
two-dimensional (2D) array Readings[] is used to store 24 temperature readings, taken once
an hour, for each of the seven days of the week. A 1D array AverageTemp[] is used to store the
average temperature for each day of the week.
The position of any day’s data is the same in all three arrays. For example, if Wednesday is
in index 4 of Days[], Wednesday’s temperature readings are in index 4 of Readings[] and
Wednesday’s average temperature is in index 4 of AverageTemp[]
The temperature readings are in Celsius to one decimal place. Temperatures can only be from
–20.0 °C to +50.0 °C inclusive.
Write a program that meets the following requirements:
•
input and validate the hourly temperatures for one week
•
calculate and store the average temperature for each day of the week
•
calculate the average temperature for the whole week
•
convert all the average temperatures from Celsius to Fahrenheit by using the formula
Fahrenheit = Celsius * 9 / 5 + 32
•
output the average temperature in Celsius and in Fahrenheit for each day
•
output the overall average temperature in Celsius and in Fahrenheit for the whole week.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays, variables or constants; you may assume that this has
already been done.
All inputs and outputs must contain suitable messages.
All data output must be rounded to one decimal place.
You will need to initialise and populate the array Days[] at the start of the program.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
6
State three different features of a high-level programming language that a programmer could use
to make sure that their program will be easier to understand by another programmer.
Give an example for each feature.
Feature 1 …
…
Example …
…
Feature 2 …
…
Example …
…
Feature 3 …
…
Example …
…
[6]
Question text
7
An algorithm has been written in pseudocode to calculate a check digit for a four-digit number.
The algorithm then outputs the five-digit number including the check digit.
The algorithm stops when –1 is input as the fourth digit.
FALSE
01 Flag
02 REPEAT
0
03
Total
1 TO 4
04
FOR Counter
05
OUTPUT "Enter a digit ", Counter
06
INPUT Number[Counter]
Total + Number * Counter
07
Total
08
IF Number[Counter] = 0
09
THEN
TRUE
10
Flag
11
ENDIF
12
NEXT Counter
13
IF NOT Flag
14
THEN
MOD(Total, 10)
15
Number[5]
0 TO 5
16
FOR Counter
17
OUTPUT Number[Counter]
18
NEXT
19
ENDIF
20 UNTIL Flag
(a) Give the line number(s) for the statements showing:
Totalling …
Count-controlled loop …
Post-condition loop …
[3]
(b) Identify the three errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
[3]
(c) The algorithm does not check that each input is a single digit.
Identify the place in the algorithm where this check should occur.
Write pseudocode for this check.
Your pseudocode must make sure that the input is a single digit and checks for –1
Place in algorithm …
Pseudocode …
…
…
…
…
…
[4]
Question text
11
The variables P and Q are used to store data in a program. P stores a string. Q stores a character.
(a) Write pseudocode statements to declare the variables P and Q, store "The world" in P and
store 'W' in Q
…
…
…
… [2]
(b) Write a pseudocode algorithm to:
•
convert P to upper case
•
find the position of Q in the string P (the first character in this string is in position 1)
•
store the position of Q in the variable Position
…
…
…
…
…
…
…
…
…
… [4]
(c) Give the value of Position after the algorithm has been executed with the data in
question 11(a).
…
… [1]
Question text
12 A two-dimensional (2D) array Account[] contains account holders’ names and passwords for a
banking program.
A 2D array AccDetails[] has three columns containing the following details:
•
column one stores the balance – the amount of money in the account, for example 250.00
•
column two stores the overdraft limit – the maximum total amount an account holder can
borrow from the bank after the account balance reaches 0.00, for example 100.00
•
column three stores the withdrawal limit – the amount of money that can be withdrawn at one
time, for example 200.00
The amount of money in a bank account can be negative (overdrawn) but not by more than the
overdraft limit.
For example, an account with an overdraft limit of 100.00 must have a balance that is greater than
or equal to –100.00
Suitable error messages must be displayed if a withdrawal cannot take place, for example if the
overdraft limit or the size of withdrawal is exceeded.
The bank account ID gives the index of each account holder’s data held in the two arrays.
For example, account ID 20’s details would be held in:
Account[20,1] and Account[20,2]
AccDetails[20,1] AccDetails[20,2] and AccDetails[20,3]
The variable Size contains the number of accounts.
The arrays and variable Size have already been set up and the data stored.
Write a program that meets the following requirements:
•
checks the account ID exists and the name and password entered by the account holder
match the name and password stored in Account[] before any action can take place
•
displays a menu showing the four actions available for the account holder to choose from:
1. display balance
2. withdraw money
3. deposit money
4. exit
•
allows an action to be chosen and completed. Each action is completed by a procedure
with a parameter of the account ID.
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 only need to declare any local arrays and local variables that you use.
You do not need to declare and initialise the data in the global arrays Account[] and
AccDetails[] and the variable Size
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
Tick (3) one box to complete the sentence.
A constant
A
stores a value that can change at any time during the execution of a program.
B
stores a value that cannot change during the execution of a program.
C
stores values of multiple data types.
D
stores values that must be of the same data type.
[1]
Question text
2
Explain the purpose of the library routines MOD and RANDOM
MOD …
…
…
…
RANDOM …
…
…
…
[4]
Question text
3
Describe what happens when a function is called during the execution of a program.
…
…
…
…
…
… [3]
Question text
6
An algorithm has been written in pseudocode to allow 100 positive numbers to be input. The total
and the average of the numbers are output.
100
01
Counter
0
02
Total
03
WHILE Counter > 100 DO
04
INPUT Number
05
IF Number > 0
06
THEN
Total + Counter
07
Total
Counter + 1
08
Counter
09
ENDCASE
10
ENDWHILE
11
OUTPUT "The total value of your numbers is ", Total
12
OUTPUT "The average value of your numbers is ", Total / 100
(a) Identify the four errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Describe the changes you should make to the corrected algorithm so that a count-controlled
loop is used to allow 100 positive numbers to be input.
You do not need to rewrite the algorithm.
…
…
…
…
…
…
…
…
…
… [5]
Question text
7
The flowchart represents an algorithm.
An input of –1 will terminate the algorithm.
START
Total
0
INPUT
Value
IS
Yes
Value =
–1 ?
No
OUTPUT
OUTPUT
Total
"Rejected"
Five1
Value DIV 5
STOP
Value / 5
Five2
IS
No
Five1 =
Five2 ?
Yes
Value DIV 10
Ten1
Value / 10
Ten2
IS
No
Ten1 =
Ten2 ?
Yes
Total + Value
Total
(a) Complete the trace table for the input data:
5, 50, 52, 555, 57, 500, –1, 5500, 55
Total
Value
Five1
Five2
Ten1
Ten2
OUTPUT
[6]
(b) Describe the purpose of the algorithm.
…
…
…
… [2]