Programming – IGCSE Computer Science (0478)
270 questions · page 18 of 18 · Clear filters
Question text
3
The flowchart below inputs the price of an item under $10. The change from a $10 note is output.
Any amount less than 5 cents is rounded up to 5 cents.
The predefined function INT rounds a number down to the nearest whole number; for example
Z ← INT(5.7) gives the value Z = 5
START
INPUT Price
Change
10 – Price
Is
Yes
Change
Dollars
INT(Change)
>= 1?
No
Change
Change – INT(Change)
OUTPUT Dollars,
" dollars"
Is
Yes
Change
Change
Change – 0.5
>= 0.5?
No
OUTPUT "One 50
cent coin"
TenCents
INT(Change * 10 + 0.5)
OUTPUT TenCents,
" ten cent coins"
Is Change*10 –
OUTPUT "One 5
Yes
TenCents
cent coin"
> 0?
No
END
Complete the trace table for the input data: 6.29
Price
Change
Dollars
TenCents
OUTPUT
[5]
Question text
REPEAT ... UNTIL
WHILE ... DO ... ENDWHILE are two different loop
5
and
structures you can use when writing pseudocode.
Explain, using examples, why you would choose to use each type of loop.
Example 1 …
…
…
…
Reason for choice …
…
…
Example 2 …
…
…
…
Reason for choice …
…
… [6]
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
For three of the variables that you have used in Task 1, state the name, type and its use.
Variable 1 name …
Type …
Use …
Variable 2 name …
Type …
Use …
Variable 3 name …
Type …
Use … [3]
(ii)
Name and describe the data structure(s) that you have used to store the donation totals
for each charity. Explain why you chose your data structure(s).
Name of data structure(s) …
Description …
…
Reason …
… [3]
(b) Write an algorithm to complete Task 2, using either pseudocode, programming statements
or a flowchart. You can assume that Task 1 has been completed.
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
Read this section of program code that inputs positive numbers, discards any negative numbers
and then outputs the average. An input of zero ends the process.
1
Total = 0
2
Counter = 100
3
REPEAT
4
REPEAT
5
INPUT Num
6
UNTIL Num < 0
7
Total = Total + 1
8
Counter = Counter + Num
9
UNTIL Num = 0
10
Average = Total / (Counter - 1)
11
Print Average
There are four errors in this code.
Locate these errors and suggest a correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
… [8]
Question text
The flowchart below inputs an integer. The predefined function DIV gives the value of the division,
3
for example Z ← 11 DIV 3 gives the value Z = 3. The predefined function MOD gives the value
of the remainder, for example Z ← 11 MOD 3 gives the value Z = 2.
67$57
,1387 ;
1R
Is X >
"
<HV
$
; ',9
287387 ;
%
; 02'
(1'
287387 %
;
$
Complete a trace table for each of the two input values 33 and 75.
Trace table for input value 33
X
A
B
OUTPUT
Trace table for input value 75
X
A
B
OUTPUT
[4]
Question text
IF ... THEN ... ELSE ... ENDIF and CASE ... OF ... OTHERWISE ... ENDCASE
4
are two different conditional statements that you can use when writing pseudocode.
Explain, using examples, why you would choose to use each conditional statement.
Example 1 …
…
…
…
…
…
Reason for choice …
…
…
Example 2 …
…
…
…
…
…
Reason for choice …
…
… [6]
Question 5 begins on page 10.
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
For each of the variables that you have used to record dimensions of the parcels in Task 1,
state the name, type and its use.
Variable 1 name …
Type …
Use …
Variable 2 name …
Type …
Use …
Variable 3 name …
Type …
Use … [3]
(ii)
State two constants that you could have used for Task 1. Give the value that would be
assigned to each one.
Constant 1 name …
Value 1 …
Constant 2 name …
Value 2 … [2]
(b) Write an algorithm to complete Task 1, using either pseudocode, programming statements
or a flowchart.
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
Read this section of program code that inputs 10 positive numbers and then outputs the smallest
number input.
1
Small = 1000
2
Counter = 0
3
REPEAT
4
INPUT Num
5
IF Num < Small THEN Small = Num
6
Counter = Counter + 1
7
UNTIL Counter = 10
8
PRINT Small
(i)
Identify three changes you would need to make to find the largest number input instead
of the smallest number.
1 …
…
2 …
…
3 …
… [3]
(ii)
Rewrite the program code with your changes.
…
…
…
…
…
…
…
… [3]
Question text
3
A program will be written to store information about members of a swimming club.
The following membership details will be recorded:
•
Name
•
Gender
•
Status:
•
Senior
•
Junior
•
Fee
•
Team member (Yes or No)
(i)
Choose a suitable data type for each of the membership details to be recorded.
Membership details
Data type
Name
Gender
Status
Fee
Team member
[5]
(ii)
The swimming club has 50 members.
State the data structure that would be most suitable to use and give a reason for your
choice.
Data structure …
Reason …
… [2]
Question text
REPEAT ... UNTIL is one type of loop structure.
5
Identify and describe two other types of loop structure that you could use when writing
pseudocode.
Loop structure 1 …
Description …
…
Loop structure 2 …
Description …
… [4]
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
For three of the variables that you have used in Task 2, state the name, type and its use.
Variable 1 name …
Type …
Use …
Variable 2 name …
Type …
Use …
Variable 3 name …
Type …
Use … [3]
(ii)
State three constants that you could have used for Task 1. Give the value that would be
assigned to each one.
Constant 1 name …
Value 1 …
Constant 2 name …
Value 2 …
Constant 3 name …
Value 3 … [3]
(b) Write an algorithm to complete Task 2, using either pseudocode, programming statements
or a flowchart. You can assume that the weight and contents have already been checked and
accepted in Task 1. You do not need to output the number of sacks rejected.
…
…
…
…
…
…
…
…
…
…
Question text
2
Read this section of program code that inputs 10 positive numbers and then outputs the total.
1
Total = 0
2
Counter = 0
3
REPEAT
4
INPUT Num
5
Total = Total + Num
6
PRINT Total
7
Counter = Counter + 1
8
UNTIL Counter = 10
This code works, but it is inefficient.
(i)
Suggest three improvements that could be made.
1 …
…
2 …
…
3 …
… [3]
(ii) Rewrite the program code with your improvements.
…
…
…
…
…
…
…
…
…
… [3]
Question text
4
Four statement types and four examples are shown below.
Draw a line to connect each statement type to the correct example.
Statement type
Example
1 TO 10
FOR X
Assignment
READ X
Iteration
PRINT X
Input
X
Y + Z
Output
[3]
Question text
5
A programmer writes a program to store a patient’s temperature every hour for a day.
State the data structure that would be most suitable to use and give the reason for your choice.
Data structure …
Reason …
… [2]
Question text
6
Identify two different selection statements that you can use when writing pseudocode.
1 …
…
2 …
… [2]
Question 7 begins on page 10.