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

Computer Science Paper 2 by Aqib Khan

BEst p2 guide tried and tested

Uploaded by

raffey.mehdi
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)
291 views18 pages

Computer Science Paper 2 by Aqib Khan

BEst p2 guide tried and tested

Uploaded by

raffey.mehdi
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

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

This document has 16 pages.


[Turn over

Guess Paper of Sir Aqib Khan


03145030717
Guess Paper of Sir Aqib Khan
03145030717
Refer to the insert for the list of pseudocode functions and operators.

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

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

The value assigned to Level when ThisValue is 40

The value assigned to Check when ThisValue is 36

The value assigned to Level when ThisValue is 18

The number of elements in array Data that may be incremented


[4]

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

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

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

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

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

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

. ................................................................................................................................................ [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
(d) Give the appropriate data types for the variables ThisValue, Check and Level.

ThisValue . .............................................................................................................................

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

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

Step 2 . ......................................................................................................................................

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

Step 3 . ......................................................................................................................................

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

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
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:

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 existing file name
○ a new file name
○ a search status value

• create a new text file using the new file name


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Page 4 of 16
(b) An alternative format could be used for storing the data.

A text file will still be used.

(i) Describe the alternative format.

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

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

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

The programmer has started to define program modules as follows:

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

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

Write pseudocode for module FindPassword().

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.

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
• not include any duplicated characters, except for the hyphen characters.

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.

Describe how this might be achieved.

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

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

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

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

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

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

The operation of this queue may be summarised as follows:

• 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

(i) Describe how “Octopus” is added to the given queue.

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

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

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

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

(i) The current state of the queue is:

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:

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

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.

1. Initialise variables OddCount and EvenCount to zero.


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.

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.

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
ENDIF
ENDFOR
String2 New // replace String2 with New
ENDFOR

IF LENGTH(String2) <> 0 // anything left in String2 ?


THEN
RetFlag FALSE
ENDIF

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:

Result Compare("SUB", "BUS")

The first row has been completed for you.

String1 String2 Len1 RetFlag x Len2 NextChar New y


"SUB" "BUS" 3 TRUE 1

[5]

(ii) State the value returned.

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

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

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

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

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

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

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


[2]

(iv) Describe the modification that needs to be made to the algorithm to correct the error.

Do not use pseudocode or program code in your answer.

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

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

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

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

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

You might also like