Algorithm design and problem-solving – A Level Computer Science (old syllabus, to 2021) (9608)
23 questions · page 1 of 2 · Clear filters
Question text
3
(a) Describe the term decomposition when used to develop algorithms.
…
…
…
…
…
… [3]
(b) Explain the term transferable skills and state how these skills are used in program
development.
…
…
…
… [2]
Question text
1
(a) Algorithms usually consist of three different stages.
One stage is INPUT.
Name the other stages.
1 …
2 …
[1]
(b) An algorithm may be documented using different methods. These include structured English,
a program flowchart, and pseudocode.
State what a program designer represents using one or more of these methods.
…
… [2]
(c) Programming languages support different data types.
Complete the table by giving four different data types together with an example data value
for each.
Data type
Example data value
[4]
(d) Draw lines to connect each of the following computing terms with the appropriate description.
Term
Description
A structure for the
Black-box testing
temporary storage of data
A method used when the
File
structure of the program is
unknown
A method of setting the
Assignment
value of a variable
A structure for the
Array
permanent storage of data
[3]
(e) A pseudocode algorithm assigns values to three variables as follows:
TRUE
FlagA
FALSE
FlagB
TRUE
FlagC
Evaluate the expressions given in the following table:
Expression
Evaluates to
NOT FlagB AND FlagC
NOT (FlagB OR FlagC)
(FlagA AND FlagB) OR FlagC
NOT (FlagA AND FlagB) OR NOT FlagC
[2]
Question text
2
(a) The following pseudocode is an attempt to define an algorithm that takes two numbers as
input and outputs the larger of the two numbers.
DECLARE A, B : INTEGER
INPUT A
INPUT B
IF A > B
THEN
OUTPUT A
ELSE
OUTPUT B
ENDIF
The algorithm needs to be amended to include the following changes:
Input three values, ensuring that each value input is unique.
1.
2.
Output the average.
3.
Output the largest value.
Write the pseudocode for the amended algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
(a) An algorithm is needed to input a list of numbers representing test marks for a class of
30 students.
The algorithm will output the number of students who have a mark greater than 75. It will also
output the average mark for the class.
Document the algorithm using structured English.
…
…
…
…
…
…
…
…
…
…
…
… [8]
(b) Each pseudocode statement in the following table contains an error.
State the error in each case.
Refer to the Appendix on page 16 for the list of built-in functions and operators.
Statement
Error
Code
LEFT(3, "Europe")
MID("ALARM:12:02", 7, 6)
Hour
LENGTH(27.5)
Size
INT(27 / (Count + 3)
Num
"Conditional" AND "Loop"
Result
[5]
(c) Part of a program flowchart is shown.
Set Index to 0
Set Status to FALSE
LOOP
Is
YES
Status = TRUE
?
NO
NO
Is Index > 100
?
Set Status to TopUp()
YES
SetLevel("Super")
Set Index to Index + 1
Write program code to implement the flowchart shown. Variable declarations are not
required.
Programming language …
Program code
…
…
…
…
…
…
…
…
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]
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]
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]
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 …
…
Question text
1
(a) (i)
Programming languages can support different data types.
Complete the table by naming three different data types together with an example data
value for each.
Data type
Example data value
[6]
(ii)
Identify the type of programming statement that assigns a data type to a variable.
… [1]
(b) As part of the development of an algorithm, a programmer may construct an identifier table.
Describe what an identifier table contains.
…
…
…
… [2]
(c) (i)
Simple algorithms usually consist of three different stages.
Complete the table below. Write each example statement in program code.
The second stage has already been given.
Stage
Example statement
Process
[5]
(ii)
Write a single statement in program code that contains two of the stages. Do not
repeat any of the statements from part (c)(i).
… [1]
(d) A software developer is writing a program and includes several features to make it easier to
read and understand. One of these features is the use of indentation.
State three other features.
Feature 1 …
Feature 2 …
Feature 3 …
[3]
(e) A trace table is often used during program testing.
Identify the type of testing that includes the use of a trace table.
… [1]
Question text
2
(a) (i)
Two types of loop that may be found in an algorithm are the ‘pre-condition’ and ‘post-
condition’ loop.
Identify one other type of loop. Explain when it should be used.
Type …
Explanation …
…
…
[2]
(ii)
Part of a program flowchart is shown.
LOOP
AlarmReset()
Set Status1 to
GetStatus(Sys_A)
Set Status2 to
GetStatus(Sys_B)
Are Status1
NO
and Status2
both TRUE?
YES
Implement the flowchart in pseudocode using a post-condition loop.
…
…
…
…
…
… [4]
(b) The following lines of code are taken from a high-level language program.
100
setvar(Count, Integer)
110
setvar(Gross[0-20], Real)
120
setvar(Posn, Real)
130
setvar(Length, Integer)
140
setvar(Rate, Real)
150
Length := 7
160
Rate := 1.175
170
180
For (Count, 0, 20, 2)
190
{
200
Echo "Input next cost"
210
Posn := Read()
220
Gross[Count] := Mult(Posn, Rate) %Apply current tax rate
230
}
Study the code. Identify the relevant features in the following table.
Feature
Answer
The symbol used to indicate an assignment
The line numbers for the start and end of a count-controlled loop
The step value of the count-controlled loop
The character that indicates a comment
The name of a function
[5]
(c) A program written in a high-level language cannot be run directly.
Identify one type of translator that can be used to translate the program.
… [1]
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().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
3
(a) Programming is sometimes referred to as a transferable skill.
You are asked to work on a program written in a language you are not familiar with.
Explain how transferable skills would help you work on the program.
…
…
…
… [2]
(b) Stepwise refinement is often used in the development of an algorithm.
Describe stepwise refinement.
…
…
…
… [2]
(c) A program needs to search through 1000 elements of an unsorted array to find a given value.
The program will output:
•
either the position in the array of the value
•
or the message “Not Found”
Outline the steps the program needs to follow.
Do not write pseudocode or program code.
…
…
…
…
…
…
…
…
…
…
… [4]
Question 4 begins on the next page.
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]
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.
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]