Past-paper question · 2016 May-June · Paper 23 · Q2(a)

Question 2(a) 2016 · May-June · Paper 23 · 8 marks

Original past-paper question for 2(A)
Original past-paper question for 2(A)
Original past-paper question for 2(A)
Reveal official mark-scheme answer Official mark-scheme answer for 2(A)Official mark-scheme answer for 2(A)

Official answer for Question 2

Part (a)

Part (a)

Example Pascal

Max[8]

✓
PROCEDURE VendingMachine;
✓
VAR SnackType: CHAR;
✓
VAR Price, CoinValue, Total: INTEGER;
✓
BEGIN
✓
ReadLn(SnackType);
✓
CASE SnackType OF
✓
'A': Price: =
✓
20;
✓
'B': Price: =
✓
40;
✓
'C': Price: =
✓
50;
✓
'D': Price: =
✓
80;
✓
END;
✓
Total: = 0;
✓
REPEAT
✓
ReadLn(CoinValue);
✓
Total:= Total + CoinValue;
✓
UNTIL Total >= Price;
✓
ChangeDue:= Total – Price;
✓
IF ChangeDue > 0
✓
THEN
✓
OutputChange(ChangeDue)
✓
ELSE
✓
WriteLn("No Change");
✓
END;
✓
Mark as follows:
  • Procedure heading & ending
  • Local variables declared
  • With correct data types
  • Input SnackType
  • Correct case statement
  • Initialise Total
  • REPEAT loop
  • Input CoinValue and keep running total
  • Calculate change due
  • IF statement with procedure call to OutputChange()
  • Output “No change”
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – May/June 2016
✓
9691

Question 23

Mark scheme 9691_s16_ms_23.pdf →

Show text version of question

Question 2

Part (a)

Question 2

A vending machine dispenses four different types of snack: ‘A’, ‘B’, ‘C’ or ‘D’.

The vending machine accepts the following coins: 100 cents, 50 cents, 20 cents, 10 cents. If the user inserts coins to a greater value than the price of the chosen snack, the machine will give change.

The program controlling the machine is to take as input:

  • the type of snack chosen (‘A’, ‘B’, ‘C’ or ‘D’)
  • the value of each coin inserted

The program output is:

  • the message “No change”, if the money inserted was exactly the price of the snack

or

  • a message summarising the number of each coin value needed to give the correct change

Question 2 continues on page 4.

Question 4

Part (a)

Write program code to implement the flowchart opposite as the procedure VendingMachine.

Programming Language ...........................................................................................................

Code .........................................................................................................................................

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

...............................................................................................................................................[8]

Question 5

PROCEDURE VendingMachine

INPUT SnackType

CASE OF SnackType 'A' Price @20

'B' Price @40

'C' Price @50

'D' Price @80

Initialise Total

INPUT CoinValue

Total @Total + CoinValue

Is Total >= No Price?

Yes This is a ChangeDue @Total - Price procedure call

Yes OutputChange Is ChangeDue (ChangeDue) > 0? No OUTPUT "No Change"

ENDPROCEDURE

Question 6

Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Programming basics

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 9691_s16_qp_23.pdf

Keep practising this topic