CompSci AS P2 memo
CompSci AS P2 memo
PUBLISHED
• INPUT
• Example input statement in language stated
• PROCESS
• Example process statement in language stated
• conditional loop
• the number of iterations is not known
1(c) 3
Statement Error
Cannot multiply a
Code ← RIGHT("Cap" * 3, 2)
string (by 3)
Parameter should
Valid ← IS_NUM(3.14159)
be a string
Closing bracket in
NextChar ← MID(ThisString, Index), 1
wrong place
2(a) • (A program fault is) when the program does not do what it is supposed 2
to do / expected to do
• … under certain circumstances
2(b)(i) Makes it easier to understand the purpose of each identifier / what the 1
identifier is used for / the purpose of the program
Max 3 marks
• white box
• dry-run testing / use of trace table / walk through
Max 1 mark
3(b) 4
START
Set Index to 1
Is Index = NO
101 ?
END
1 Initialise Index
2 Test index for 100 elements
3 End when 100 elements output
4 Output, increment and repeat
1 Initialise Online
2 WHILE .. ENDWHILE loop, terminated when Online = TRUE
3 IF Active = TRUE THEN .. ELSE .. ENDIF
4 Nested IF Active = FALSE THEN .. ELSE .. ENDIF
5 Call Sync() and Call Reset()and Call Error() and assignment to
Online in appropriate place in pseudocode
6 Final call to ReCheck()in appropriate place
4(a)(i) 5
Result Count Index NextChar
0 1
1 1 ‘7’
2 2 ‘4’
3 3 ‘.’
4 4 ‘0’
5 ‘,’
5 6 ‘4’
6 7 ‘.’
7 8 ‘6’
9 ‘,’
8 10 ‘3’
-1 11 ‘x’
0 12 ‘2’
Note:
One mark per region indicated
If no marks by zone then mark by column (max 3)
Values in column 4 must be in quotes
4(a)(ii) 0 (zero) 1
Max 1 mark
RETURN FString
ENDFUNCTION
Mark as follows:
5(b) One mark for check plus one for corresponding test data example. 4
Test data must be invalid to prove that the check is working.
Telephone number:
• Length check // Check that the telephone number string is at least six
characters
e.g. number of "127"
OR
Template:
OR
• Check that there are enough characters in the TelNum string so that
the template can be applied
e.g. Telnum = "123456", Template = "66"
Filename ← ""
RETURN Filename
ENDFUNCTION
1 Conditional loop
2 Use of GetValidFilename()in a loop
3 OPEN file in READ mode and CLOSE in a loop
4 Test if file not empty (using EOF() or READ empty string)
5 If not empty, prompt and input (in case of a non-empty file) in a loop
6 …. and process response
7 Set loop termination condition by checking for new file or overwrite
confirmed
in a loop
8 Return Filename
Total ← 0
Count ← 0
IF Count = 0
THEN
OUTPUT "There are no items in Group: ", Group
ELSE
OUTPUT "Group: ", Group
OUTPUT "Number of items in Group: ", Count
OUTPUT "Total value of items in Group: ", Total
ENDIF
ENDPROCEDURE
Total ← 0
RETURN Total
ENDFUNCTION
Total = 0
Count = 0
If Count = 0 Then
Console.WriteLine("There are no items in Group: " & Group)
Else
Console.WriteLine("Group: " & Group)
Console.WriteLine("Number of items in Group: " & Count)
Console.WriteLine("Total value of items in Group: " & Total)
End If
End Sub
var
Total : real;
Count, Index : integer;
begin
Total := 0;
Count := 0;
if Count = 0 then
writeLn(‘There are no items in Group: ‘, Group)
else
begin
writeLn(‘Group: ‘, Group);
writeLn(‘Number of items in Group: ‘, Count);
writeLn(‘Total value of items in Group: ‘, Total);
end;
end;
def GroupReport(Group):
## Total As Real
## Count, Index As Integer
## ThisID As String
Total = 0
Count = 0
if Count == 0:
print("There are no items in Group: ", Group)
else:
print("Group: ", Group)
print("Number of items in Group: ", Count)
print("Total value of items in Group: ", Total)
Total = 0
Return Total
End Function
var
Index, GroupIndex, Total : Integer;
ThisGroup : String;
begin
Total := 0;
end;
def GroupSummary():
Total = 0
return Total