Past-paper question · 2021 May-June · Paper 23 · Q6(c)

Question 6(c) 2021 · May-June · Paper 23 · 17 marks

Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Original past-paper question for 6(C)
Reveal official mark-scheme answer Official mark-scheme answer for 6(C)

Official answer for Question 6

Part (c)

✓
‘Pseudocode’ solution included here for development and clarification of

Question 7

✓
mark scheme.
✓
Programming language example solutions appear in the Appendix
✓
FUNCTION GroupSummary() RETURNS INTEGER
✓
DECLARE Index, GroupIndex Total : INTEGER
✓
DECLARE ThisGroup : STRING
✓
Total ← 0
✓
FOR Index ← 1 TO 10000
✓
IF StockID[Index] <> ""
✓
THEN
✓
ThisGroup ← LEFT(StockID[Index], 4)
✓
GroupIndex ← Lookup(ThisGroup)
✓
IF GroupIndex = -1
✓
//ThisGroup not found
✓
THEN
✓
//add new group
✓
Summary[Total + 1] ← ThisGroup
✓
Total ← Total + 1
✓
ENDIF
✓
ENDIF
✓
ENDFOR
✓
RETURN Total
✓
ENDFUNCTION
✓
1 mark for each of the following:

Question 1

✓
Function heading and ending and final return of Total

Question 2

✓
Declare and initialise Total

Question 3

✓
Loop through all 10 000 elements

Question 4

✓
Skip empty StockID in a loop

Question 5

✓
Extract ThisGroup from StockID and pass to Lookup()

Question 6

✓
… if Lookup() returns −1 (following reasonable attempt at MP5)

Question 7

✓
…….Store ThisGroup to Summary[Total] and increment Total
✓
9608/23
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Program Code Example Solutions
✓
Question 6(b): Visual Basic
✓
Sub GroupReport(Group As String)
✓
Dim Total As Double
✓
Dim Count, Index As Integer
✓
Total = 0
✓
Count = 0
✓
For Index = 0 To 3 ‘1 to 10000
✓
If Left(StockID(Index), 4) = Group Then
✓
Count = Count + 1
✓
Total = Total + (Quantity(Index) * Cost(Index))
✓
End If
✓
Next Index
✓
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
✓
Question 6(b): Pascal
✓
procedure GroupReport(Group : string);
✓
var
✓
Total : real;
✓
Count, Index : integer;
✓
begin
✓
Total := 0;
✓
Count := 0;
✓
for Index := 1 TO 10000 do
✓
begin
✓
if LeftStr(StockID[Index], 4) = Group then
✓
begin
✓
Count := Count + 1;
✓
Total := Total + (Quantity[Index] * Cost[Index]);
✓
end;
✓
end;
✓
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;
✓
9608/23
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question 6(b): Python
✓
def GroupReport(Group):
✓
## Total As Real
✓
## Count, Index As Integer
✓
## ThisID As String
✓
Total = 0
✓
Count = 0
✓
for Index in range(1, 10001):
✓
ThisID = StockID[Index]
✓
if ThisID[:4] == Group:
✓
Count = Count + 1
✓
Total = Total + (Quantity[Index] * Cost[Index])
✓
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)
✓
Question 6(c): Visual Basic
✓
Function GroupSummary() As Integer
✓
Dim Index, GroupIndex, Total As Integer
✓
Dim ThisGroup As String
✓
Total = 0
✓
For Index = 1 TO 10000
✓
If StockID(Index) <> "" Then
✓
ThisGroup = Left(StockID(Index), 4)
✓
GroupIndex = Lookup(ThisGroup)
✓
If GroupIndex = -1 Then
✓
// ThisGroup not found
✓
Summary(Total + 1) = ThisGroup
✓
// Add new Group
✓
Total = Total + 1
✓
End If
✓
End If
✓
Next Index
✓
Return Total
✓
End Function
✓
9608/23
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question 6(c): Pascal
✓
function GroupSummary() : Integer;
✓
var
✓
Index, GroupIndex, Total : Integer;
✓
ThisGroup : String;
✓
begin
✓
Total := 0;
✓
for Index := 1 TO 10000 do
✓
begin
✓
if StockID[Index] <> "" then
✓
begin
✓
ThisGroup := LeftStr(StockID[Index], 4);
✓
GroupIndex := Lookup(ThisGroup);
✓
If GroupIndex = -1 then
✓
//ThisGroup not found
✓
begin
✓
Summary[Total + 1] := ThisGroup; //Add new Group
✓
Total := Total + 1;
✓
end;
✓
end;
✓
end;
✓
GroupSummary := Total; // result := Total;
✓
end;
✓
Question 6(c): Python
✓
def GroupSummary():
✓
## Index, GroupIndex, Total As Integer
✓
## ThisGroup, ThisID As String
✓
Total = 0
✓
for Index in range(1, 10001):
✓
ThisID = StockID[Index]
✓
if ThisID != "":
✓
ThisGroup = ThisId[:4]
✓
GroupIndex = Lookup(ThisGroup)
✓
if GroupIndex == -1:
✓
#ThisGroup not found
✓
Summary[Total + 1] = ThisGroup
✓
#Add new Group
✓
Total = Total + 1
✓
return Total

Mark scheme 9608_s21_ms_23.pdf →

Show text version of question

Question 6

Part (c)

Question 6

A program stores data about stock items in four global 1D arrays as follows:

Example Initial data Array Data type Description data value value the stock item ID StockID STRING (eight alpha-numeric "ABLK0001" "" characters) a description of the item Description STRING "torch" "" (alphabetic characters only) Quantity INTEGER the number in stock 6 0

Cost REAL the cost of the item 4.80 0.0

  • Each array contains 10 000 elements.
  • Elements with the same index relate to the same stock item. For example, StockID[5]

contains the ID for the product whose description is in Description[5].

  • The StockID array is not sorted and unused elements may occur at any index position.
  • Unused elements are assigned the initial data value shown in the table above.
  • The first four characters of the StockID represent a product group. The last four characters

represent the item within the group.

The program is to be modified so that:

  • data from the arrays are stored in a text file for backup purposes. Data from unused elements

are not stored in the file.

  • a Summary array is added. This will be a global 1D array of 500 elements of type STRING.

Each product group will occur once in the array, for example "ABLK" for the item in the table above.

The programmer has started to define program modules as follows:

Module Description

  • prompts and inputs a filename
  • GetValidFilename()

  • returns a valid filename as a STRING
  • calls GetValidFilename() for a filename
  • checks if the file is empty
  • CheckBackupFile() • If the file is not empty ask the user to confirm that overwrite is intended. If not intended allow the user to re-input a different filename.

  • returns the filename.

Question 17

Part (c)

Two additional modules are required:

Module Description

  • called with a STRING representing a product group
  • (for example, "ABLK") Lookup()

  • searches the Summary array for the group
  • returns the index position or returns −1 if not found
  • stores each product group name (found in the
  • StockID array) into the Summary array, if not there already GroupSummary() • calls Lookup() to check whether the name is already in the Summary array

  • returns the number of product groups added to the

Summary array

You can assume:

  • all elements of the Summary array have been initialised to the value "" before
  • GroupSummary() is called

  • there will be no more than 500 product groups.

Write program code for the module GroupSummary().

Visual Basic and Pascal: You should include the declaration statements for variables. Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

Program code

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

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

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

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

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

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

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

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

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

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

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

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

Question 21

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[7]

Question 22

Appendix Built-in functions (pseudocode) Each function returns an error if the function call is not properly formed.

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING returns a string representation of a numeric value. Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL returns a numeric representation of a string. Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

IS_NUM(ThisString : STRING) RETURNS BOOLEAN returns the value TRUE if ThisString contains only numeric characters ('0' to '9').

Example: IS_NUM("123a") returns FALSE

Question 23

Operators (pseudocode)

Operator Description Concatenates (joins) two strings & Example: "Summer" & " " & "Pudding" produces "Summer Pudding" Performs a logical AND on two Boolean values AND Example: TRUE AND FALSE produces FALSE Performs a logical OR on two Boolean values OR Example: TRUE OR FALSE produces TRUE

Question 24

reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.

Topic relevance

Why this question appears here

99% assigned-topic match · Data types and structures › Data types and records

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_s21_qp_23.pdf

Keep practising this topic