Programming – IGCSE Computer Science (0478)
270 questions · page 9 of 18 · Clear filters
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]
Question text
9
The variable Saying is used to store string data in a program.
(a) Write the pseudocode statement to declare the variable Saying
…
… [1]
(b) Write the pseudocode statements to:
•
allow a string to be input to the variable Saying
•
store the content of the variable Saying in a text file named "Quotations.txt"
•
make sure the text file is closed at the end of the algorithm.
…
…
…
…
…
…
…
…
…
… [5]
Question text
11
A two-dimensional (2D) array Contacts[] is used to store names and telephone numbers. All
the data is stored as strings. The array must have the capacity to store 100 contacts in the form of:
•
column 1 – contact names as: last name, first name
for example: Smith, John
•
column 2 – telephone numbers.
The variable CurrentSize shows how many contacts are in the array.
Write a program that meets the following requirements:
•
display a menu of choices:
○ enter new contact details
○ display all the contact details
○ delete all the contact details
•
validate the menu input
•
allow up to a maximum of five new contacts to be added to the array at any one time
•
do not allow more than 100 contacts in total
•
after new contacts have been added, sort the array by contact name, as long as there are at
least two contacts in the array
•
output the whole of the array
•
delete the contents of the array.
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.
You do not need to initialise the data in the array Contacts[] and the variable CurrentSize
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
Tick (3) one box to show which word accurately describes the scope of a variable declared in a
procedure.
A
Function
B
Global
C
Local
D
Subroutine
[1]
Question text
2
(a) Four descriptions and five pseudocode statements are shown.
Draw one line to link each description to its most appropriate pseudocode statement.
Not all pseudocode statements will be used.
Description
Pseudocode statement
a statement to count
FOR Count
1 TO 10
Value
Value + NewValue
a statement to total
WHILE Value > 10 DO
a statement to start a
pre-condition loop
Value
Value + 1
REPEAT
a statement to start a
post-condition loop
[4]
(b) Write an algorithm in pseudocode, using a single loop, to output the average of 50 numbers
that have been stored in the array Number[]
…
…
…
…
…
…
…
…
…
… [5]