Question 8(c)(ii) 2015 · October-November · Paper 21 · 2 marks
Reveal official mark-scheme answer
Official answer for Question 8
Part (c)
(ii)
(ii)
Question 3
Question 4
Question 1
Question 4
Question 16
Question 16
Question 1
Show text version of question
Question 8
Part (c)
(ii)
Question 8
In this question you will need to use the given pseudocode built-in function:
ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR returns the single character at position Position (counting from the start of the string with value 1) from the string ThisString. For example: ONECHAR("Barcelona", 3) returns 'r'. The following pseudocode uses these additional built-in functions:
TONUM(ThisDigit : CHAR) RETURNS INTEGER returns the integer value of character ThisDigit For example: TONUM('8') returns digit 8.
TOSTR(ThisNumber : INTEGER) RETURNS STRING returns the string value of integer ThisNumber For example: TOSTR(27) returns "27".
Study the pseudocode.
Complete the three dry runs for the three given values of FractionString.
OUTPUT "Enter the expression" INPUT FractionString
// isolate each number digit and assign its number value ← N1Char ONECHAR(FractionString, 1) N1 ← TONUM(N1Char) ← N2Char ONECHAR(FractionString, 3) N2 ← TONUM(N2Char) ← N3Char ONECHAR(FractionString, 5) N3 ← TONUM(N3Char) ← N4Char ONECHAR(FractionString, 7) N4 ← TONUM(N4Char)
BottomAnswer ← N2 * N4
Op ← ONECHAR(FractionString, 4) IF Op = '+' THEN // add fractions TopAnswer ← (BottomAnswer / N2) * N1 + (BottomAnswer / N4) * N3 ELSE // subtract fractions TopAnswer ← (BottomAnswer / N2) * N1 - (BottomAnswer / N4) * N3 ENDIF
IF TopAnswer = BottomAnswer THEN OUTPUT '1' ELSE IF TopAnswer > BottomAnswer THEN TopAnswer ← TopAnswer MOD BottomAnswer // the & operator joins strings or character values OUTPUT "1 " & TOSTR(TopAnswer) & "/" & TOSTR(BottomAnswer) ELSE OUTPUT TOSTR(TopAnswer) & "/" & TOSTR(BottomAnswer) ENDIF ENDIF
Question 19
(ii)
FractionString ← "3/4+1/4"
N1 N2 N3 N4 BottomAnswer Op TopAnswer OUTPUT
Why this question appears here
82% 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_w15_qp_21.pdf
