0% found this document useful (0 votes)
15 views9 pages

Computer Science Paper 2 MS by Aqib Khan

The document consists of a series of programming questions and answers, focusing on various programming concepts including variable assignments, loops, file handling, and functions. It includes specific marks for each part of the questions, detailing expected outputs and explanations. The content is structured to assess understanding of programming logic and syntax.

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)
15 views9 pages

Computer Science Paper 2 MS by Aqib Khan

The document consists of a series of programming questions and answers, focusing on various programming concepts including variable assignments, loops, file handling, and functions. It includes specific marks for each part of the questions, detailing expected outputs and explanations. The content is structured to assess understanding of programming logic and syntax.

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/ 9

1(a) One mark per row: 4

Answer

The value assigned to Level when ThisValue is 40 "Medium"

The value assigned to Check when ThisValue is 36 12

The value assigned to Level when ThisValue is 18 "Low"

The number of elements in array Data that may be 11


incremented

1(b) One mark for identifying assignment: 3

MP1 Level  "Very Low" // the level is assigned value “very low”

Explanation points:

MP2 because CASE clauses are checked in sequence // because of the order
of the clauses
MP3 a value < 30 satisfies the first clause // Clause '< 20' will never be tested

1(c) MP1 all of the possible values are addressed via all / four / three / the other 1
clauses // there are no other possible values to map to OTHERWISE

1(d) One mark per point: 3

• ThisValue: INTEGER
• Check: REAL
• Level: STRING

2(a) Max 5 marks 5

MP1 Set total to zero


MP2 Input a number
MP3 Check if number greater than 29 and less than 71
MP4 … if check is true - add number to total
MP5 Repeat from step 2 99 times // for a total of 100 iterations
MP6 Output the total

2(b) MP1 An iterative construct // a (count-controlled) loop 2


MP2 A selection construct // an IF statement
3(a) PROCEDURE MakeNewFile(OldFile, NewFile, Status : STRING) 7
DECLARE Line1, Line2, Line3 : STRING
DECLARE NumCopied, NumRecs : INTEGER

NumRecs ← 0
NumCopied ← 0

OPENFILE OldFile FOR READ


OPENFILE NewFile FOR WRITE

WHILE NOT EOF(OldFile)


READFILE OldFile, Line1
READFILE OldFile, Line2
READFILE OldFile, Line3
NumRecs ← NumRecs + 1
IF Line3 <> Status THEN
WRITEFILE NewFile, Line1
WRITEFILE NewFile, Line2
WRITEFILE NewFile, Line3
NumCopied ← NumCopied + 1
ENDIF
ENDWHILE

OUTPUT "File " , OldFile , " contained " , NumRecs ,__


" employee details"
OUTPUT Numcopied , " employee sets of details were __
written to file", NewFile
CLOSEFILE OldFile
CLOSEFILE NewFile
ENDPROCEDURE

Mark as follows:

1 Procedure heading and ending, including parameters


2 OPEN OldFile for READ and NewFile for WRITE and subsequently
CLOSE both files
3 Conditional loop until EOF(OldFile)
4 Read three lines from OldFile in a loop
5 Compare 3rd line read with Status parameter and if not equal write
3 lines to NewFile in a loop
6 Count number of sets read and those written in a loop
7 Final output including both counts and file names with suitable text after a
loop

Note:
MP6: Both counts must have been declared and initialised

3(b)(i) Store all three items on one line 1

3(b)(ii) One mark per point: 2

Advantage: Fewer file operations required

Disadvantage: Algorithm to combine / extract individual data items is more


complex
4(a) FUNCTION RandomChar() RETURNS CHAR 6
DECLARE ThisRange : INTEGER
DECLARE ThisChar : CHAR

//First select the range


ThisRange  INT(RAND(3)) + 1 // 1 to 3

CASE OF ThisRange
1: ThisChar  CHR(INT(RAND(26) + 65)) // 65 to 90:
'A' to 'Z'
ThisChar  LCASE(ThisChar) // 'a' to 'z'
2: ThisChar  CHR(INT(RAND(26) + 65)) // 65 to 90:
A to Z
3: ThisChar  NUM_TO_STR(INT(RAND(10)) // '0' to '9'
ENDCASE

RETURN ThisChar
ENDFUNCTION

Mark as follows:

1 Generation of any integer random number


2 Randomly decide which of the three ranges to select
3 Selection structure based on range
4 One alphanumeric character range correct
5 All alphanumeric character ranges correct
6 Return ThisChar, following a reasonable attempt to generate a
character in each range
4(b) FUNCTION FindPassword(Name: STRING) RETURNS STRING 7
DECLARE Index : INTEGER
DECLARE Password : STRING

Password  ""
Index  1

WHILE Password = "" AND Index <= 500


IF Secret[Index, 1] = Name THEN
Password  Decrypt(Secret[Index, 2])
ELSE
Index  Index + 1
ENDIF
ENDWHILE

IF Password = "" THEN


OUTPUT "Domain name not found"
ENDIF

RETURN Password

ENDFUNCTION

Mark as follows:

1 Declare all local variables used, attempted solution has to be reasonable


2 Conditional loop while not found and not end of array
3 Compare value of element in column 1 with parameter passed into
function
4 ...and use Decrypt() with element in column 2 as parameter
5 …use the return value of Decrypt()
6 Output warning message if parameter not found
7 Return STRING value

4(c) One mark for the name, one for the description 3
Name:
 Stub testing

Description:
 A simple module is written to replace each of the modules.
 The simple module will return an expected value // will output a message
to show they have been called

4(d) Acceptone example of a valid password to Max 2 2

One mark for each password example that breaks one of the rules due to:
 Length too long // length too short
 Invalid character
 Incorrect grouping (including number of hyphens)
 Duplicated characters

4(e) One mark for each part: 3

 Generate a random integer divisible by 3


 Split range into 1/3 and set as numeric
 Else alphabetic character
5(a)(i) One mark per point: 2

• EoQ pointer will move to point to location 4 // incremented EoQ (by 1)


• Data value "Octopus" will be stored in location pointed to be EoQ /
location 4

5(a)(ii) One mark for each bullet 2

• Value "Frog" // value pointed to by FoQ / location 0 is assigned to variable


AnimalName
• FoQ pointer will move to point to location 1 / point to "Cat" // incremented
FoQ (by 1)

0 Frog ← Front of queue pointer

1 Cat

2 Fish

3 Elk ← End of queue pointer

5(a)(iii) There is only one data item in the queue 1

5(b)(i) One mark for data values plus one mark for pointers 3

0 Frog

1 Cat

2 Fish ← Front of queue pointer

3 Elk

4 Wasp

5 Bee

6 Mouse ← End of queue pointer

One mark for each pointer


One mark for three new data values
5(b)(ii) 2
0 Shark ← End of queue pointer

1 (Cat)

2 (Fish)

3 (Elk)

4 Wasp ← Front of queue pointer

5 Bee

6 Mouse

7 Dolphin

One mark for BOTH pointers


One mark for all data values as shown

5(c) One mark per point: 3

1 If incremented EoQ = FoQ then error condition: queue is full


2 Increment the EoQ
3 Manage wrap-around
6(a) 7

Mark as follows:
• One mark for START and END
• One mark per area outlined

Outputs from conditional diamond must have at least one label


6(b)(i) One mark per region as indicated. 5

Strin String RetFl Len NextCh


Len1 X New y
g1 2 ag 2 ar
"SUB" "BUS" 3 TRUE 1
3 'S' ""
"B" 1
"BU" 2
3

"BU" 2
2 'U' ""
1
"B" 2

"B" 3
1 'B' ""
1

""
6(b)(ii) TRUE 1

6(b)(iii) One mark for explanation of problem, one mark for test strings 2

Problem:

• The inner FOR loop removes ALL characters from String2 that match the current character from String1 and not just
one instance

Test Strings:

• ‘SAME’ and ‘MASS’ (for example)

6(b)(iv) The inner FOR loop should only remove one instance of the character from String2 1

6(b)(v) • Dry run // White-box testing 1

6(b)(vi) Max 2 marks, features include: 2

• Single stepping
• Breakpoints
• Variable and expressions report window
• Syntax error highlighting

You might also like