May/June 2011 - P2 9691/22 Q&As

22 views
Skip to first unread message

9691 Discussion Group

unread,
Jun 3, 2011, 11:02:35 AM6/3/11
to Computing (9691 CIE Syllabus)
May/June 2011 - P2 9691/22 Q&As

Dear group members,
We could only get hold of 9691/22 below and have solved it for all
group members. If you have P21 or P23 then solve or upload that for
the group to review/check/discuss their own answer.
-Admin

1 Ahmed, a designer, stores the following details of each job that he
does in a file.
.job ID (a whole number between 1 and 1000 inclusive)
.job description
.price (greater than $10 and not more than $5000)
.expected completion date
.paid (yes/no)
(a) Complete the following table.
Field Name/Data Type/Size of Field (bytes)
JoblD/Integer/2
JobDescription/Character/15
Price/Real/2
ExpectedCompletionDate/Chracter/10
Paid/ Boolean/1
[10]

(b) The details of the last 200 jobs are stored in the file.
Estimate the size, in kilobytes, of the file. Show your working.
Record size = 30 Bytes
Total records (file) size = 30 x 200 = 6000 Bytes
10% Housekeeping = 600
Actual file size = 6000 + 600 = 6600 B (6.6KB)
[5]

(c) In a high-level programming language of your choice, write the
code to define the record type for the record structure in part (a).
Language: Visual Basic
Code:
Type myRec
JoblD as Integer
JobDescription as Character
Price as Real
ExpectedCompletionDate as Chracter
Paid as Boolean
End Type
(Refer to http://www.vb6.us/tutorials/user-defined-types-udt-vb)
[3]

(d) Some data will need to be validated when entered.
(i) State what is meant by validation. [3]
-Data validation is the process of ensuring that a program operates on
clean, correct and useful input data.
-It uses routines, often called "validation rules" or "check
routines", that check for correctness, meaningfulness, and security of
data that are input to the system.
-The rules may be implemented by the inclusion of explicit application
program validation logic.
[1]

(ii) Describe two different validation checks that can be performed on
the ExpectedCompletionDate
Format or picture check: Checks that the data is in a specified format
(template), e.g., dates have to be in the format DD/MM/YYYY.
Range check: Checks that the data lie within a specified range of
values, e.g., the month of a date lie between 1 and 12.
[2]

(e) The logic statement to validate the Price field is (Price > 10)
AND (Price <= 5000)
Write a similar logic statement to validate each of the following.
JobID:
(JobID >= 1) AND JobID <= 1000)
Paid:
(Paid = 'Yes') OR (Paid = 'yes') OR (Paid = 'No') OR (Paid = 'no')
[4]

(f) The code for the validation will have to be tested.
State four items of data you would use to test the JoblD validation.
State the reasons for using that test data.
Test No/JobID value/Reason
Test 1/1,1000/extremem ranges working
Test 2/500,758/normal ranges working
Test 3/-1,0 /-ve values dealing
Test 4/a,560/non number characters dealing

2 Raul wants to write a program that will count the number of vowels
in a word. He starts by writing some pseudocode that will count the
number of letter 'a'.
1 INPUT Word
2 Count <- 0
3 LOOP FOR Index <- 1 TO length(Word)
4 IF Word(Index)<-'a'
5 THEN
6 Count <- Count + 1
7 ENDIF
8 ENDLOOP
(a) (i) Complete the trace table for this pseudocode using 'banana' as
input.
The first seven rows have been filled in.
Word Count Index Word(Index) Word(Index)='a'
banana
0
1
b
false
2
a
true
1
3
n
false
4
a
true
2
5
n
false
6
a
true
3
7
[6]

(ii) Complete this trace table for the pseudocode using 'Ant' as
input.
1 INPUT Word
2 Count <- 0
3 LOOP FOR Index <- 1 TO length(Word)
4 IF Word(Index)<-'a'
5 THEN
6 Count <- Count + 1
7 ENDIF
8 ENDLOOP
Word Count Index Word(Index) Word(Index)='a'
Ant
0
1
A
false
2
n
false
3
t
false
4
(N.B: Computer checks/compares characters using their ASCII codes.
Char('a')=97 and char('A')=65, thus 'a' <> 'A')

(b) Raul wants uppercase 'A' to be counted as well as each lower case
'a'. Re-write line 4 of the pseudocode so that every 'A' is included
in the count.
IF Word(Index)<-'a' OR Word(Index)<-'A'
[2]

(c) (i) The pseudocode has features that make it easy to understand.
State two such features.
Feature 1:
It is intended for human reading rather than machine reading.
Pseudocode typically omits details that are not essential for human
understanding of the algorithm, such as variable declarations, system-
specific code and subroutines.

Feature 2:
It enables the programmer to concentrate on the algorithms without
worrying about all the syntactic details of a particular programming
language. In fact, we can write pseudocode without even knowing what
programming language we will use for the final implementation.
[2]

Program code is to be produced from the pseudocode.
(ii) State one other feature that could be introduced to make the
program code easy to understand.
-Use of proper and relevant names for variable etc.
-Use of comments, etc.
[1]

(iii) State two reasons why it is important for the program to be
easily understood.
Reason 1:
Later someone else work on the code written by us.

Reason 2:
Later after a significant time if we re-work or work around the code
then we might have troupble ourself for:
Readability
Ease of maintenance, testing, debugging, fixing, modification and
portability
Low complexity
Low resource consumption: memory, CPU
Robust input validation and error handling, established by software
fault injection
[2]

(d) Each letter in the alphabet has an ASCII code.
(i) What form does an ASCII code take?
ASCII codes are designed as numbers allocated to each letter as
computer unlike humans cannot understand the graphics.
Each number is designed to be <=255, so it does not grow beyond a
single byte when converted to binary.
Uppercase letters are in the range of 65/01000001 (for letter A) and
90/01011010 (for letter Z)
Lowercase letters are in the range of 97/01100001 (for letter a) and
122/01111010 (for letter z)

(ii) Describe how ASCII codes can be used to arrange two lower case
letters in alphabetical order.
-ASCII code for lower case are ranging from 97 to 122 for a to z
respectively.
-Computer would find out the ASCII code for both of the lowercase
letters.
-ASCII code for the lowercase letter lower in alphabetical order would
be smaller then then other.
-So all letters will be arranged by the computer according to their
ascending ASCII codes and thus will be arranged in alphabetical order.
[3]

(iii) Describe how two words (lower case letters only) can be arranged
in alphabetical order.
-Find the ASCII codes for every letter of both the word
-Sum them up separately for both lowercase words
-Compare the summed ASCII code numbers of both of the characters
-Place the word with lower number before the word having higher
number.
[4]

3 Raul writes a program which will keep a tally of the number of times
each letter appears in a given text. He uses an array of size 26 to
store the totals for each letter. He then initialised each element of
the array.
(a) What value should Raul give each element?
Raul should initialise every array element to zero/0.

(b) Define the array and initialise each element of the array using a
high-level programming language of your choice.
Language: Visual Basic
Code:
DIM CountArr(26) as Integer
DIM Count as integer
Count = 0
For Count = 1 to 26
CountArr(Count) = 0
Next Count
[4]

(c) Write the statements required to update the array when a letter
has been read.
For Count = 1 to 26
IF Count = (ASC(letterRead) - 96) Then
CountArr(Count) = CountArr(Count) + 1
Exit FOR
ENDIF
Next Count
(N.B: Supposedly every array element index is numbered after the
lowercase alphabetical order, like 1 for a, 2 for b and 3 for c etc.
So a loop runs for 26 times supposedly for every lowercase character,
in every loop round it is checked that if current count is equal to
the [ASC(letterRead) - 96], which is, suppose if 'd' is enetered then
its array element index would be 4, now ASC('d') = 100 and 100 - 96 =
4, thus as soon as variable Count reaches 4, array element holding
index 4 will be increased by one and Loop discontinued.
[3]

4 The following pseudocode is a recursive function where n is an
integer.
FUNCTION prod(n)
IF n = 1
THEN
prod <- 1 ELSE
prod <- n * prod (n-1)
ENDIF
RETURN
(a)
(i) What value is returned by prod(1)?
1 will be returned by this function.
[1]

(ii) What value is returned by prod(3)?
6 will be returned by this function.
[1]

(b) (i) What happens if the parameter passed is -1?
-Since there is no validation check for the values entered,
-And entered value is different then value expected by this
pseudocode,
-This would become a never ending loop and system will be hanged
altogether.
[2]

What changes will need to be made to the pseudocode to address the
problem in (b)(i)?
After line 1 of the code add following:
IF (n < 1) THEN
prod <- 0
RETURN
ENDIF

(c) Rewrite this function in pseudocode as an iterative function.
FUNCTION prod(n)
Count <- 0
Product <- 1
LOOP FOR Count <- 1 to n
Product <- Product * Count
ENDLOOP
prod <- Product
RETURN
[4]
Reply all
Reply to author
Forward
0 new messages