Algorithm design and problem-solving – A Level Computer Science (old syllabus, to 2021) (9608)

13 questions · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
9608/21/M/J/20 · Question 1May/June 2020Paper 218 marks
Loading question…
Question text

1
(a) Complete this definition of the term algorithm.
An algorithm is a solution to a problem expressed as …
…
… [2]
(b) A program design includes the use of subroutines (functions and procedures).
Give three advantages of using subroutines in a program.
1 …
…
2 …
…
3 …
…
[3]
(c) Draw lines on the following diagram to connect each computing term with the appropriate
description.
Term
Description
Checking that a program
Selection
performs as expected
A method for increasing the
Black-box testing
level of detail of an algorithm
To test a condition to determine
Stepwise refinement
the path of program execution
A method of executing certain
Iteration
lines of code more than once
[3]

2
9608/22/M/J/20 · Question 1May/June 2020Paper 2210 marks
Loading question…
Question text

1
(a) Selection and repetition are basic constructs of an algorithm.
Name and describe one other construct.
Name …
Description …
…
…
[3]
(b) Program coding is a transferable skill.
Explain the term transferable skill.
…
…
…
… [2]
(c) Count-controlled and post-condition are two types of loop.
Describe the characteristics of each of these types of loop.
Count-controlled …
…
…
Post-condition …
…
…
[2]
(d) Name three features provided by an Integrated Development Environment (IDE) that assist
in the coding and initial error detection stages of the program development cycle.
1 …
2 …
3 …
[3]

3
9608/23/M/J/20 · Question 1May/June 2020Paper 238 marks
Loading question…
Question text

1
(a) Algorithms are produced during program development.
State when you would produce an algorithm during program development and state its
purpose.
When …
…
Purpose …
…
[2]
(b) Selection is one of the basic constructs used in algorithms.
Explain the term selection.
…
…
…
… [2]
(c) Explain the process of problem decomposition. State one reason it may be used.
Explanation …
…
…
Reason …
…
…
[2]
(d) Name two features provided by a typical Integrated Development Environment (IDE) that
assist in the debugging stage of the program development cycle.
1 …
2 …
[2]

Advertisement
4
9608/23/M/J/20 · Question 3May/June 2020Paper 2310 marks
Loading question…
Question text

3
(a) Study the following pseudocode.
Delta(Plan, Actual)
Error
CASE OF Error
Steer − 10
> 10 : Steer
ZCount + 1
0 : ZCount
Steer + 10
< -10 : Steer
OTHERWISE OUTPUT "Unexpected Error"
ENDCASE
Draw a program flowchart to represent the pseudocode. Variable declarations are not
required in program flowcharts.
[5]
(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.
To be a valid password, a string must:
•
be longer than five characters
•
contain at least one numeric digit
•
contain at least one upper case letter
•
contain at least one other character (not a numeric digit or an upper case letter).
10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN
11
12
DECLARE Index : INTEGER
13
DECLARE StrLen : INTEGER
14
DECLARE NumUpper, NumDigit : INTEGER
15
DECLARE NextChar : CHAR
16
DECLARE NumOther : INTEGER
17
0
18
NumUpper
0
19
NumDigit
20
LENGTH(InString)
21
StrLen
22
IF StrLen < 6
23
THEN
24
RETURN FALSE
25
ELSE
1 TO StrLen - 1
26
FOR Index
27
// loop for each character
MID(InString, Index, 1)
28
NextChar
29
IF NextChar >= '0' AND NextChar <= '9'
30
THEN
NumDigit + 1 // count digits
31
NumDigit
32
ELSE
33
IF NextChar >= 'A' AND NextChar <= 'Z'
34
THEN
NumUpper + 1 // count upper case
35
NumUpper
36
ENDIF
37
ENDIF
38
ENDFOR
39
ENDIF
40
StrLen – (NumDigit – NumUpper)
41
NumOther
42
IF NumDigit >= 1 AND NumUpper >= 1 AND NumOther >= 1
43
THEN
44
RETURN TRUE
45
ELSE
46
RETURN FALSE
47
ENDIF
48
49 ENDFUNCTION
The pseudocode does not work under all circumstances.
The function was dry run with the string "1234AP" and the following trace table was
produced. The string is an invalid password, but the pseudocode returned the value
TRUE.
Trace
StrLen
Index
NextChar
NumUpper
NumDigit
NumOther
table row
6
0
0
1
1
'1'
2
1
3
2
'2'
4
2
5
3
'3'
6
3
7
4
'4'
8
4
9
5
'A'
10
1
11
3
12
(i)
The pseudocode algorithm contains two errors.
State how the given trace table indicates the existence of each error.
Error 1 …
…
…
…
Error 2 …
…
…
…
[2]
(ii)
Give the line number of each error in the pseudocode algorithm and write the modified
pseudocode to correct each error.
Line number for error 1 …
Correct pseudocode …
…
Line number for error 2 …
Correct pseudocode …
…

5
9608/22/M/J/19 · Question 5May/June 2019Paper 229 marks
Loading question…
Question text

5
A student is learning about text files. She wants to write a program to count the number of lines in
a file.
(a) Use structured English to describe an algorithm she could use.
…
…
…
…
…
… [3]
(b) A procedure, CountLines(), is being written to count the number of lines in a text file. The
procedure will:
•
take a filename as a string parameter
•
count the number of lines in the file
•
output a single suitable message that includes the total number of lines.
Write pseudocode for the procedure CountLines().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

6
9608/21/M/J/18 · Question 3May/June 2018Paper 218 marks
Loading question…
Question text

In a chemical factory, a procedure, CheckSensor() is required to allow an operator to monitor
3
the temperature in different locations.
In the factory:
•
the temperature is measured by 10 sensors, each at a different location
•
each sensor has a unique ID (1 to 10).
The procedure CheckSensor() will compare the measured temperature against each of two
constant values, LowTemp and HighTemp. It will perform the following actions depending on the
result of the comparison.
Measured temperature
Action
below LowTemp
Output "Cold"
from LowTemp to HighTemp
Output "Normal"
above HighTemp
Call procedure Alarm()
A library function, GetTemp(), returns the temperature value from a given sensor.
The structured English representing the algorithm for the procedure CheckSensor() is as
follows:
1.
Prompt for the input of a sensor ID.
2.
Input a sensor ID.
3.
If the sensor ID is invalid, repeat from step 1.
4.
Call the GetTemp() function with the sensor ID as the parameter, to obtain the relevant
temperature.
5.
Compare the temperature against the two constant values and take the appropriate action.
Draw a program flowchart on the next page to represent the algorithm for procedure
CheckSensor().
Variable declarations are not required in program flowcharts.
[8]

7
9608/22/M/J/18 · Question 3May/June 2018Paper 2211 marks
Loading question…
Question text

3
A chocolate factory produces bars of chocolate. A computer program controls the process.
The weight of each bar is stored in an array, BarWeight. The array contains 100 elements,
representing the weights of 100 bars that make up one shipping box.
A procedure, CheckWeight(), is required to:
1.
examine each array element and count how many times the weight has exceeded MaxWeight
2.
compare the count obtained with a limit value, Threshold. Call procedure ServiceCheck()
if the count exceeds the Threshold
3.
output a message if the count does not exceed the Threshold. For example:
"ShippingBox OK – maximum weight exceeded 3 times."
Draw a program flowchart on the next page to represent the algorithm for the CheckWeight()
procedure.
Assume that:
•
the array contains 100 valid weight values and the first element is BarWeight[1]
•
MaxWeight, Threshold and BarWeight are global variables.
Variable declarations are not required in program flowcharts.
[10]
Question 4 begins on the next page.

8
9608/23/M/J/18 · Question 4May/June 2018Paper 2310 marks
Loading question…
Question text

4
A program controls a chemical process in a factory.
The temperature is monitored as part of the control process. The temperature is measured at
fixed time intervals and the value is stored in an array, PTemp. The array contains 100 elements,
representing 100 temperature values. The first element is PTemp[1].
The program will check whether the temperature is outside the acceptable range more than 20
times. This task is performed by a function, IsTempOK().
The algorithm for the function IsTempOK() is expressed in structured English as follows:
1
Examine each array element and count the number of times that a temperature is less than
MinTemp or more than MaxTemp.
2
If the count in step 1 exceeds 20, return FALSE, otherwise return TRUE.
Draw a program flowchart, on the next page, to represent the algorithm for the function
IsTempOK().
Assume:
•
the array contains 100 valid temperature values
•
PTemp, MinTemp and MaxTemp are global variables.
Note that variable declarations are not required in program flowcharts.
[9]

Advertisement
9
9608/21/M/J/17 · Question 1May/June 2017Paper 2116 marks
Loading question…
Question text

1
(a) Simple algorithms usually consist of three different stages.
Complete the following table.
Add a description of the stage and an example pseudocode statement.
The first stage has been given.
Stage
Description and example
Description: …
…
Input
Pseudocode example: …
…
Description: …
…
…
Pseudocode example: …
…
Description: …
…
…
Pseudocode example: …
…
[7]
(b) (i)
AND and OR are two operators that may be used when implementing an algorithm.
An example of their use is given in the following pseudocode statement:
VarA OR VarB
MyFlag
State the data type of variable MyFlag.
… [1]
(ii)
State the name given to the type of operators to which AND and OR belong.
… [1]
(iii)
Evaluate the expressions given in the following table when the variable values are as
follows:
TRUE
FlagA
FALSE
FlagB
TRUE
FlagC
Expression
Evaluates to
FlagA AND (FlagB OR FlagC)
FlagA AND (FlagB AND FlagC)
(NOT FlagA) OR (NOT FlagC)
[3]
(c) A common construct found in many algorithms is a loop.
Using pseudocode, write a pre-condition loop to output all of the even numbers between 99
and 201.
…
…
…
…
…
…
…
…
… [4]

10
9608/21/M/J/17 · Question 2May/June 2017Paper 2114 marks
Loading question…
Question text

2
One of the security features of a multi-user computer system is a user login process. The user
must complete this successfully before they can access the resources of the system.
As part of the login process the user enters their user ID followed by a password. The system then
compares the password entered with the password held in a file.
(a) The steps involved in the login process are described as follows:
•
User enters their ID and password.
•
Validation checks:
Compare user ID with data from the file.
Indicate whether or not the user ID was found.
If user ID found, check whether passwords match.
The description above is not detailed enough to allow a program to be written. The validation
checks must be expressed as a more detailed algorithm.
Give the name of the process of increasing the level of detail of the algorithm.
… [1]
(b) An identifier table is created as the algorithm is developed. A section of the table is shown.
Complete the table.
Identifier
Data Type
Description
…
Stores the user ID entered
UserIDInput
…
…
PasswordInput
…
…
…
UserIDFound
…
…
…
PasswordValid
…
[5]
(c) The validation checks described in part (a) are to be used as the basis for program code.
Use structured English to write a more detailed algorithm.
You should:
•
use the identifiers given in the previous table
•
assume that the password file, password.txt, is organised as a simple text file. The
user ID and password are stored together, one entry per line.
…
…
…
…
…
…
…
…
…
…
…
…
…

11
9608/22/M/J/17 · Question 2May/June 2017Paper 2215 marks
Loading question…
Question text

2
A multi-user computer system maintains a text file containing the ID and preferred name for each
user.
User IDs are unique. Preferred names may be repeated.
(a) Stepwise refinement is to be applied to the following three steps.
After a user logs in, a welcome message is produced as follows:
1. Search for the user ID in the file.
2. Read the preferred name from the file.
3. Output the welcome message.
Describe the goal of stepwise refinement.
…
…
…
… [2]
(b) An initial identifier table is created as part of the stepwise refinement. A section of the table is
shown. Complete this table.
Identifier
Data type
Description
Stores the user ID entered
SearchUserID
…
FileUserID
…
…
FilePreferredName
…
…
IDFoundFlag
…
[5]
(c) The file may not contain an entry for every user. If the user ID is not found, then the name
“Guest” should be used as the preferred name.
Use structured English to write a more detailed algorithm for the welcome message process
described in part (a).
Use the identifiers given in the previous table.
Assume that the file, UserNames.txt, is organised as a simple text file. The user ID and
preferred name are held together in unencrypted form, one entry per line.
…
…
…
…
…
…
…
…
…
…
…
…

12
9608/21/M/J/16 · Question 2May/June 2016Paper 2110 marks
Loading question…
Question text

2
A team is designing a software system to monitor temperature in a process. To do this, the system
needs to sample the temperature repeatedly. If the temperature exceeds a given threshold value,
an alarm will sound.
The system is to be software-based. It will include a subroutine, SampleTemp, which samples the
temperature and sets the alarm state to either ON or OFF.
The initial design stage will produce a prototype of SampleTemp with a user interface.
The structured English for this is:
1.
IF the temperature does not exceed threshold value, SET alarm state to OFF
2.
INPUT threshold value (to two decimal places)
3.
INPUT sensor value (a whole number in the range 0 to 100)
4.
MULTIPLY sensor value by conversion factor 1.135 to give temperature
5.
IF temperature exceeds threshold value SET alarm state to ON
6.
IF temperature exceeds threshold value OUTPUT message “Temperature Alarm”
7.
IF temperature does not exceed threshold value OUTPUT message “Temperature OK”
(a) The procedure needs four variables. Complete the identifier table below for these variables.
Identifier
Data type
Description
…
AlarmState
…
…
SensorValue
…
…
ThresholdValue
…
…
Temperature
…
[4]
(b) Write the pseudocode equivalent of the structured English. Use the identifiers from the table
in part (a).
…
…
…
…
…
…
…
…
…
…
…
…
…
…

13
9608/23/M/J/16 · Question 2May/June 2016Paper 2311 marks
Loading question…
Question text

2
The engine management system of a car includes an energy-saving facility. When certain
conditions are met, this facility will automatically stop the engine.
The system is to be software-based. It will include a subroutine, EnergySaver, which repeatedly
takes data from sensors in the car. The subroutine decides whether or not to set the EngineStop
value.
The table of identifiers used by this subroutine is shown below.
(a) Complete the identifier table below by stating the data types.
Identifier
Data type
Description
Accelerator pedal position
Values: 0 to 100 in steps of 1
Accelerator
…
Meaning:
0: none (not pressed)
100: maximum (fully pressed)
Engine temperature in °C
EngineTemp
…
(-50 to +150 stored to 1 decimal place)
Normal engine temperature in °C
NormalTemp
…
Whole number; typical value 90
Road speed of car (in km/hr)
Speed
…
Values: 0 to 200 in steps of 1
Value used to signal engine must be stopped
Possible values:
EngineStop
…
TRUE: stop engine
FALSE: run engine
[5]
The condition for stopping the engine is that all three of the following are true:
•
Accelerator is not pressed
•
Engine temperature is normal or above
•
Car speed is zero
The initial design stage will produce a prototype of EnergySaver, with a user interface.
The structured English for this is:
1.
INPUT value for accelerator pedal position
2.
INPUT value for engine temperature
3.
INPUT value for normal engine temperature
4.
INPUT value for car speed
5.
EVALUATE engine stopping condition
6.
IF stopping condition satisfied SET engine stop value to TRUE
7.
IF stopping condition not satisfied SET engine stop value to FALSE
8.
OUTPUT message indicating engine stop value
(b) Write the pseudocode equivalent of the structured English. Use the identifiers from the table
in part (a).
For the built-in functions list, refer to the Appendix on the last page.
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement