Computer Science Paper 2 by Aqib Khan
Computer Science Paper 2 by Aqib Khan
CS BY AAQIB KHAN
STUDENT
NAME
STUDENT GROUP:
ID
INSTRUCTIONS 011010101101010110101
● 10110101101011010110
Answer all questions.
●
10110101101011010110
Use a black or dark blue pen.
10110101101011010110
● Write your name college ID number
1011010110 in the boxes at the top of the page.
1011010110
● Write your answer to each question
10110101101011010110 in the space provided.
● 1011010110 1011010110
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.
AAQIB KHAN
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.
011010101101010110101
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
AAQIB KHAN
3
Refer to the insert for the list of pseudocode functions and operators.
CS BY AAQIB KHAN
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 and 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
AAQIB KHAN
. ..................................................................................................................................................
. ..................................................................................................................................................
. ..................................................................................................................................................
. ..................................................................................................................................................
. ..................................................................................................................................................
. ............................................................................................................................................ [3]
(c) The following line is added immediately before the ENDCASE statement:
. ..................................................................................................................................................
. ............................................................................................................................................ [1]
Page 1 of 16
4
(d) Give the appropriate data types for the variables ThisValue, Check and Level.
ThisValue . .............................................................................................................................
CS BY AAQIB KHAN
Check . ......................................................................................................................................
Level . .....................................................................................................................................
[3]
Outline, using stepwise refinement, the five steps for this algorithm which could be used to
produce pseudocode.
Step 1 . ......................................................................................................................................
011010101101010110101
10110101101011010110
. ..................................................................................................................................................
10110101101011010110
10110101101011010110
Step 2 . ......................................................................................................................................
10110101101011010110
10110101101011010110
. ..................................................................................................................................................
10110101101011010110
Step 3 . ......................................................................................................................................
. ..................................................................................................................................................
AAQIB KHAN
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
5
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.
CS BY AAQIB KHAN
An example of the first six lines of one of the files is as follows:
AAQIB KHAN
An example summary output is as follows:
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Page 3 of 16
6
...................................................................................................................................................
...................................................................................................................................................
CS BY AAQIB KHAN
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
011010101101010110101
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
...................................................................................................................................................
...................................................................................................................................................
AAQIB KHAN
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
Page 4 of 16
7
CS BY AAQIB KHAN
(i) Describe the alternative format.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) State one advantage and one disadvantage of the alternative format.
Advantage .........................................................................................................................
...........................................................................................................................................
Disadvantage ....................................................................................................................
...........................................................................................................................................
[2]
011010101101010110101
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
AAQIB KHAN
Page 5 of 16
8
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
CS BY AAQIB KHAN
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,
0110101 2]
01101010110101 ""
10110101101011010110
10110101101011010110
Note: 10110101101011010110
• For security, passwords
1011010110 are stored in an encrypted form, shown as "" in the
1011010110
example. 10110101101011010110
• The passwords cannot1011010110
1011010110 be used without being decrypted.
• Assume that the encrypted form of a password will not be an empty string.
Module Description
AAQIB KHAN
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
9
You may wish to refer to the insert for a description of the CHR() function. Other functions
may also be required.
CS BY AAQIB KHAN
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
011010101101010110101
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
...................................................................................................................................................
...................................................................................................................................................
AAQIB KHAN
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Page 7 of 16
10
Module Description
FindPassword() • Takes a website domain name as a parameter of type string
CS BY AAQIB KHAN
Assume that modules Encrypt() and Decrypt() have already been written.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
011010101101010110101
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
...................................................................................................................................................
...................................................................................................................................................
AAQIB KHAN
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
Page 8 of 16
11
(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
CS BY AAQIB KHAN
were completed. Describe how this would work.
Method ......................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(d) A validation function is written to check that the passwords generated are valid.
Password 1 ...............................................................................................................................
Password 2 ...............................................................................................................................
[2]
AAQIB KHAN
(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
12
5 (a) The diagram below represents a queue Abstract Data Type (ADT) that can hold a maximum
of eight items.
...........................................................................................................................................
..................................................................................................................................... [2]
AAQIB KHAN
(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
13
(b) Some operations are carried out on the original queue given in part (a).
CS BY AAQIB KHAN
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) 0110101
The state 01101010110101
of the queue after other operations are carried out is shown:
10110101101011010110
10110101101011010110
0 1011010110
1011010110 Frog
10110101101011010110
1 1011010110
1011010110 Cat
1011010110
2 1011010110
Fish
3 Elk Front of queue pointer
4 Wasp
5 Bee
AAQIB KHAN 6
7
Mouse
Ant
End of queue pointer
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
14
6 The following structured English describes an algorithm used to count the number of odd and
even digits in an input sequence.
011010101101010110101
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
AAQIB KHAN
Page 12 of 16
15
CS BY AAQIB KHAN
011010101101010110101
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
AAQIB KHAN
[7]
Page 13 of 16
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.
CS BY AAQIB KHAN
Len1 LENGTH(String1)
RetFlag TRUE
RETURN RetFlag
ENDFUNCTION
AAQIB KHAN
Page 14 of 16
17
(i) Complete the trace table below by performing a dry run of the function when it is called
as follows:
CS BY AAQIB KHAN
The first row has been completed for you.
011010101101010110101
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
..................................................................................................................................... [1]
Page 15 of 16
18
(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.
CS BY AAQIB KHAN
Problem .............................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
(iv) Describe the modification that needs to be made to the algorithm to correct the error.
0110101
Do not 01101010110101
use pseudocode or program code in your answer.
10110101101011010110
10110101101011010110
...........................................................................................................................................
10110101101011010110
10110101101011010110
...........................................................................................................................................
10110101101011010110
10110101101011010110
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [1]
(v)
AAQIB KHAN
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