Computer Science Paper 2 by Aqib Khan
Computer Science Paper 2 by Aqib Khan
NAME
STUDENT GROUP:
ID
INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name college ID number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.
INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
CASE OF ThisValue
< 30 : Level "Low" ←
// less than 30
Check 1 ←
< 20 : Level "Very Low" ←
// less than 20
Check ThisValue / 2 ←
30 TO 40 : Level "Medium" ←
// between 30 an d 40
Check ThisValue / 3 ←
Data[ThisValue] Data[ThisValue] + 1 ←
> 40 : Level "High" ←
ENDCASE
(a) Complete the table by writing the answer for each row:
Answer
(b) The pseudocode contains four assignments to variable Level. One of these assignments
will never be performed.
. ..................................................................................................................................................
. ..................................................................................................................................................
. ..................................................................................................................................................
. ..................................................................................................................................................
. ..................................................................................................................................................
. ................................................................................................................................................ [3]
(c) The following line is added immediately before the ENDCASE statement:
. ..................................................................................................................................................
. ................................................................................................................................................ [1]
Page 1 of 16
(d) Give the appropriate data types for the variables ThisValue, Check and Level.
ThisValue . .............................................................................................................................
Check . ......................................................................................................................................
Level . .....................................................................................................................................
[3]
Outline, using stepwise refinement, the five steps for this algorithm which could be used to
produce pseudocode.
Step 1 . ......................................................................................................................................
. ..................................................................................................................................................
Step 2 . ......................................................................................................................................
. ..................................................................................................................................................
Step 3 . ......................................................................................................................................
. ..................................................................................................................................................
Step 4 . ......................................................................................................................................
. ..................................................................................................................................................
Step 5 . ......................................................................................................................................
. ..................................................................................................................................................
[5]
Identify two other programming constructs that will be required when the algorithm is
converted into pseudocode.
Construct 1 . ..............................................................................................................................
. ..................................................................................................................................................
Construct 2 . ..............................................................................................................................
. ..................................................................................................................................................
[2]
Page 2 of 16
3 A company has several departments. Each department stores the name, email address and the
status of each employee in that department in its own text file. All text files have the same format.
Employee details are stored as three separate data strings on three consecutive lines of the file.
An example of the first six lines of one of the files is as follows:
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Page 3 of 16
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
. ................................................................................................................................................ [7]
Page 4 of 16
(b) An alternative format could be used for storing the data.
...........................................................................................................................................
......................................................................................................................................... [1]
(ii) State one advantage and one disadvantage of the alternative format.
Advantage .........................................................................................................................
...........................................................................................................................................
Disadvantage ....................................................................................................................
...........................................................................................................................................
[2]
Page 5 of 16
4 A program allows a user to save passwords used to login to websites. A stored password is
inserted automatically when the user logs into the corresponding website.
A student is developing a program to generate a password. The password will be of a fixed format,
consisting of three groups of four alphanumeric characters. The groups are separated by the
hyphen character '-'.
A global 2D array Secret of type STRING stores the passwords together with the website domain
name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns.
Unused elements contain the empty string (""). These may occur anywhere in the array.
Secret[27, 1] "www.thiswebsite.com"
Secret[27, 2] ""
Secret[28, 1] "www.thatwebsite.com"
Secret[28, 2] ""
Note:
• For security, passwords are stored in an encrypted form, shown as "" in the
example.
• The passwords cannot be used without being decrypted.
• Assume that the encrypted form of a password will not be an empty string.
Module Description
RandomChar() • Generates a single random character from within one of the
following ranges:
○ 'a' to 'z'
○ 'A' to 'Z'
○ '0' to '9'
• Returns the character
Encrypt() • Takes a password as a parameter of type string
• Returns the encrypted form of the password as a string
Decrypt() • Takes an encrypted password as a parameter of type string
• Returns the decrypted form of the password as a string
'A' to 'Z' 65 to 90
'0' to '9' 48 to 57
Page 6 of 16
(a) Write pseudocode for module RandomChar().
You may wish to refer to the insert for a description of the CHR() function. Other functions
may also be required.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
. ................................................................................................................................................ [6]
Page 7 of 16
(b) A new module is defined as follows:
Module Description
FindPassword() • Takes a website domain name as a parameter of type string
• Searches for the website domain name in the array Secret
• If the website domain name is found, the decrypted password
is returned
• If the website domain name is not found, a warning message
is output, and an empty string is returned
Assume that modules Encrypt() and Decrypt() have already been written.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
................................................................................................................................................... [7]
Page 8 of 16
(c) The modules Encrypt() and Decrypt() are called from several places in the main
program.
Identify a method that could have been used to test the main program before these modules
were completed. Describe how this would work.
Method ......................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.................................................................................................................................................. [2]
(d) A validation function is written to check that the passwords generated are valid.
Note: lower-case and upper-case characters are not the same. For example, 'a' is not the
same as 'A'.
Give two password strings that could be used to test different areas of the validation rules.
Password 1 ...............................................................................................................................
Password 2 ...............................................................................................................................
[2]
(e) The RandomChar() module is to be modified so that alphabetic characters are generated
twice as often as numeric characters.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.................................................................................................................................................. [2]
Page 9 of 16
5 (a) The diagram below represents a queue Abstract Data Type (ADT) that can hold a maximum
of eight items.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
......................................................................................................................................... [2]
(ii) Describe how the next item in the given queue is removed and stored in the variable
AnimalName.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
......................................................................................................................................... [2]
(iii) Describe the state of the queue when the front of queue and the end of queue pointers
have the same value.
...........................................................................................................................................
......................................................................................................................................... [1]
Page 10 of 16
(b) Some operations are carried out on the original queue given in part (a).
0 Frog
1 Cat
2 Fish
3 Elk
4
5
6
7
Complete the diagram to show the state of the queue after the following operations:
Add “Wasp”, “Bee” and “Mouse”, and then remove two data items.
[2]
(ii) The state of the queue after other operations are carried out is shown:
0 Frog
1 Cat
2 Fish
3 Elk Front of queue pointer
4 Wasp
5 Bee
6 Mouse End of queue pointer
7 Ant
Complete the following diagram to show the state of the queue after the following
operations:
0
1
2
3
4
5
6
7
[2]
Page 11 of 16
6 The following structured English describes an algorithm used to count the number of odd and
even digits in an input sequence.
Page 12 of 16
[7]
Page 13 of 16
7 The following pseudocode is an attempt to check whether two equal-length strings consist of
identical characters.
Refer to the Insert Document for the list of built-in functions and operators.
Len1 LENGTH(String1)
RetFlag TRUE
RETURN RetFlag
ENDFUNCTION
Page 14 of 16
(i) Complete the trace table below by performing a dry run of the function when it is called
as follows:
[5]
. .................................................................................................................................................... [1]
Page 15 of 16
(iii) There is an error in the algorithm, which means that under certain circumstances, the
function will return an incorrect value.
Describe the problem. Give two test strings that would demonstrate it.
Problem .............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
(iv) Describe the modification that needs to be made to the algorithm to correct the error.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
. .................................................................................................................................................... [1]
(v) State the name given to the type of testing that makes use of a trace table.
. .................................................................................................................................................... [1]
(vi) State two features found in a typical Integrated Development Environment (IDE) that
may be used for debugging a program.
1 ........................................................................................................................................
2 ........................................................................................................................................
[2]
Page 16 of 16