Past-paper question · 2018 May-June · Paper 21 · Q7

Question 7 2018 · May-June · Paper 21 · 7 marks

Original past-paper question for 7
Original past-paper question for 7
Original past-paper question for 7
Reveal official mark-scheme answer Official mark-scheme answer for 7

Official answer for Question 7

✓
'Pseudocode' solution included here for development and clarification of mark
✓
Max7
✓
scheme.
✓
Programming language solutions appear in the Appendix.
✓
FUNCTION ProcessMarks(Mark: ARRAY[1:20] OF INTEGER)
✓
RETURNS INTEGER
✓
DECLARE Highest : INTEGER
✓
DECLARE Average as REAL
✓
DECLARE Total as INTEGER
✓
DECLARE Position as INTEGER
✓
Total ← 0
✓
Highest ← Mark[1] //The highest mark is the first one
✓
Position ← 1
✓
FOR i ← 1 to 20
✓
Total ← Total + Mark[i]
✓
IF Mark[i] > Highest
✓
THEN
✓
Highest ← Mark[i]
✓
Position ← i
✓
ENDIF
✓
ENDFOR
✓
Average ← Total/20
✓
Output ("The average mark is " & Average & " and the
✓
highest mark is " & Highest)
✓
RETURN Position
✓
ENDFUNCTION
✓
1 mark for each of the following:

Question 1

✓
Correct Function heading (including Mark as parameter) and ending

Question 2

✓
Declare local variable for Highest and initialise

Question 3

✓
Loop structure (1 to 20 or 0 to 19)

Question 4

✓
Comparison with current Highest

Question 5

✓
«Assign new Highest

Question 6

✓
Calculate Average

Question 7

✓
Output message including both variables and explanatory text

Question 8

✓
Return value of index
✓
*** End of Mark Scheme – example program code solutions follow ***
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Appendix
✓
Program Code Example Solutions
✓
Q5(c)
✓
Visual Basic
✓
Sub AddNewScores()
✓
Dim
✓
FileData As String
✓
Dim
✓
MembershipNumber As String
✓
Dim
✓
Score As Integer
✓
Dim
✓
ScoreDate As String
✓
Dim
✓
FileHandle As IO.StreamWriter
✓
FileHandle = New IO.StreamWriter("ScoreDetails.txt")
✓
Console.WriteLine("Input the date for the scores")
✓
ScoreDate = Console.ReadLine()
✓
Console.WriteLine("Input the Membership number")
✓
MembershipNumber = Console.ReadLine()
✓
Do While MembershipNumber <> ""
✓
Console.WriteLine("Input the score")
✓
Score = Console.ReadLine()
✓
Do While Score < 50 Or Score > 99
✓
Console.WriteLine("Input a valid score from 50 to 99")
✓
Score = Console.ReadLine()
✓
Loop
✓
FileData = MembershipNumber & ScoreDate & Str(Score)
✓
FileHandle.WriteLine(FileData)
✓
Console.WriteLine("Input the Membership number")
✓
MembershipNumber = Console.ReadLine()
✓
Loop
✓
FileHandle.Close()
✓
End Sub
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Python
✓
def AddNewScores():
✓
#ScoreDate as string
✓
#MembershipNumber as string
✓
#Score as integer
✓
#FileHandle as text file
✓
FileHandle = open("ScoreDetails.txt", "a")
✓
ScoreDate = str(input("Input the date for the scores"))
✓
MembershipNumber = str(input("Input the Membership number"))
✓
while MembershipNumber != "":
✓
Score = int(input("Input the score"))
✓
while Score < 50 or Score > 99:
✓
Score = int(input("Input a valid score from 50 to 99"))
✓
FileData = MembershipNumber + ScoreDate + str(Score)
✓
FileHandle.write(FileData)
✓
MembershipNumber = str(input("Input the Membership number"))
✓
FileHandle.close
✓
Pascal
✓
procedure AddNewScores;
✓
var FileData, ScoreDate, MembershipNumber: String;
✓
Score: Integer
✓
MyFile: text;
✓
begin
✓
assign(MyFile,'ScoreDetails.txt');
✓
append(MyFile);
✓
writeln('Input the date for the scores');
✓
readln(ScoreDate);
✓
writeln('Input the Membership number');
✓
readln(MembershipNumber);
✓
while MembershipNumber <> '' do
✓
begin
✓
writeln('Input the score');
✓
readln(Score);
✓
while (Score < 50) or (Score > 99) do
✓
begin
✓
writeln('Input the score');
✓
readln(Score);
✓
end;
✓
FileData := MembershipNumber + ScoreDate + IntToStr(Score);
✓
write(MyFile, FileData);
✓
writeln('Input the Membership number');
✓
readln(MembershipNumber);
✓
end;
✓
close (MyFile);
✓
end;
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Q7
✓
Visual Basic
✓
Function ProcessMarks(ByVal Mark() As Integer) As Integer
✓
Dim
✓
Highest As Integer
✓
Dim
✓
Average As Single
✓
Dim
✓
Total As Integer
✓
Dim
✓
Position As Integer
✓
Dim
✓
i As Integer
✓
Total = 0
✓
Position = 1
✓
Highest = Mark(1)
✓
For i = 1 To 20
✓
Total = Total + Mark(i)
✓
If Mark(i) > Highest Then
✓
Highest = Mark(i)
✓
Position = i
✓
End If
✓
Next
✓
Average = Total / 20
✓
Console.WriteLine ("The average mark is " & Average & _
✓
" and the highest mark is " & Highest)
✓
Return Position
✓
End Function
✓
Python
✓
def ProcessMarks (mark):
✓
#highest, i, position, total as integer
✓
#average as real
✓
highest = mark[0]
✓
total = 0
✓
position = 0
✓
for i in range(0,20):
✓
total = total + mark[i]
✓
if mark[i] > highest:
✓
highest = mark[i]
✓
position = i
✓
average = total/20
✓
print('The average mark is ' + str(average) + \
✓
' and the highest mark is ' + str(highest))
✓
return position

Mark scheme 9608_s18_ms_21.pdf →

Show text version of question

Question 7

A
function, ProcessMarks(), is required to analyse test marks for a class of students.
  • There are 20 students in the class.
  • A mark is between 0 and 100.
  • The marks for the class are stored in an array, Mark, which has 20 elements.
  • The array is passed to the function as a parameter.
  • The function will output a message stating the average and highest marks. For example:
  • "The average mark is 34 and the highest mark is 76"

  • The function returns the subscript of the highest mark.

Write program code to implement the ProcessMarks() function.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

......................................................................................................................................................[7]

Question 15

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 string "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of string 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 string "ABC"

LCASE(ThisChar : CHAR) RETURNS CHAR returns the character value representing the lower case equivalent of ThisChar

If ThisChar is not an upper-case alphabetic character then it is returned unchanged. Example: LCASE('W') returns 'w'

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

Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar

Example: ASC('A') returns 65

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

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 16

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 International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series.

Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself 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_s18_qp_21.pdf

Keep practising this topic