0% found this document useful (0 votes)
33 views8 pages

Paper 3

The document provides instructions for a candidate to complete programming questions and save their responses in an evidence document. The candidate is asked to write code to: 1) Declare arrays and pointers to implement a stack data structure. 2) Define a QuestionClass with attributes, constructor, and getters. 3) Sort an array using bubble sort, count even numbers in the array, and output results. The candidate is instructed to save their code for each part and copy it into the specified sections of the evidence document. Screenshots of output are also requested for some parts.

Uploaded by

sami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views8 pages

Paper 3

The document provides instructions for a candidate to complete programming questions and save their responses in an evidence document. The candidate is asked to write code to: 1) Declare arrays and pointers to implement a stack data structure. 2) Define a QuestionClass with attributes, constructor, and getters. 3) Sort an array using bubble sort, count even numbers in the array, and output results. The candidate is instructed to save their code for each part and copy it into the specified sections of the evidence document. Screenshots of output are also requested for some parts.

Uploaded by

sami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Open the document evidence.doc.

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

Save your program as question1.

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.

Save your program.

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().

Save your program.

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 added 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.

Save your program.

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

Take a screenshot to show the output.

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().

Save your program.

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.

If you are writing in Python, include attribute declarations using comments.

Use your programming language’s constructor method.


Save your program in a new file with name Question2

Copy and paste the program code into part 2(a) in the evidence document.

[6]

(b)

Save your program.

Copy and paste the program code into part 2(b) in the evidence document.

[4]

(c)

Save your program.

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

[4]
(d)

Save your program.

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:

• declare the global 1D array, numData, with 10 elements


• initialise numData in the main program using the data values shown

Save your program as question3.

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.

Save your program.

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

(ii) Test your program by calling the function BubbleSort().

Take a screenshot to show the result

Save your program.

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]

(iii) Take the screenshot of the output of (ii)


Save your program.

Copy and paste the screenshots into part 3(c)(iii) in the evidence document.

[1]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy