0% found this document useful (0 votes)
80 views18 pages

Computer Science Paper 2 by Aqib Khan

This document is a mock examination paper for a Computer Science course, consisting of various pseudocode-related questions and programming concepts. It includes instructions for answering, the total marks, and a series of tasks related to algorithms, data types, and file handling. The examination is designed to assess students' understanding of programming constructs and their ability to write pseudocode.

Uploaded by

danishwaheed2805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views18 pages

Computer Science Paper 2 by Aqib Khan

This document is a mock examination paper for a Computer Science course, consisting of various pseudocode-related questions and programming concepts. It includes instructions for answering, the total marks, and a series of tasks related to algorithms, data types, and file handling. The examination is designed to assess students' understanding of programming constructs and their ability to write pseudocode.

Uploaded by

danishwaheed2805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

1

CS BY AAQIB KHAN
STUDENT
NAME

STUDENT GROUP:
ID

COMPUTER SCIENCE 9618/22


Paper 2 Mock Examination 2024
2 Hours

You must answer on the question paper.

You will need: Insert (enclosed)

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.

This document has 16 pages.


[Turn over
CS BY AAQIB KHAN 2

011010101101010110101
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110

AAQIB KHAN
3

Refer to the insert for the list of pseudocode functions and operators.

1 The following pseudocode represents part of the algorithm for a program:

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

The value assigned to Level when ThisValue is 40

The value assigned to Check when ThisValue is 36


011010101101010110101
The value assigned to Level
1011010110 when ThisValue is 18
1011010110
10110101101011010110
The number of1011010110
elements in1011010110
array Data that may be incremented
10110101101011010110 [4]
10110101101011010110
10110101101011010110
(b) The pseudocode contains four assignments to variable Level. One of these assignments
will never be performed.

Identify this assignment and explain why this is the case.

AAQIB KHAN
. ..................................................................................................................................................

. ..................................................................................................................................................

. ..................................................................................................................................................

. ..................................................................................................................................................

. ..................................................................................................................................................

. ............................................................................................................................................ [3]

(c) The following line is added immediately before the ENDCASE statement:

OTHERWISE : Level ← "Undefined"


State why this assignment is never performed.

. ..................................................................................................................................................

. ............................................................................................................................................ [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]

2 (a) An algorithm is expressed as follows:

• input 100 numbers, one at a time •


keep a total of all numbers input that have a value between 30 and 70 inclusive and
output this total after the last number has been input.

Outline, using stepwise refinement, the five steps for this algorithm which could be used to
produce pseudocode.

Do not use pseudocode statements in your answer.

Step 1 . ......................................................................................................................................
011010101101010110101
10110101101011010110
. ..................................................................................................................................................
10110101101011010110
10110101101011010110
Step 2 . ......................................................................................................................................
10110101101011010110
10110101101011010110
. ..................................................................................................................................................
10110101101011010110
Step 3 . ......................................................................................................................................

. ..................................................................................................................................................

AAQIB KHAN
Step 4 . ......................................................................................................................................

. ..................................................................................................................................................

Step 5 . ......................................................................................................................................

. ..................................................................................................................................................
[5]

(b) Sequence is one programming construct.

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:

File line Comment


1 First employee name

2 First email address

3 First employee status

4 Second employee name

5 Second email address

6 Second employee status

A procedure MakeNewFile() will:

• take three parameters as strings:


○ an 0110101 01101010110101
existing file name
1011010110 1011010110
○ a1011010110
new file name
1011010110
○ a1011010110
search status value
1011010110
10110101101011010110
• 1011010110
create a new 1011010110
text file using the new file name
10110101101011010110
• write all employee details to the new file where the employee status is not equal to the search
status value
• count the number of sets of employee details that were in the original file
• count the number of sets of employee details that were written to the new file
• produce a summary output.

AAQIB KHAN
An example summary output is as follows:

File Marketing contained 54 employee details


52 employee sets of details were written to file NewMarketingList

(a) Write pseudocode for the procedure MakeNewFile().

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

Page 3 of 16
6

...................................................................................................................................................

...................................................................................................................................................
CS BY AAQIB KHAN

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
011010101101010110101
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
...................................................................................................................................................

...................................................................................................................................................

AAQIB KHAN
...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [7]

Page 4 of 16
7

(b) An alternative format could be used for storing the data.

A text file will still be used.

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

hyphen character '-'.

An example of a password is: "FxAf-3haV-Tq49"

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.

An example of a part of the array is:

Array element Value

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.

The programmer has started to define program modules as follows:

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

For reference, relevant ASCII values are as follows:

Character range ASCII range

'a' to 'z' 97 to 122

'A' to 'Z' 65 to 90

'0' to '9' 48 to 57

Page 6 of 16
9

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

CS BY AAQIB KHAN
...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................
011010101101010110101
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
10110101101011010110
...................................................................................................................................................
10110101101011010110
...................................................................................................................................................

...................................................................................................................................................

AAQIB KHAN
...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [6]

Page 7 of 16
10

(b) A new module is defined as follows:

Module Description
FindPassword() • Takes a website domain name as a parameter of type string
CS BY AAQIB KHAN

• 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

Write pseudocode for module FindPassword().

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.

To be valid, each password must:


• be 14 characters long
• be organised as three groups of four case-sensitive alphanumeric characters. The
groups are separated by hyphen characters
• 0110101
not include 01101010110101
any duplicated characters, except for the hyphen characters.
10110101101011010110
1011010110
Note: lower-case and 1011010110
upper-case characters are not the same. For example, 'a' is not the
10110101101011010110
same as 'A'.
10110101101011010110
10110101101011010110
Give two 1011010110 1011010110
password strings that could be used to test different areas of the validation rules.

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.

Describe how this might be achieved.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

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

The operation of this queue may be summarised as follows:


CS BY AAQIB KHAN

• The front of queue pointer points to the next item to be removed.


• The end of queue pointer points to the last item added.
• The queue is circular so that empty storage elements can be reused.

0 Frog Front of queue pointer


1 Cat
2 Fish
3 Elk End of queue pointer
4
5
6
7
011010101101010110101
(i) 1011010110
Describe 1011010110
how “Octopus” is added to the given queue.
10110101101011010110
10110101101011010110
...........................................................................................................................................
10110101101011010110
10110101101011010110
...........................................................................................................................................
10110101101011010110

...........................................................................................................................................

..................................................................................................................................... [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).

(i) The current state of the queue is:

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:

Remove one item, and then add “Dolphin” and “Shark”.

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.

1. Initialise variables OddCount and EvenCount to zero.


CS BY AAQIB KHAN

2. Prompt and input an integer.


3. If the integer is not in the range 0 to 9 then go to step 7.
4. If the integer is an even number then add 1 to EvenCount.
5. Otherwise add 1 to OddCount.
6. Repeat from step 2.
7. Output "Same" if there are the same number of odd and even integers.
8. Output "Odd" if there are more odd than even integers.
9. Output "Even" if there are more even than odd integers.

Draw a flowchart on the following page to represent the algorithm.

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

FUNCTION Compare(String1, String2 : STRING) RETURNS BOOLEAN


DECLARE x, y, Len1, Len2 : INTEGER
DECLARE RetFlag : BOOLEAN
DECLARE NextChar : CHAR
DECLARE New : STRING

Len1 LENGTH(String1)
RetFlag TRUE

FOR x 1 TO Len1 // for each char in String1


Len2 LENGTH(String2)
NextChar MID(String1, x, 1) // get NextChar from String1
New ""
FOR y 1 TO Len2 // for each char in String2
IF NextChar <> MID(String2, y, 1) // no match
THEN
New New & MID(String2, y, 1) // save this char from String2
ENDIF011010101101010110101
ENDFOR 10110101101011010110
String2 1011010110
New 1011010110 // replace String2 with New
ENDFOR 10110101101011010110
10110101101011010110
10110101101011010110
1011010110
IF LENGTH(String2) <>1011010110
0 // anything left in String2 ?
THEN
RetFlag FALSE
ENDIF

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:

Result Compare("SUB", "BUS")

CS BY AAQIB KHAN
The first row has been completed for you.

String1 String2 Len1 RetFlag x Len2 NextChar New y


"SUB" "BUS" 3 TRUE 1

011010101101010110101
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110
10110101101011010110

AAQIB KHAN [5]

(ii) State the value returned.

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

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

Test String1 .......................................................................................................................

Test String2 .......................................................................................................................


[2]

(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

You might also like