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

23 questions · page 2 of 2 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
16
9608/21/O/N/17 · Question 2Oct/Nov 2017Paper 2116 marks
Loading question…
Question text

2
The following pseudocode represents a simple algorithm.
DECLARE NumberFound, Remainder, Number : INTEGER
DECLARE StartNumber, EndNumber, Divisor : INTEGER
INPUT StartNumber
INPUT EndNumber
INPUT Divisor
0
NumberFound
StartNumber TO EndNumber
FOR Number
MODULUS(Number, Divisor)
Remainder
IF Remainder = 0
THEN
OUTPUT Number
NumberFound + 1
NumberFound
ENDIF
ENDFOR
OUTPUT "Count: " & NumberFound
For the built-in functions list, refer to the Appendix on page 14.
(a) Complete the following trace table.
StartNumber
EndNumber
Divisor
NumberFound
Number
Remainder
Output
11
13
2
0
[3]
(b) Describe the purpose of this algorithm.
…
…
…
…
…
… [3]
(c) Draw a program flowchart to represent this algorithm.
Variable declarations are not required in program flowcharts.
[10]

17
9608/22/O/N/17 · Question 2Oct/Nov 2017Paper 2211 marks
Loading question…
Question text

2
A 1D array, ClassName, of type STRING contains 100 elements.
The following pseudocode represents a simple algorithm to process the array.
DECLARE SearchValue : STRING
DECLARE FoundFlag : BOOLEAN
DECLARE Index : INTEGER
INPUT SearchValue
FALSE
FoundFlag
1
Index
WHILE Index < 101 AND FoundFlag = False
IF ClassName[Index] = SearchValue
THEN
OUTPUT Index
TRUE
FoundFlag
ENDIF
Index + 1
Index
ENDWHILE
IF FoundFlag = FALSE
THEN
OUTPUT "Not found"
ENDIF
(a) Describe the purpose of the algorithm.
…
…
…
…
…
… [2]
(b) Draw a program flowchart to represent this algorithm.
Note that variable declarations are not required in program flowcharts.
[9]

18
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]

Advertisement
19
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.
…
…
…
…
…
…
…
…
…
…
…
…
…

20
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.
…
…
…
…
…
…
…
…
…
…
…
…

21
9608/21/O/N/16 · Question 1Oct/Nov 2016Paper 2114 marks
Loading question…
Question text

1
A programmer wants to write a program to calculate the baggage charge for a passenger’s airline
flight.
Two types of ticket are available for a flight:
•
economy class (coded E)
•
standard class (coded S)
Each ticket type has a baggage weight allowance as shown below. The airline makes a charge if
the weight exceeds the allowance.
Ticket type
Baggage allowance
Charge rate per additional kg
(kg)
($)
'E'
16
3.50
'S'
20
5.75
(a) A program flowchart will document the program. The flowchart will contain the following
statements:
Statement
Statement
number
0
Charge
1
INPUT BaggageWeight
2
ExcessWeight * ChargeRate
Charge
3
Is ExcessWeight > 0 ?
4
INPUT TicketType
5
BaggageWeight - BaggageAllowance
ExcessWeight
6
BaggageAllowance
16
7
3.5
ChargeRate
8
OUTPUT Charge
9
5.75
ChargeRate
10
BaggageAllowance
20
11
Is TicketType = 'E' ?
12
Complete the flowchart by putting the appropriate statement number in each flowchart
symbol. Statement 5 has been done for you.
Start
5
Stop
[6]
(b) The programmer needs data to test the flowchart.
Complete the table of test data below to show five tests.
TicketType
BaggageWeight
Explanation
Expected output
…
E
15
…
…
…
…
…
…
…
…
…
…
…
…
…
…
[5]
(c) The program design is to be amended. The value input by the user for the ticket type is to be
validated. Part of the amended flowchart is shown below.
Start
Loop
INPUT TicketType
Is
TicketType
E or S ?
No
Yes
Write pseudocode to use a pre-condition loop for this validation.
…
…
…
…
…
… [3]

22
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).
…
…
…
…
…
…
…
…
…
…
…
…
…
…

23
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