# A level Computer science Pre Release Material Paper 2 solution 2017

## What is pre release material?

Pre release material is sent by CIE to studnets who are currently studying O level Computer science or A level Computer science, the pre release material contains programming related Tasks to prepare students for Cambridge international examinations, for O level students the pre release material is sent only for Computer science Paper 2 and for A level students the pre release is sent for Computer science paper 2 and paper 4.

## Task 1 – Stages of simple Alogrithm

### (a) Fundamental algorithm stages:input, process and Output.

Describe a range of activities in terms of these three stages.

Draw examples from different areas such as:

• Manufacturing
• College/School
• Data Processing Systems

#### Solution

[table id=8 /]

Give examples of programming statements that illustrate each of the three stages.

Compare similar statements in Pseudocode and High-level Languages.

[table id=9 /]

### (b) Appreciate the use of  logic Statements within an algorithm.

Given the following Pseudocode assignments:

FlagA True

FlagB  False

FlagC True

MyNum  27

Evaluate the Following expressions:

[table id=10 /]

[table id=11 /]

#### Task 2 – Programming basics: Loops

This is Pseudocode for a simple count-controlled loop:

```For Count  1 to 100
Output count
EndFOR```

Re-write this Pseudocode to provide the same functionality using:

1. A post-condition loop
2. A pre-condition loop

##### 1.Post-Condition Loop

```     DECLARE count : INTEGER
count ← 1 REPEAT OUTPUT count
count ← count +1
UNTIL count > 100```
##### 2.Pre-Condition Loop

```     DECLARE count : INTEGER
count ← 0
WHILE count < 100
count ← count + 1
OUTPUT count
ENDWHILE```

Modify the solutions from Task 2.1 to:

1. Prompt for the input of start and end value.
2. Output all the numbers between the start and end values that are exactly divisible by 3.

##### 1.Post-Condition Loop

```DECLARE count : INTEGER
DECLARE start : INTEGER
DECLARE end : INTEGER
OUTPUT “Enter starting value”
INPUT start
OUTPUT “Enter final value”
INPUT end
count ← start + 1
REPEAT
IF MOD(count, 3) = 0
THEN
OUTPUT count
ENDIF count ← count +1
UNTIL count > end - 1```
##### 2. ​Pre-Condition Loop

```DECLARE count : INTEGER
DECLARE start : INTEGER
DECLARE end : INTEGER
OUTPUT “Enter starting value”
INPUT start
OUTPUT “Enter final value”
INPUT end
count ← start
WHILE  count < end - 1
count ← count + 1
IF MOD(count, 3) = 0
THEN
OUTPUT count
ENDIF
ENDWHILE```

#### Task 3 – program design and coding

A string exists in CamelCase format, for example: ‘ThisIsACamelCaseString’

A procedure is required that will:

• prompt for the original string
• separate each word of the string
• store each word in separate array element
• fill unused array elements with a rogue string such as “(Empty)”.

After processing the preceding example, the array content will look like this:

This

Is

A

Camel

Case

String

(Empty)

(Empty)

(Empty)

Use pseudocode to declare the array that can be used to store the separate words of the original string.

You can assume that the original string will contain no more than 10 separate words.

`DECLARE Word : ARRAY[1:10] OF STRING`

Express the requirements using Structured English.

##### Identifier table:
[table id=12 /]

```SET count to 1
SET index to 0
OUTPUT "enter camelcase string"
INPUT camelstring
REPEAT
IF count is less than the length of camelstring THEN
set charactercode to ascii value of (count)-th letter in camelstring
IF charactercode is between 65 and 90 THEN
increment index
ENDIF
Add (count)-th letter in camelstring to word(index)
increment count
ELSE
increment index
set word(index) to “(empty)”
ENDIF
UNTIL index is equal to 10```

Write pseudocode for this design.

```DECLARE Word : ARRAY[1:10] OF STRING
DECLARE Charactercode : String
DECLARE CamelString : STRING
DECLARE Count : INTEGER
Count ← 1
DECLARE Index : INTEGER
Index ← 0
OUTPUT "Enter CamelCase String"
INPUT CamelString
REPEAT
IF Count <= LENGTH(CamelString)
THEN
Charactercode ← ASC(MID(CamelString, Count, 1))
IF Charactercode <= 90 AND Charactercode >= 65
THEN
Index ← Index + 1
ENDIF
Word[Index] ← Word[Index] & CHR(Charactercode)
Count ← Count + 1
ELSE
Index ← Index + 1
Word[Index] ← "(empty)"
ENDIF
UNTIL Index = 10 ```

Write program code for this design.

```
Sub Main()
Dim charactercode As String
Dim word(9) As String
Dim count As Integer = 1
Dim index As Integer = -1
Dim CamelString As String
Console.WriteLine("Enter CamelCase String")
Do
If count &amp;amp;amp;amp;amp;amp;amp;lt;= Len(CamelString) Then
charactercode = Asc(Mid(CamelString, Count, 1))
If charactercode &amp;amp;amp;amp;amp;amp;amp;lt;= 90 And charactercode &amp;amp;amp;amp;amp;amp;amp;gt;= 65 Then
index = index + 1
End If
word(index) = word(index) &amp;amp;amp;amp;amp;amp;amp;amp; Chr(charactercode)
count = count + 1
Else
index = index + 1
word(index) = "(empty)"
End If
Loop Until index = 9
End Sub

```

Amend your program code to print out the contents of the array in a format that is easy to understand.

```
Sub Main()
Dim charactercode As String
Dim word(9) As String
Dim count As Integer = 1
Dim index As Integer = -1
Dim CamelString As String
Console.WriteLine("Enter CamelCase String")
Do
If count &amp;amp;amp;amp;amp;amp;amp;amp;lt;= Len(CamelString) Then
charactercode = Asc(Mid(CamelString, Count, 1))
If charactercode &amp;amp;amp;amp;amp;amp;amp;amp;lt;= 90 And charactercode &amp;amp;amp;amp;amp;amp;amp;amp;gt;= 65 Then
index = index + 1
End If
word(index) = word(index) &amp;amp;amp;amp;amp;amp;amp;amp;amp; Chr(charactercode)
count = count + 1
Else
index = index + 1
word(index) = "(empty)"
End If
Loop Until index = 9
Console.writline()                //'ammendments to the program from here:
For a As integer = 0 to 9
Console.Write(word(a) &amp;amp;amp;amp;amp;amp; " ")
End Sub

```

Design Suitable test data to test the code thoroughly. Justify your choice.

Invalid data:  “computer”

Output:          IndexOutOfRangeException

Valid data:

1. “AStringInCamelCaseFormat”

2. “COMPUTER”

3. “SEQUENTIAL”

Output:

1. A String In Camel Case Format (empty) (empty) (empty) (empty)

2. C O M P U T E R (empty) (empty)

3. S E Q U E N T I A L

#### Task 4 – File Handling

The Computer club at sports club maintains a log of attendances of each member .Each time a member visits the club, an entry is added to the log file as follows:

• Membership number ( 6 Characters, for example “123456”)
• Date of Visit ( 8 Characters , for example “28/07/15”)

The system Concatenates these data items and adds them as a single line to the file.

```DECLARE membernum : STRING
DECLARE visitdate : STRING
OPENFILE "VisitLog.txt" FOR WRITE
OUTPUT "Enter "endlog" when prompted for Membership Number to terminate program"
REPEAT
OUTPUT "Enter Membership Number"
INPUT membernum
OUTPUT "Enter date of visit"
INPUT visitdate
IF membernum <> "endlog"
THEN
FILEWRITE "VisitLog.txt" , membernum & visitdate
ENDIF
UNTIL membernum = "endlog"
CLOSEFILE "VisitLog.txt"

```

Write Pseudocode to create a text file containig log data for a number of attendances by sports club members. The user will input the two strings described above and these will be concatenated and added to the file.

The process will repeat until a rogu value is input.

```DECLARE membernum : STRING
DECLARE visitdate : STRING
OPENFILE "VisitLog.txt" FOR WRITE
OUTPUT "Enter "endlog" when prompted for Membership Number to terminate program"
REPEAT
OUTPUT "Enter Membership Number"
INPUT membernum
OUTPUT "Enter date of visit"
INPUT visitdate
IF membernum <> "endlog"
THEN
FILEWRITE "VisitLog.txt" , membernum & visitdate
ENDIF
UNTIL membernum = "endlog"
CLOSEFILE "VisitLog.txt"```

Write pseudocode to append a new data line to the existing file.

```OUTPUT "Enter Membership Number"
INPUT membernum
OUTPUT "Enter date of visit"
INPUT visitdate
OPENFILE "VisitLog.txt" FOR APPEND
FILEWRITE "VisitLog.txt" , membernum & visitdate
CLOSEFILE "VisitLog.txt"```

Write pseudocode to output a list of visits made by a member. Prompt the user to input the membership number and output the date of each visit by that member. If the membership number is not found, output a suitable message.

```DECLARE Entry : STRING
DECLARE Flag : BOOLEAN Flag2 ← TRUE
OUTPUT "Enter Membership Number"
INPUT membernum
WHILE NOT EOF("VisitLog.txt")
IF LEFT(Entry, 6) = membernum
THEN
OUTPUT RIGHT(Entry, 8)
Flag ← FALSE
ENDIF
ENDWHILE
CLOSEFILE
IF Flag = TRUE
THEN

```
Imports System.IO
Module Module1
Dim membernum As String
Dim visitdate As String
Dim path As String
Sub Main()
Dim a As Integer = 0
Console.WriteLine("Enter path of file") ' “C:\VisitLog.txt” can be a possible path
path = Console.ReadLine ' delete the file once you’re done
MakeVisitLog()
Console.WriteLine()
Appendlog()
Console.WriteLine()
SearchMember()
End Sub
Sub MakeVisitLog()
Dim Filewriter As New StreamWriter(path, False)
Console.WriteLine("Enter ""end"" when prompted for Membership Number to terminate
program”)
Do
Console.WriteLine()
Console.WriteLine("Enter Membership Number")
If membernum &lt;&gt; "end" Then
Console.WriteLine("Enter date of visit")
Filewriter.WriteLine(membernum &amp; visitdate)
End If
Loop Until membernum = "end"
Filewriter.Close()
End Sub
Sub Appendlog()
Console.WriteLine("Enter Membership Number")
Console.WriteLine("Enter date of visit")
Dim Filewriter As New StreamWriter(path, True)
Filewriter.WriteLine(membernum &amp; visitdate)
Filewriter.Close()
End Sub
Sub SearchMember()
Dim Entry As String
Dim Flag As Boolean = True
Console.WriteLine("Enter Membership Number")
Do
If Left(Entry, 6) = membernum Then
Console.WriteLine(Right(Entry, 8))
Flag = False
End If
If Flag = True Then
End If
End Sub
End Module

```
` `

Extend the program from Task 4.4. The program will represent a menu to allow the user to repeatedly add a new visit (4.2) or print the visits (4.3). Use a suitable input value to terminate the program.

```
Imports System.IO
Module Module1
Dim membernum As String
Dim visitdate As String
Dim path As String
Sub Main()
Dim a As Integer = 0
Console.WriteLine("Enter path of file") ' “C:\VisitLog.txt” can be a possible
path
path = Console.ReadLine() ' delete the file once you’re done
Console.WriteLine()
MakeVisitLog()
Do
Console.WriteLine()
Console.WriteLine("Enter: ")
Console.WriteLine("1 ; for adding a new visit | 2 ; for printing the visits for a specific
member")
Console.WriteLine("3 ; terminate program")
Console.WriteLine()
If a = 1 Then
Appendlog()
ElseIf a = 2 Then
SearchMember()
End If
Loop Until a = 3
End Sub
Sub MakeVisitLog()
Dim Filewriter As New StreamWriter(path, False)
Console.WriteLine("Enter ""end"" when prompted for Membership Number to terminate
program")
Do
Console.WriteLine()
Console.WriteLine("Enter Membership Number")
If membernum <> "end" Then
Console.WriteLine("Enter date of visit")
Filewriter.WriteLine(membernum & visitdate)
End If
Loop Until membernum = "end"
Filewriter.Close()
End Sub
Sub Appendlog()
Console.WriteLine("Enter Membership Number")
Console.WriteLine("Enter date of visit")
Dim Filewriter As New StreamWriter(path, True)
Filewriter.WriteLine(membernum & visitdate)
Filewriter.Close()
End Sub
Sub SearchMember()
Dim Entry As String
Dim Flag As Boolean = True
Console.WriteLine("Enter Membership Number")
Do
If Left(Entry, 6) = membernum Then
Console.WriteLine(Right(Entry, 8))
Flag = False
End If
If Flag = True Then
End If
End Sub
End Module
```

## A Level Computer Science 9608 Pre Release Task 4 explained by james waring

SHARE
Previous articlePakistan Studies-History- Source based Questions.
Hello, I am a Web developer and blogger, currently a UETian, I want to compile all the best O and A level resources at one place for the ease of students.