Data types, arrays and files – A Level Computer Science (old syllabus, to 2021) (9608)

70 questions · page 4 of 5 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
46
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

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

48
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.

Advertisement
49
9608/22/M/J/18 · Question 5May/June 2018Paper 2218 marks
Loading question…
Question text

5
A golf club holds information about its members. When a member completes a round of golf, their
score is stored along with their membership number and the date of the round.
A program is to be written to store and process the score information. The information to be stored
is formed into a string as follows:
<MembershipNumber><Date><Score>
(a) The program designer considers storing the strings in either a 1D array, RoundScore or
as a separate variable for each round, for example, RoundScore01, RoundScore02,
RoundScore03 and so on.
Describe two advantages of storing the strings in a 1D array rather than as separate variables.
Advantage 1 …
…
Advantage 2 …
…
[2]
(b) A procedure, AddNewScores() is being developed. The procedure will be coded using
an Integrated Development Environment (IDE).
Name two features provided by an IDE that assist in the initial detection of errors in the
procedure.
Feature 1 …
…
Feature 2 …
…
[2]
(c) The program needs a function, GetNumber(), to return a valid membership number. A valid
membership number is a four-digit numeric string between “1111” and “9999”.
The structured English representing the algorithm for this function is as follows:
1.
Prompt and input a membership number.
2.
Validate the membership number.
3.
Repeat from step 1 if the membership number is invalid.
4.
Return the valid membership number as a string.
An example of the function call in pseudocode is:
GetNumber()
MembershipNumber
Write program code for the GetNumber() 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
…
…
…
…
…
…
…
…

50
9608/22/M/J/18 · Question 6May/June 2018Paper 2210 marks
Loading question…
Question text

6
(a) Individual elements in a 1D array are referenced using an integer value that is used as the
subscript to the array.
Give the technical terms for the minimum and maximum values the subscript may take.
Minimum value …
Maximum value …
[2]
(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.
A graphics program needs a procedure, Flip(), to flip (reflect) the image. An example of an
image before and after the function is:
Before flip
After flip
The values contained in the 2D array before the flip are as follows:
Data values
80
80
255
80
80
255
80
80
80
80
255
80
80
255
80
80
255
80
120
120
120
120
255
80
255
80
255
255
255
255
80
80
255
80
120
120
120
120
80
80
In pseudocode, the array is declared as follows:
DECLARE Picture : ARRAY[1:5, 1:8] OF INTEGER
Write pseudocode to implement the Flip() procedure.
Assume that Picture is a global variable.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

51
9608/23/M/J/18 · Question 1May/June 2018Paper 2314 marks
Loading question…
Question text

1
(a) A program controls the heating system of an energy-efficient house.
Give a suitable identifier name for each of the data items.
Description of data item
Suitable identifier name
The temperature inside the house
The temperature outside the house
The wind speed
Whether it was raining or not
[4]
(b) (i)
Program variables have values as follows:
Variable
Value
Quality
'D'
DayNumber
20
MyName
"Stephen"
QualityConfirmed
TRUE
Factor
6.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 15.
Expression
Evaluates to
MID(MyName, 4, 4) & "ol"
QualityConfirmed AND (Factor >= 6.5)
20 + ASC(Quality)
QualityConfirmed + 3
MOD(Factor * 2, 9)
[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
QualityConfirmed
DayNumber
Factor
Quality
MyName
[5]

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

53
9608/23/M/J/18 · Question 5May/June 2018Paper 2314 marks
Loading question…
Question text

5
A golf club holds information about its members. When a member completes a round of golf, their
score is stored along with their membership number and the date of the round.
A program is to be written to store and process the score information.
The information to be stored is as follows:
•
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”.
This information is stored in a single string in the format:
<MembershipNumber><Date><Score>
(a) (i)
The program designer considers storing the strings in an array.
State how many dimensions the array would require.
… [1]
(ii)
The designer has decided to store the strings in a file.
Give a reason for this choice.
…
… [1]
(b) The program will be developed using an Integrated Development Environment (IDE). One
feature provided by an IDE is known as prettyprint.
Name two presentation features provided by prettyprint.
Feature 1 …
…
Feature 2 …
…
[2]
(c) The strings are stored in a text file, ScoreDetails.txt.
The program needs a function, GetAverageScore().
The structured English representing the algorithm for this function is as follows:
1
Receive a membership number as its argument.
2
Search the ScoreDetails.txt file for all scores for that member.
3
Calculate the average score.
4
Return the average score.
You can assume that there will be at least one score relating to each member.
Write program code for the GetAverageScore() 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
…
…
…
…
…
…
…
…
…

Advertisement
54
9608/23/M/J/18 · Question 6May/June 2018Paper 2310 marks
Loading question…
Question text

6
(a) Individual elements in a 1D array are referenced using an integer variable.
For example, using the variable n, an individual element would be referenced in pseudocode
as:
StudentGrade[n]
Give the correct technical term for the variable n.
… [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, Clip(), is required that will:
•
take an integer parameter, MaxVal, to represent the maximum allowed value for each
pixel
•
limit each pixel value to the maximum allowed value
•
return TRUE if any of the pixel values have been changed, otherwise return FALSE
An example use of the function is:
Clip(234)
IsClipped
This will limit the maximum pixel value within the array to 234. Pixels with a value not greater
than 234 will remain unchanged.
Write pseudocode to implement the Clip() function.
Assume that Picture is a global variable.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

55
9608/21/O/N/17 · Question 1Oct/Nov 2017Paper 2117 marks
Loading question…
Question text

1
(a) (i)
Procedural high-level languages usually support different data types.
Give an appropriate data type for each data value in the following table.
Data value
Data type
27
"27"
"27.3"
TRUE
27/3/2015
27.3
[6]
(ii)
State an appropriate data structure to store the individual test scores for a class of
students.
… [1]
(iii)
Describe how characters are represented using the ASCII character set.
…
…
…
… [2]
(b) Functions and procedures are subroutines.
Explain why you should use subroutines when designing a program solution.
…
…
…
… [2]
(c) The following pseudocode is an example of nested IF statements.
IF MyVar = 1
THEN
CALL Proc1()
ELSE
IF MyVar = 2
THEN
CALL Proc2()
ELSE
IF MyVar = 3
THEN
CALL Proc3()
ELSE
OUTPUT "Error"
ENDIF
ENDIF
ENDIF
Use pseudocode to write a CASE statement with the same functionality.
…
…
…
…
…
…
…
… [4]
(d) Program coding is a transferable skill.
You are given program code written in a high-level language that you have not studied.
State two different features of the code that you should be able to recognise.
1 …
…
2 …
…

56
9608/21/O/N/17 · Question 3Oct/Nov 2017Paper 2123 marks
Loading question…
Question text

3
(a) A multi-user computer system stores information about users. It uses a 1D array,
UserNameArray, of type STRING. There are 100 elements in the array.
The format of the string in each element of the array is as follows:
<UserID><UserName>
•
UserID is a six-character string of numerals.
•
UserName is a variable-length string.
Write pseudocode for a procedure, BubbleSort, to perform an efficient bubble sort on
UserNameArray. The array is to be sorted in ascending order of UserID.
You should assume that UserNameArray has been declared as a global variable.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

57
9608/21/O/N/17 · Question 4Oct/Nov 2017Paper 215 marks
Loading question…
Question text

4
Numeric formatting converts a numeric value to a string in order to present it in a specific way.
In a generic high-level language, formatting is implemented using a mask system. In this system,
each character of the mask corresponds to one character of the formatted string.
Mask characters have the following meaning:
Mask character
Meaning
Character must be a digit or a space
#
Character must be a digit
0
Any other mask characters are taken as literal values and are included in the formatted string.
(a) Using the mask "###00.00", complete the following table. Use □ to represent a space. The
first value has been done for you.
Value
Formatted string
1327.5
"□1327.50"
1234
7.456
[2]
(b) For each row in the following table, define the mask required to produce the formatted output
from the given value. □ represents a space.
Value
Required output
Mask
1234.00
"1,234.00"
3445.66
"£3,445.66"
10345.56
"$□ □10,345"
[3]

58
9608/21/O/N/17 · Question 5Oct/Nov 2017Paper 2114 marks
Loading question…
Question text

5
A sports club maintains a record of the email address of each of its members. The details are
stored in a text file, EmailDetails.txt. The format of each line of the text file is as follows:
<MembershipNumber><EmailAddress>
•
MembershipNumber is a four-character string of numerals.
•
EmailAddress is a variable-length string.
Membership of the club has increased and a four-character membership number is no longer
adequate.
A procedure, MakeNewFile, is required to perform the following actions:
1.
Create a new file, NewEmailDetails.txt
2.
Read a line from file EmailDetails.txt
3.
Extend MembershipNumber by adding two leading zero digits (for example, "1234"
becomes "001234")
4.
Write the new line to file NewEmailDetails.txt
5.
Repeat steps 2 to 4 for all lines in the original file.
(a) Write pseudocode for the procedure MakeNewFile.
For the built-in functions list, refer to the Appendix on page 14.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]
(b) A function, IsEmailValid, is to be written to test for a valid email address format.
An email address has a valid format if it obeys the following three rules:
1.
It contains a single ‘@’ symbol.
2.
The ‘@’ symbol must be preceded by at least one character.
3.
The ‘@’ symbol must be followed by at least three characters.
Choose three different invalid strings to test distinct aspects of the rules.
Explain your choice in each case.
1 …
Explanation …

Advertisement
59
9608/22/O/N/17 · Question 1Oct/Nov 2017Paper 2223 marks
Loading question…
Question text

1
(a) (i)
Procedural high-level languages usually support different data types.
Give an appropriate data type for each data value in the following table:
Data value
Data type
FALSE
03/03/2013
35
"INTEGER"
3.5
"35"
[6]
(ii)
The following is a declaration in a high-level language:
DEFINE MyGrade[1 to 100]
State the data structure of variable MyGrade.
… [1]
(iii)
An experienced programmer is presented with program code in an unfamiliar high-level
language.
State two features of the code that the programmer should be able to recognise.
1 …
…
2 …
…
[2]
(b) (i)
In the ASCII character set ‘A’ is represented by the value 65. The values representing the
other characters of the alphabet follow in sequence, so ‘B’ is represented by 66, ‘C’ by 67
and so on.
The following table represents consecutive memory locations. Each memory location
stores one byte.
Complete the table to show how the string "CAGE" may be stored in memory using the
ASCII set.
Address
Data
100
101
102
103
104
105
[2]
(ii)
In a high-level language, a LENGTH function is used to return the number of characters in
a string.
Explain what is stored in addition to the string characters to allow this function to
determine this number.
…
…
…
… [2]
(c) Functions and procedures are subroutines.
Explain why parameters are used with subroutines.
…
…
…
…
…
… [3]
(d) The following pseudocode is an example of a CASE structure.
CASE OF MyMark
"Distinction"
75 to 100: MyGrade
"Pass"
35 to 74: MyGrade
"Fail"
0 to 34: MyGrade
OTHERWISE: OUTPUT "Invalid value entered"
ENDCASE
(i)
Describe what will happen if the pseudocode is tested when MyMark has the following
values:
27 …
…

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

Advertisement