Paper 3
Paper 3
Make sure that your name, centre number and candidate number will appear on every page of
this document. This document will contain your answers to each question.
Save this evidence document in your work area as:
evidence_ followed by your centre number_candidate number, for example:
evidence_zz999_9999
A class declaration can be used to declare a record.
A list is an alternative to an array.
1) A program needs to use a stack data structure. The stack can store up to 10 integer elements
A 1D array StackData is used to store the stack globally. The global variable StackPointer points to the next
available space in the stack and is initialised to 0.
(a) Write program code to declare the array and pointer as global data structures. Initialise the pointer to 0
Copy and paste the program code into part 1(a) in the evidence document.
[3]
(b) Write a procedure to output all 10 elements in the stack and the value of StackPointer.
Copy and paste the program code into part 1(b) in the evidence document.
[3]
(c) The function Push() takes an integer parameter and returns FALSE if the stack is full. If the stack is not
full, it puts the parameter value on the stack, updates the relevant pointer and returns TRUE.
Write program code for the function Push().
Copy and paste the program code into part 1(c) in the evidence document.
[6]
(d) (i) Edit the main program to test the Push() function. The main program needs to:
• allow the user to enter 11 numbers and attempt to add these to the stack
• output an appropriate message when a number is not added to the stack if it is full
• output the contents of the stack after attempting to add all 11 numbers.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[5]
(ii) Test your program from part 1(d)(i) with the following 11 inputs:
11 12 13 14 15 16 17 18 19 20 21
Copy and paste the screenshots into part 1(d)(ii) in the evidence document.
[1]
(e) The function Pop() returns −1 if the stack is empty. If the stack is not empty, it returns the element at
the top of the stack and updates the relevant pointer.
(i) Write program code for the function Pop().
Copy and paste the program code into part 1(e)(i) in the evidence document.
[5]
(ii) After the code you wrote in the main program for part 1(d)(i), add program code to:
• remove two elements from the stack using Pop()
• output the updated contents of the stack.
Test your program and take a screenshot to show the output.
Copy and paste the screenshots into part 1(e)(ii) in the evidence document.
[2]
2
(a) Write Program Code to define the class QuestionClass. You are required to write the
code for the attribute declarations, constructor and the getters.
Copy and paste the program code into part 2(a) in the evidence document.
[6]
(b)
Copy and paste the program code into part 2(b) in the evidence document.
[4]
(c)
Copy and paste the program code into part 2(c) in the evidence document.
[4]
(d)
Copy and paste the program code into part 2(d) in the evidence document.
[5]
(3) 1 A program stores the following 10 numbers in a 1D array with identifier numData.
10 4 23 45 12 8 21 11 3 1
(a) Write program code for a new program to:
Copy and paste the program code into part 1(a) in the evidence document.
[2]
(b) (i) A function BubbleSort() takes numData as by reference parammeter and sort the elements in
the numData array in ascending order.
Write program code for the function BubbleSort() and make sure the code is efficient.
Copy and paste the program code into part 3(b)(i) in the evidence document.
Copy and paste the screenshots into part 3(b)(ii) in the evidence document.
[1]
(c) The Function EvenNumber() takes the array as a Parameter and it returns count of how
numbers are even.
(i) Write program code for the function EvenNumber().
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[3]
(ii) Pass the numData in the Function EvenNumber() and find out how many even numbers
are there in numData and print it with suitable message.
Save your program.
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[3]
Copy and paste the screenshots into part 3(c)(iii) in the evidence document.
[1]