Programming – A Level Computer Science (old syllabus, to 2021) (9608)

130 questions · page 6 of 9

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
76
9608/22/O/N/18 · Question 4Oct/Nov 2018Paper 2222 marks
Loading question…
Question text

4
Part of a program written in pseudocode is shown.
010 DECLARE NextArrayElement : INTEGER
…
100 FUNCTION ScanFile(SearchString: STRING) RETURNS INTEGER
101
102
DECLARE FileData : STRING
103
DECLARE FileLine : INTEGER
104
105
NextArrayElement
1
106
FileLine
1
107
FileData
ReadFileLine("DataFile.txt", FileLine)
108
109
WHILE FileData <> ""
110
IF LEFT(FileData, 7) = SearchString
111
THEN
112
ResultArray[NextArrayElement]
FileData
113
NextArrayElement
NextArrayElement + 1
114
ENDIF
115
FileLine
FileLine + 1
116
FileData
ReadFileLine("DataFile.txt", FileLine)
117
ENDWHILE
118
119
CALL ScanCompleted()
120
RETURN FileLine
121
122 ENDFUNCTION
(a) (i)
Examine the pseudocode. Complete the following table.
Answer
The identifier name of a local variable
The identifier name of a user-defined procedure
The identifier name of a user-defined function
The number of dimensions of ResultArray
The scope of FileData
[5]
(ii)
Describe in detail the purpose of lines 109 to 117 in the ScanFile() function. Do not
use pseudocode in your answer.
…
…
…
…
…
… [4]
(b) The function ScanFile() is to be amended so that the first 7 characters of FileData are
not written to the array.
Write program code to implement this amended ScanFile() function.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…

77
9608/22/O/N/18 · Question 5Oct/Nov 2018Paper 2211 marks
Loading question…
Question text

5
The procedure LineNumber() will:
•
read data from a text file
•
modify each line by adding a line number, and the string (": ")
•
output each modified line.
For example, when the procedure reads MyFile.txt, the output is:
10: <First line of MyFile.txt>
15: <Second line of MyFile.txt>
20: <Third line of MyFile.txt>
…
350: <Last line of MyFile.txt>
The procedure takes three parameters:
Identifier
Data type
Description
FileName
The name of the text file
STRING
StartNumber
The first line number to be added
INTEGER
StepNumber
The line number increment
INTEGER
In this example, the procedure call would be:
CALL LineNumber("MyFile.txt", 10, 5)
After every 20 lines, the program outputs a message asking whether the user wants to continue.
The program ends when the user enters an 'N' or the end of file is reached.
Write pseudocode for the LineNumber() procedure.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

78
9608/23/O/N/18 · Question 1Oct/Nov 2018Paper 2316 marks
Loading question…
Question text

1
(a) The following table contains statements written in pseudocode.
Show the type of programming construct each statement represents.
Put a tick (3) in the appropriate column for each statement.
Repetition
Statement
Assignment
Selection
(Iteration)
CASE OF TempSensor1
ELSE
REPEAT
ENDFOR
DayNumber + 1
DayNumber
TRUE
Error
[6]
(b) (i)
The following table contains statements written in pseudocode.
Give the most appropriate data type for the variable used in each statement.
Statement
Data type
Revision
500
'P'
FuelType
-6.3
MinValue
FALSE
ServiceDue
"W212DEC15"
ModelRef
[5]
(ii)
The following table contains statements written in pseudocode.
Complete the table by evaluating each expression using the values from part (b)(i).
If any expression is invalid, write “ERROR” in the Evaluates to column.
For the built-in functions list, refer to the Appendix on page 16.
Expression
Evaluates to
"Month: " & MID(ModelRef, 5, 3)
INT(MinValue * 2)
ASC(Revision)
Revision > 500
ServiceDue = TRUE OR FuelType = 'P'
[5]

Advertisement
79
9608/23/O/N/18 · Question 2Oct/Nov 2018Paper 2321 marks
Loading question…
Question text

2
Shop customers have a discount card with a unique card number. Customers collect points when
they buy items. At the end of each year, customers are given bonus (extra) points related to the
total amount they have spent during the year, and the number of points they have on their card.
The function CalcBonus() takes the card number as a parameter. It returns the bonus points for
the customer. A flowchart for the function is shown.
The function uses the following variables and functions.
Identifier
Data type
Description
A numeric string representing the unique card number
CardNum
STRING
The number of points collected
Points
INTEGER
The total amount that customer has spent during the year
Spend
REAL
The number of bonus points
Bonus
INTEGER
Takes the card number as a parameter and returns the
GetPoints()
FUNCTION
number of points already collected
Takes the card number as a parameter and returns the
GetSpend()
FUNCTION
total amount that customer has spent during the year
START
Points
GetPoints(CardNum)
Spend
GetSpend(CardNum)
Is
YES
Points > 2000 ?
NO
Is
YES
Spend > 1000 ?
NO
Bonus
10
Bonus
50
Bonus
100
RETURN Bonus
END
(a) (i)
Write pseudocode for the CalcBonus() function.
Your solution should follow the flowchart for the function as closely as possible.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

80
9608/23/O/N/18 · Question 4Oct/Nov 2018Paper 2323 marks
Loading question…
Question text

4
Part of a program written in pseudocode is shown.
010 DECLARE ThisArray : ARRAY [1:100, 1:10] OF STRING
011 DECLARE LastElement : INTEGER
…
100 FUNCTION Update(NewData : STRING) RETURNS INTEGER
101
DECLARE ArrayIndex : INTEGER
102
DECLARE Found : BOOLEAN
103
104
ArrayIndex
1
105
Found
FALSE
106
107
WHILE ArrayIndex <= LastElement AND Found = FALSE
108
IF ThisArray[ArrayIndex, 1] > NewData
109
THEN
110
Found
TRUE
111
ELSE
112
ArrayIndex
ArrayIndex + 1
113
ENDIF
114
ENDWHILE
115
116
IF Found = TRUE
117
THEN
118
CALL Insert(ArrayIndex, NewData)
119
ELSE
120
ArrayIndex
0
121
ENDIF
122
123
RETURN ArrayIndex
124 ENDFUNCTION
(a) (i)
Examine the pseudocode and complete the following table.
Answer
The name of a global identifier
The name of a user-defined procedure
The scope of ArrayIndex
The number of dimensions of ThisArray
The scope of NewData
[5]
(ii)
Describe in detail, the purpose of lines 107 to 114 in the Update() function.
Do not use pseudocode in your answer.
…
…
…
…
…
… [4]
(b) Line 118 of the function Update() calls the subroutine Insert(). A designer decides to
convert Insert() from a procedure to a function. Insert() returns TRUE or FALSE.
A programmer must amend the function Update() as follows:
•
If Insert() returns FALSE then the function Update() returns -1
•
If Insert() returns TRUE then the function Update() returns the value as before.
Write program code to implement the amended Update() function.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…

81
9608/23/O/N/18 · Question 5Oct/Nov 2018Paper 2310 marks
Loading question…
Question text

5
The function ReadFileLine() returns a specific line from a text file.
The function takes two parameters:
Identifier
Data type
Description
The name of the text file
FileName
STRING
The line number that is required
FileLine
INTEGER
The following pseudocode gives an example of the use of the function.
ReadFileLine(FileName, FileLine)
FileData
The function ReadFileLine() will:
•
open the file, FileName
•
read each line from the file until line FileLine is found or the end of the file is reached
•
if the line exists, return the string from this line; otherwise return the string "****"
Write pseudocode for the ReadFileLine() function.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

82
9608/21/M/J/18 · Question 1May/June 2018Paper 2114 marks
Loading question…
Question text

(a) A program stores data about hospital patients.
1
Give a suitable identifier name for each of the data items.
Description of data item
Suitable identifier name
The temperature of the patient
The temperature of the room
The patient identification number
The name of the nurse taking the measurement
[4]
Program variables have values as follows:
(b) (i)
Variable
Value
MyGreeting
"Happy Birthday"
MyInitial
'C'
AgeInYears
27
Weight
60.5
Married
TRUE
Children
TRUE
Evaluate each expression in the following table.
If an expression is invalid, write ERROR.
For the built-in functions list, refer to the Appendix on page 15.
Expression
Evaluates to
"Mon" & MID(MyGreeting, 10, 2)
AgeInYears + ASC(MyInitial)
INT(MyInitial)
MOD(Weight * 2, 10)
Married AND (NOT Children)
[5]
Programming languages support different data types.
(ii)
Give an appropriate data type for each of these variables from part (b)(i).
Variable
Data type
MyGreeting
MyInitial
AgeInYears
Weight
Married
[5]

83
9608/21/M/J/18 · Question 2May/June 2018Paper 2114 marks
Loading question…
Question text

2
The following is a function design in pseudocode.
Line numbers are given for reference only.
01
FUNCTION StringClean(InString : STRING) RETURNS STRING
02
03
DECLARE
NextChar : CHAR
04
DECLARE
OutString : STRING
05
DECLARE
Counter : INTEGER
06
DECLARE
MyString : STRING
07
""
08
OutString
09
1 TO LENGTH(InString)
10
FOR Counter
11
MID(InString,Counter,1)
12
NextChar
LCASE(NextChar)
13
NextChar
14
15
IF (NextChar >= 'a') AND (NextChar <= 'z')
16
17
THEN
18
OutString & NextChar
19
OutString
20
21
ENDIF
22
23
ENDFOR
24
25
RETURN OutString
26
27
ENDFUNCTION
This pseudocode includes features that make it easier to read and understand.
(a) (i)
State four such features.
Feature 1 …
Feature 2 …
Feature 3 …
Feature 4 …
[4]
State one feature that could be added to make the pseudocode easier to understand.
(ii)
… [1]
(b) Study the function StringClean(). Identify the features of the function in the following
table.
Feature
Answer
A line number containing an example of an assignment statement
A line number containing the start of a repetition block
A line number containing the end of a repetition block
A line number containing the start of a selection statement
The number of parameters of the MID function
The Boolean operator used
The number of local variables
The number of function calls from within StringClean()
resulting from the call:
StringClean("Me")
NewString
The number of a line containing an unnecessary statement
[9]

Advertisement
84
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]

85
9608/21/M/J/18 · Question 4May/June 2018Paper 219 marks
Loading question…
Question text

(a) A structure chart is used in modular program design.
4
Iteration and selection are two features of an algorithm that may be shown on a structure chart.
Give three other features.
Feature 1 …
…
Feature 2 …
…
Feature 3 …
…
[3]
(b) Pseudocode for a function is shown.
FUNCTION ItemProcess (AddItem, InString : STRING) RETURNS BOOLEAN
DECLARE RetFlag : BOOLEAN
FALSE
RetFlag
IF AddItem = "Yes"
THEN
RetFlag
AddToList(InString)
ELSE
CALL RemoveFromList(InString)
ENDIF
RETURN RetFlag
ENDFUNCTION
Draw a structure chart on the next page to represent this pseudocode.
[6]

86
9608/21/M/J/18 · Question 5May/June 2018Paper 2112 marks
Loading question…
Question text

A golf club holds information about its members. When a member completes a round of golf, their
5
score is stored along with their membership number and the date of the round.
(a) Explain why the club stores these data in a file rather than an array.
…
… [1]
(b) Editing functions such as cut, copy and paste are features provided by an Integrated
Development Environment (IDE).
Give two additional features of an IDE that are helpful when coding a program.
Feature 1 …
…
Feature 2 …
…
[2]
(c) The information is stored in a text file, ScoreDetails.txt. The format of each line of the
text file is as follows:
<MembershipNumber><Date><Score>
•
MembershipNumber is a four-digit numeric string.
•
Date is a six-digit numeric string in the format DDMMYY
•
Score is a two-digit numeric string in the range "50" to "99".
A procedure, AddNewScores(), is being developed. This will allow the user to enter scores
for several members on a particular date.
The procedure, AddNewScores(), will perform the following actions:
1.
Prompt for the date of the scores.
2.
Input the date of the scores.
3.
Prompt for the membership number.
4.
Input the membership number.
5.
If the membership number is an empty string then end the procedure.
6.
Prompt for the score.
7.
Input the score.
8.
Validate the score.
9.
If the validation fails then repeat from step 6.
10.
Form a text string from the data and write this to the ScoreDetails.txt file.
11.
Repeat from step 3.
Write program code for the AddNewScores() procedure.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…

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

6
(a) The following pseudocode includes references to a 1D array.
DECLARE StudentGrade : ARRAY[1:5] OF CHAR
DECLARE n : INTEGER
DECLARE x : CHAR
3
n
StudentGrade[n]
x
(i)
Use the correct technical terms to explain the meaning of [1:5] in this pseudocode.
…
…
…
… [2]
(ii)
Use the correct technical term to complete the following statement.
Integer n is used as the … to StudentGrade.
[1]
(b) A 2D array, Picture, contains data representing a bitmap image. Each element of the array
represents one pixel of the image. The image is grey-scale encoded where the value of each
pixel ranges from 0 (representing black) to 255 (representing white) with intermediate values
representing different levels of grey.
The following is an example of an image and the corresponding data values for the Picture
array.
Bitmap image
Values
240 10
10
10
10
10
10 240
80
80 240 80
80 240 80
80
80
80 240 80
80 240 80
80
80
80 150 150 150 150 80
80
80
80 240 240 240 240 80
80
80
80 150 150 150 150 80
80
240 240 150 150 150 150 240 240
240 240 150 150 150 150 240 240
In pseudocode, the array is declared as follows:
DECLARE Picture : ARRAY[1:8, 1:8] OF INTEGER
A function, Lighten(), is required to lighten the image. Lightening an image may cause it to
‘burn out’. An image is said to be ‘burnt out’ if any pixel is set to the maximum value of 255.
The function Lighten() will:
1.
increase the value of each pixel by 10%
2.
return TRUE if the resultant image is ‘burnt out’.
Write pseudocode to implement the Lighten() function.
Assume that the array Picture is a global variable.
…
…
…
…
…
…
…
…
…
…
…
…

88
9608/21/M/J/18 · Question 7May/June 2018Paper 217 marks
Loading question…
Question text

A function, ProcessMarks(), is required to analyse test marks for a class of students.
7
•
There are 20 students in the class.
•
A mark is between 0 and 100.
•
The marks for the class are stored in an array, Mark, which has 20 elements.
•
The array is passed to the function as a parameter.
•
The function will output a message stating the average and highest marks. For example:
"The average mark is 34 and the highest mark is 76"
•
The function returns the subscript of the highest mark.
Write program code to implement the ProcessMarks() function.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [7]
Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
MID(ThisString : STRING, x : INTEGER, y : INTEGER

Advertisement
89
9608/22/M/J/18 · Question 1May/June 2018Paper 2214 marks
Loading question…
Question text

1
(a) A farm has a number of greenhouses used to grow vegetables. Each greenhouse has a
different identification number. A program is needed to store temperature information for each
greenhouse throughout the day.
Give a suitable identifier name for each of the data items.
Description of data item
Suitable identifier name
The temperature inside the greenhouse
The temperature outside the greenhouse
The greenhouse identification number
The time of the temperature measurements
[4]
(b) (i)
Program variables have values as follows:
Variable
Value
Mark
60
Subject
"Computer Science"
Grade
'B'
CourseCompleted
TRUE
AverageMark
49.5
Evaluate each expression in the following table.
If an expression is invalid, write ERROR.
For the built-in functions list, refer to the Appendix on page 16.
Expression
Evaluates to
"Fas" & MID(Subject, 6, 3)
LEFT(Mark, 1)
10 + ASC(Grade)
MOD(AverageMark * 2, 3)
CourseCompleted AND (Mark >= 60)
[5]
(ii)
Programming languages support different data types.
Give an appropriate data type for each of these variables from part (b)(i).
Variable
Data type
Mark
Subject
Grade
CourseCompleted
AverageMark
[5]

90
9608/22/M/J/18 · Question 2May/June 2018Paper 2218 marks
Loading question…
Question text

2
The following is a function design in pseudocode.
Line numbers are given for reference only.
01
FUNCTION CountDigits(InString : STRING) RETURNS CHAR
02
03
DECLARE nc : CHAR
04
DECLARE c : INTEGER
05
DECLARE n : INTEGER
06
07
0
08
c
LENGTH(InString)
// get number of characters for loop
09
n
10
11
WHILE n > 0
// repeat until no more characters left
12
LEFT(InString,1)
13
nc
n - 1
14
n
RIGHT(InString,n)
// remove first character
15
InString
16
17
IF (nc < '0') OR (nc > '9')
18
THEN
19
// do nothing
20
ELSE
c + 1
21
c
22
ENDIF
23
24
ENDWHILE
25
26
RETURN c
27
28
ENDFUNCTION
(a) (i)
This pseudocode includes features that make it easier to read and understand.
State two such features.
Feature 1 …
Feature 2 …
[2]
(ii)
State two additional features that should be used to make this pseudocode easier to
read and understand.
Feature 1 …
Feature 2 …
[2]
(b) Study the function CountDigits(). Identify the features of the function in the following
table.
Feature
Answer
A line number containing an example of an assignment statement
A line number containing the start of a ‘pre-condition’ loop
A line number containing the end of a ‘pre-condition’ loop
A line number containing the start of a selection statement
The number of parameters passed to the LEFT() function
The Boolean operator used
The number of times the function LEFT() is called from within
CountDigits() resulting from the call:
CountDigits("AB27C4")
Result
The number of local variables
[8]
(c) (i)
There is a mistake in the pseudocode that would produce a data type mismatch error if a
programmer were to write similar program code.
Describe this mistake and how it may be corrected.
…
…
…
… [2]
(ii)
Lines 17 to 22 of the pseudocode could be written in a simplified form.
Re-write the lines in a simplified form.
…
…
…
…
…
…
…
… [4]

Advertisement