Past-paper question · 2023 May-June · Paper 41 · Q3(c)

Question 3(c) 2023 · May-June · Paper 41 · 5 marks

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

Official answer for Question 3

Part (c)

Question 1

mark each to max 5

Question 5

✓
Procedure heading (and close where appropriate) and outputting the colour and animal using PopColour() and
✓
PopAnimal() (only if both are successfully popped)
✓
Checking if no colour and outputting "No colour" …
✓
….pushing the removed animal back onto the stack
✓
Checking if no animal and outputting "No animal" …
✓
…pushing the removed colour back onto the stack
✓
Example program code:
✓
Java
✓
public static void OutputItem(){
✓
String ColourReturned = PopColour();
✓
String AnimalReturned = PopAnimal();
✓
if(ColourReturned.equals("")){
✓
System.out.println("No colour");
✓
PushAnimal(AnimalReturned);
✓
}else{
✓
if(AnimalReturned.equals("")){
✓
System.out.println("No animal");
✓
PushColour(ColourReturned);
✓
}else{
✓
System.out.println("A " + ColourReturned + " " + AnimalReturned);
✓
}
✓
}
✓
}
✓
VB.NET
✓
Sub OutputItem()
✓
Dim ColourReturned As String = PopColour()
✓
Dim Animalreturned As String = PopAnimal()
✓
If ColourReturned = "" Then
✓
Console.WriteLine("No colour")
✓
PushAnimal(AnimalReturned)
✓
9618/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2023
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s23_ms_41.pdf →

Show text version of question

Question 3

Part (c)

Question 3

A program implements two stacks using 1D arrays. One stack stores the names of colours. One

stack stores the names of animals.

Part (c)

The procedure OutputItem():

  • pops the next item from both Animal and Colour
  • outputs the colour and animal on one line, for example "black horse"

If there is no data in Colour:

  • the animal is pushed back onto Animal
  • "No colour" is output.

If there is no data in Animal:

  • the colour is pushed back onto Colour
  • "No animal" is output.

Write program code for the procedure OutputItem()

Save your program.

Copy and paste the program code into part 3(c) in the evidence document.

[5]
Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Constructs

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 9618_s23_qp_41.pdf

Keep practising this topic