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

70 questions · page 5 of 5 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
61
9608/22/O/N/17 · Question 3Oct/Nov 2017Paper 228 marks
Loading question…
Question text

3
A 1D array, Product, of type STRING is used to store information about a range of products in a
shop. There are 100 elements in the array. Each element stores one data item.
The format of each data item is as follows:
<ProductID><ProductName>
ProductID is a four-character string of numerals
•
ProductName is a variable-length string
•
The following pseudocode is an initial attempt at defining a procedure, ArraySort, which will
perform a bubble sort on Product. The array is to be sorted in ascending order of ProductID.
Line numbers have been added for identification purposes only.
01
PROCEDURE SortArray
02
DECLARE Temp : CHAR
03
DECLARE FirstID, SecondID : INTEGER
1 TO 100
04
FOR I
2 TO 99
05
FOR J
MODULUS(LEFT(Product[J], 6))
06
FirstID
MODULUS(LEFT(Product[J + 1], 6))
07
SecondID
08
IF FirstID > SecondID
09
THEN
Product[I]
10
Temp
Product[J + 1]
11
Product[I]
Temp
12
Product[J + 1]
13
ENDFOR
14
ENDIF
15
ENDFOR
16
ENDPROCEDURE
The pseudocode on page 8 contains a number of errors. Complete the following table to show:
the line number of the error
•
the error itself
•
the correction that is required.
•
Note:
If the same error occurs on more than one line, you should only refer to it ONCE.
•
Lack of optimisation should not be regarded as an error.
•
Line
Error
Correction
number
01
Wrong procedure name – “SortArray”
PROCEDURE ArraySort
[8]

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

63
9608/21/M/J/17 · Question 5May/June 2017Paper 2110 marks
Loading question…
Question text

5
A multi-user computer system records user login information in a text file, LoginFile.txt. Each
time a user successfully logs into the system, the following information is recorded:
Item
Information
Example data
1
A five character user ID
"JimAA"
2
A four character port ID
"3456"
3
A fourteen character time and date
"08:30Jun012015"
The data items are concatenated to form a single string. Each string is saved as a separate line in
the text file.
The example data in the preceding table would result in the following text line in the file:
"JimAA345608:30Jun012015"
The computer system can produce a list of the successful login attempts by a given user.
The file LoginFile.txt is searched for a given user ID and the corresponding data are copied
into a 2D array, LoginEvents.
LoginEvents has been declared in pseudocode as:
DECLARE LoginEvents[1 : 1000, 1 : 2] OF STRING
A procedure, SearchFile, is needed to search the file and copy selected data to the array.
The main steps of the procedure are as follows:
•
Input a user ID.
•
Search LoginFile.txt for entries with matching user ID.
•
For matching entries, copy items 2 and 3 above into the LoginEvents array.
You can assume that:
•
the system initialises all elements of LoginEvents to an empty string " ", before it calls
SearchFile
•
there will be no more than 1000 successful logins for a single user.
Write program code for the procedure SearchFile.
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
64
9608/22/M/J/17 · Question 5May/June 2017Paper 2212 marks
Loading question…
Question text

5
A multi-user computer system records user login data. Each time a user successfully logs into the
system, it records the following data.
Data item
Example data
User ID
"Jim27"
Port ID
"3456"
Time and date
"08:30 Jun 01 2015"
The data items are concatenated (joined) using a separator character to form a single string. Each
string represents one log entry.
(a) (i)
Suggest a suitable separator character. Give the reason for your choice.
Character …
Reason …
…
[2]
(ii)
The concatenated strings are stored in an array, LogArray, which may contain up to 20
log entries.
Use pseudocode to declare LogArray.
… [2]
(b) A procedure, LogEvents, is required to add the log entry data from LogArray to the existing
text file, LoginFile.txt.
Unused array elements are assigned the value "****". These can occur anywhere in the
array and should not be written to the file.
Write program code for the procedure LogEvents.
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
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

65
9608/21/O/N/16 · Question 4Oct/Nov 2016Paper 2122 marks
Loading question…
Question text

4
A company employs Ahmed as a programmer.
(a) At College, before joining the company, Ahmed used two items of software for programming:
•
a text editor
•
a compiler
Describe how he could have developed programs using these software tools.
Include in the description the terms ‘object code’ and ‘source code’.
…
…
…
…
…
…
… [3]
(b) Ahmed now uses an Integrated Development Environment (IDE) for programming.
(i)
State one feature an IDE provides to help with the identification of syntax errors.
…
… [1]
(ii)
State one feature an IDE provides to carry out white box testing.
…
… [1]
(c) The company maintains a file of product data. Ahmed is to write a program to add a new
product and search for a product based on the structure diagram shown:
Product
processing
Add
Search for
product
product
By
By
By
product code
description
price
The program records the following data for each product:
•
product code
•
product description
•
product retail price
The text file PRODUCTS stores each data item on a separate line, as shown below:
File PRODUCTS
0198
Plums(10kg)
11.50
0202
Onions(20kg)
10.00
0376
Mango chutney(1kg)
02.99
0014
Mango(10kg)
12.75
The program uses the variables shown in the identifier table.
Identifier
Data type
Description
Storing the code, description and
PRODUCTS
TEXT FILE
retail price for all current products
PCode
ARRAY[1:1000] OF STRING
Array storing the product codes
PDescription
ARRAY[1:1000] OF STRING
Array storing the product descriptions
PRetailPrice
ARRAY[1:1000] OF REAL
Array storing the product retail prices
i
INTEGER
Array index used by all three arrays
(i) The first operation of the program is to read all the product data held in file PRODUCTS
and write them into the three 1D arrays.
Complete the pseudocode below.
OPEN …
1
i
WHILE …
READFILE ("PRODUCTS", … )
READFILE ("PRODUCTS", … )
READFILE ("PRODUCTS", … )
…

66
9608/21/M/J/16 · Question 3May/June 2016Paper 2118 marks
Loading question…
Question text

3
A string encryption function is needed. The encryption uses a simple character-substitution method.
In this method, a new character substitutes for each character in the original string. This will create
the encrypted string.
The substitution uses the 7-bit ASCII value for each character. This value is used as an index for a
1D array, Lookup, which contains the substitute characters.
Lookup contains an entry for each of the ASCII characters. It may be assumed that the original
string and the substitute characters are all printable.
For example:
•
‘A’ has ASCII value 65
•
Array element with index 65 contains the character ‘Y’ (the substitute character)
•
Therefore, ‘Y’ substitutes for ‘A’
•
There is a different substitute character for every ASCII value
The programmer writes a function, EncryptString, to return the encrypted string. This function
will receive two parameters, the original, PlainText string and the 1D array.
(a) The first attempt at writing the pseudocode for this function is shown below.
Complete the pseudocode.
For the built-in functions list, refer to the Appendix on page 18.
FUNCTION EncryptString( … ) RETURNS STRING
DECLARE … , … : CHAR
DECLARE OldCharValue : …
DECLARE n : INTEGER
DECLARE OutString : STRING
… //initialise the return string
//loop through PlainText to produce OutString
FOR n
1 TO … //from first to last character
… //get next character
OldChar
… //find the ASCII value
OldCharValue
… //look up substitute character
NewChar
… //concatenate to OutString
ENDFOR
…
ENDFUNCTION
[10]
(b) Additional code needs to be written to allow the user to change some of the characters in the
array Lookup.
The user will input:
•
the array start position
•
the number of elements to change
•
each new substitute character
At the end, the program will finally output a confirmation message.
The first version of the algorithm is represented by the flowchart on the following page.
Write program code to declare the array Lookup.
(i)
Programming language …
…
…
… [2]
(ii)
Write program code to implement the flowchart design.
In addition to the Lookup array, assume that the following variables have been declared:
StartPos, NumToChange, n, NewChar
Programming language …
…
…
…
…
…
…
…

67
9608/21/M/J/16 · Question 5May/June 2016Paper 2113 marks
Loading question…
Question text

5
Toni has a large collection of jazz CDs that are stored in different places. She wants to record
where the CDs are stored. She decides to write a program to do this.
The program must store the data in a file, MyMusic.
(a) (i)
Why is a file needed?
…
… [1]
MyMusic is a text file with the data for each CD as one line of text.
(ii)
Data for a typical CD are:
Title:
Kind of Green
Artist:
Miles Coltrane
Location:
Rack1-5
The line will be formed by concatenating the three data items.
For the example above, the line stored will be:
Kind of GreenMiles ColtraneRack1-5
Describe a problem that might occur when organising the data in this way.
…
…
…
…
Describe a possible solution.
…
…
…
…
[4]
(b) Toni must input the data into the file for all of her CDs.
A procedure, InputData, is needed to do this.
Toni designs the procedure and chooses the following identifiers:
Identifier
Data type
CDTitle
STRING
CDArtist
STRING
CDLocation
STRING
The procedure repeatedly performs the following steps:
•
input a CD title (A rogue value of “##” is to be used to end the input)
•
input the artist
•
input the location
•
create the text line
•
write the text line to the file
When the rogue value is encountered the file is closed.
Write program code for the procedure InputData.
Visual Basic and Pascal: You should include declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
…
…
…
…
…
…
…
…

68
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
69
9608/23/M/J/16 · Question 3May/June 2016Paper 2317 marks
Loading question…
Question text

3
String encryption was implemented using a simple character-substitution method. A function,
Decrypt, is needed to reverse the encryption process and return the original character.
The encryption uses the 7-bit ASCII value for each character. This value is used as an index for a
1D array, Lookup, which contains the substitute characters.
Lookup contains an entry for each of the ASCII characters.
This function, Decrypt, will accept two parameters, a single character, CipherChar, and the 1D
array, Lookup.
The steps involved in Decrypt are follows:
•
Search for the character in the array
•
Note the index value where the character is found (the index value is the ASCII value of the
original character)
•
Use the index value to obtain the original character
(a) The first attempt at writing the pseudocode for this function is shown below.
Complete the pseudocode.
For the built-in functions list, refer to the Appendix on the last page.
FUNCTION Decrypt( … , … ) RETURNS CHAR
DECLARE Found
: …
DECLARE … : INTEGER
DECLARE OriginalChar
: CHAR
1
// …
Index
FALSE
Found
//search for CipherChar in Lookup:
WHILE …
//compare CipherChar with this array element:
IF …
THEN
… //Set the flag
ELSE
Index … //Move to next array element
ENDIF
ENDWHILE
//dropped out of loop so must have found CipherChar:
… //convert Index to original character
RETURN …
ENDFUNCTION
[11]
Question 3 continues on page 8.
(b) A program is to be written to output part of the Lookup array.
The design of the algorithm is shown below.
It may be assumed that the characters output from Lookup are all printable.
START
Input StartIndex and
NumberToOutput
Index
StartIndex
Loop
Produce OriginalChar from
Index (using built-in function)
Assign current array element to
Increment Index
CipherChar
Output message line
(see examples on the next page)
NO
End of
loop?
YES
STOP
For example, for the input of 65 and 3, the output will be:
Index 65: Character A has substitute character Y
Index 66: Character B has substitute character Q
Index 67: Character C has substitute character F
Write program code to implement the flowchart design.
In addition to the Lookup array, assume that the following variables have been declared:
StartIndex, NumberToOutput, Index
Programming language …
…
…
…
…
…

70
9608/23/M/J/16 · Question 5May/June 2016Paper 2316 marks
Loading question…
Question text

5
Claudia stores her large collection of music CDs in different places. Claudia wants to record where
she stores each CD. She decides to write a program to do this.
Data items for a typical CD are:
Title:
Kind of Green
Artist:
Miles Coltrane
Location: Rack3-23
The data is to be stored in a text file, MyMusic. Each line of the text file will be a string, formed by
concatenating the three data items.
Before concatenation, the title and artist will each be made into a fixed-length string of 40
characters. Space characters may need to be added to each data item.
The location is always 8 characters long.
(a) (i)
Explain the benefit of making the stored data into fixed-length strings.
…
…
…
…
State a drawback of this file design.
…
…
[3]
When Claudia buys a new CD, the CD data must be added to the existing file, MyMusic.
(ii)
She has written a procedure in pseudocode. This has the following file-handling
statements:
OPENFILE "MyMusic" FOR WRITE
WRITEFILE "MyMusic", OutputString
CLOSEFILE "MyMusic"
There is a problem with the logic of this pseudocode.
State the problem.
…
…
Identify the effect it will have if the final code is implemented in this way.
…
…
Give a possible solution.
…
…
[3]
(b) Claudia needs to output a list of all the CDs in a particular location.
She designs a procedure, OutputLocationList, to do this. She also chooses the following
identifiers:
Identifier
Data type
CDTitle
STRING
CDArtist
STRING
CDLocation
STRING
The procedure will:
•
prompt for the name of the location
•
input the location (such as “Rack3-23”)
•
search the file for all CDs at this location
•
output the title and artist of each CD found
•
output the total number of CDs found at that location (such as “17 CDs found”)
Write program code for the procedure OutputLocationList.
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 …
…
…

Advertisement