Programming – IGCSE Computer Science (0478)
270 questions · page 10 of 18 · Clear filters
Question text
4
Describe how variables and constants are used in programming.
…
…
…
…
…
…
…
… [3]
Question text
6
The energy efficiency of an electrical appliance is the percentage of useful energy out compared with
the total energy in.
An algorithm has been written in pseudocode to calculate the energy efficiency of an appliance.
Values for total energy in and useful energy out are input. The efficiency is calculated and output
as a percentage.
The entry of the number –1 for either value stops the algorithm.
01 REPEAT
02
OUTPUT "Enter total energy in "
03
INPUT TotalEnergyIn
04
OUTPUT "Enter useful energy out "
05
OUTPUT UsefulEnergyOut
06
IF TotalEnergyIn <> -1 AND UsefulEnergy <> -1
07
THEN
(UsefulEnergyOut / TotalEnergyIn) * 100
08
Efficiency
09
OUTPUT "Efficiency is ", Efficiency, "%"
10
ENDIF
11 UNTIL TotalEnergyIn <> -1 OR UsefulEnergyOut <> -1
(a) Identify the three errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
[3]
(b) Write pseudocode to check for an efficiency of 92% or over for this appliance and to output
“A-rated” if the efficiency is 92% or over.
…
…
…
…
… [2]
Question text
10 The variables X, Y and Z are used in a program: X stores a whole number, Y stores a decimal
number and Z stores a flag that can be set to TRUE or FALSE
(a) Write pseudocode statements to declare the variables X, Y and Z
…
…
… [3]
(b) The function Same(A,B) returns TRUE if the value of A is the same as the value of B when B
is rounded to the nearest whole number and FALSE otherwise.
Write pseudocode statements to:
•
define the function
•
call the function with X and Y and store the return value in Z
Function definition …
…
…
…
…
…
…
…
Function call …
…
…
…
[6]
(c) State the difference between defining and calling a function.
…
… [1]
Question text
11
The one-dimensional (1D) array TeamName[] contains the names of teams in a sports league.
The two-dimensional (2D) array TeamPoints[] contains the points awarded for each match.
The position of each team’s data in the two arrays is the same. For example, the team stored at
index 10 in TeamName[] and TeamPoints[] is the same.
The variable LeagueSize contains the number of teams in the league. The variable MatchNo
contains the number of matches played. All teams have played the same number of matches.
The arrays and variables have already been set up and the data stored.
Each match can be played at home or away. Points are recorded for the match results of each
team with the following values:
•
3 – away win
•
2 – home win
•
1 – drawn match
•
0 – lost match.
Write a program that meets the following requirements:
•
calculates the total points for all matches played for each team
•
counts the total number of away wins, home wins, drawn matches and lost matches for each
team
•
outputs for each team:
–
name
–
total points
–
total number of away wins, home wins, drawn matches and lost matches
•
finds and outputs the name of the team with the highest total points
•
finds and outputs the name of the team with the lowest total points.
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 arrays TeamName[] and TeamPoints[] or the
variables LeagueSize and MatchNo
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Describe the arrays you have set up in Task 1 to record the members’ details. Include in
your description the name, data type and sample data for each array.
…
…
…
…
…
…
…
…
…
… [5]
(ii)
Explain how your program for Task 1 populated the arrays with the members’ details.
…
…
…
…
…
… [2]
(b) Explain how your program removed the members that have not paid their fees from the
system in Task 3.
…
…
…
… [2]
(c) Write an algorithm for the part of Task 3 that checks the age of all the members, and whether
they are in a team, then updates the type of membership and the annual fee if required.
Use pseudocode, programming statements or a flowchart.
…
…
…
…
Question text
2
An algorithm has been written to:
•
set 100 elements of the array Reading[1:100] to zero
•
input integer values between 1 and 100
•
end the process with an input of –1
•
reject all other values
•
count and output the number of times each value is input, starting with the largest value.
(a) Complete the pseudocode algorithm:
1 TO …
01
FOR Count
0
O2
Reading[Count]
03
NEXT Count
04
OUTPUT "Please enter next reading "
05
INPUT Value
06
WHILE Value <> -1 DO
IF Value <= 0 OR …
07
08
THEN
09
OUTPUT "Reading out of range"
10
ELSE
…
11
Reading[Value]
12
ENDIF
13
OUTPUT "Please enter next reading "
…
14
15
ENDWHILE
100
16
Count
17
REPEAT
OUTPUT "There are ", … ,
18
" readings of ", Count
…
19
Count
20
UNTIL Count = 0
[6]
(b) Describe how the algorithm could be changed so that it does not output any counts of zero.
…
…
…
…
…
… [3]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one constant you could have used for Task 1 and state its value.
Constant …
Value …
[2]
(ii)
Identify one array you could have used in Task 1 and describe its use.
Array …
Use …
…
…
[2]
(b) Describe how your program could validate the input for the day number within the two-week
period to make sure an appropriate value is entered (part of Task 1).
You must include programming statements as part of your answer.
…
…
…
…
…
…
…
…
…
…
…
… [3]
(c) Write an algorithm to show how your program allocates a parking space if the visitor requires
accessible parking (part of Task 2), including all relevant input and output, using pseudocode,
programming statements or a flowchart.
…
…
…
…
…
Question text
2
Draw a line to connect each programming concept to the most appropriate description.
Programming concept
Description
carrying out an action multiple times within a loop
structure
counting
adding together the numbers in a list of numbers
repetition
tracking the number of iterations a program has
selection
performed in a loop
sequence
branching off to take a course of action depending
on the answer to a question
totalling
a set of statements to be executed in order
[4]
Question text
5
This pseudocode should allow 500 marks to be entered into the algorithm. If the mark is 80 or
greater it is stored in an array for higher marks. If the mark is less than 80, but greater than or
equal to 50 it is stored in an array for middle marks. The remaining marks are stored in an array
for lower marks. The results from the algorithm are displayed at the end.
0
01
HighList
0
02
MidList
0
03
LowList
0
04
MarksEntry
05
REPEAT
06
INPUT Mark
07
IF Mark >= 80
08
THEN
MarksEntry
09
Higher[HighList]
HighList + 1
10
HighList
11
ELSE
12
IF Mark >= 50
13
THEN
Mark
14
Middle[MidList]
MidList
15
MidList
16
ELSE
Mark
17
Lower[HighList]
LowList + 1
18
LowList
19
ENDIF
20
ENDIF
MarksEntry + 1
21
MarksEntry
22
NEXT MarksEntry = 500
23
OUTPUT "You entered ", HighList, " higher marks"
24
OUTPUT "You entered ", MidList, " middle marks"
25
OUTPUT "You entered ", LowList, " lower marks"
(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) The corrected algorithm needs to be changed so that any number of marks may be entered
and the algorithm runs until the user tells it to stop.
Write the new pseudocode statements that would be needed to achieve this and state where
in the algorithm they would be placed.
…
…
…
…
…
…
…
Question text
6
This flowchart represents an algorithm to divide three-digit numbers into hundreds, tens and units.
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
START
Counter
0
Counter
Counter + 1
IS
Yes
Counter > 7?
No
INPUT
Number
IS
Yes
Number < 100?
No
IS
Yes
Number > 999?
No
Hundreds
Number DIV 100
Temp
Number MOD 100
Tens
Temp DIV 10
Units
Number MOD 10
STOP
OUTPUT "Hundreds: ",
Hundreds, " Tens: ",
Tens, " Units: ", Units
Complete the trace table for the algorithm using this input data:
97, 876, 4320, 606, 9875, 42, 124
Counter
Number
Hundreds
Temp
Tens
Units
OUTPUT
[5]
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.
State the value that would be assigned to the constant.
Give a reason why a constant was used rather than a variable.
Constant name …
Value …
Reason …
…
…
[3]
(ii)
Describe the array that you set up in Task 1 to record the customer details.
Include the name, data type and sample data for the array in your description.
…
…
…
…
…
… [3]
(b) Explain how your program allowed only two floors or three floors to be chosen but not both.
…
…
…
…
…
… [3]
(c) Write an algorithm for the part of Task 2 that calculates the total cost of the bill.
Assume that the customer details and services required have already been input.
Use pseudocode, programming statements or a flowchart.
…
…
…
…
…
…
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]