0% found this document useful (0 votes)
59 views6 pages

Computer P4-QP Mock Exam

The document describes a programming assignment involving several tasks related to data structures and algorithms. Students are asked to write code to declare functions and classes, implement sorting and searching algorithms, and work with arrays and queues. Screenshots of test outputs are required.

Uploaded by

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

Computer P4-QP Mock Exam

The document describes a programming assignment involving several tasks related to data structures and algorithms. Students are asked to write code to declare functions and classes, implement sorting and searching algorithms, and work with arrays and queues. Screenshots of test outputs are required.

Uploaded by

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

CANDIDATE

NAME

CENTRE CANDIDATE
NAME NAME

COMPUTER SCIENCE 9618/42


Paper 4 Practical
MARCH 2024

2 hours 30 minutes
You will need: Candidate source files (listed on page 2)
evidence.doc

INSTRUCTIONS
● Carry out every instruction in each task.
● Save your work using the file names given in the task as and when instructed.
● You must not have access to either the internet or any email system during this examination.
● You must save your work in the evidence document as stated in the tasks. If work is not saved in the
evidence document, you will not receive marks for that task.
● You must use a high-level programming language from this list:
Java (console mode)
Python (console mode)
Visual Basic (console mode)
● A mark of zero will be awarded if a programming language other than those listed here is used.

INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].

This document has 07 pages. Any blank pages are indicated.


1 Study the following pseudocode for a recursive function.

The operator DIV returns the integer value after division e.g. 13 DIV 2 would give 6

(a) Write program code to declare the function Unknown(). [3]

(b) The main program needs to run all three of the following function calls and output the result
of each call:

(i) For each of the three function calls, the main program needs to:
• output the value of the two parameters
• call the function with those parameters
• output the return value.

Write the program code for the main program. [3]

(ii) Take a screenshot to show the output from part (b)(i). [2]

(c) Rewrite the function Unknown() as an iterative function, IterativeUnknown(). [7]

(d) The iterative function needs to be called three times with the same parameters as in
part (b).
(i) For each of the three function calls, the main program needs to:
• output the value of the two parameters
• call the iterative function with those parameters
• output the return value.
Amend the main program to perform these tasks. [1]

(ii) Take one or more screenshots to show the output of both functions for each set of
parameters. [1]

2 A programmer is designing a computer game that uses a set of cards.


Each card has a number and a colour. The cards are saved in the text file CardValues.txt
The program has a class named Card. The class has the following attributes and methods.

(a) The constructor takes the number and colour of the card as parameters and sets them to the
private attributes.

Write program code to declare the class Card and its constructor. Do not write any other
methods.

Use your programming language appropriate constructor.

All attributes should be private. If you are writing in Python, include attribute declarations
using comments. [5]

(b) The two get methods return the associated attribute.


Write program code for the get methods GetNumber() and GetColour(). [3]

(c) The text file CardValues.txt stores the data for 30 cards, in the order: number, colour.
For example, the first card in the text file:
1 is the number
red is the colour.

A 1D array of type Card is declared to store all the cards read in from CardValues.txt

Write the main program to:

• declare an array of type Card with 30 elements


• read in the data for the 30 cards from CardValues.txt and assign each to the
array.
[7]
(d) The program needs to allow all players (maximum of 5) to select 4 cards from the 30
available. A card can only be selected once, so the program needs to record which cards
have already been selected.

The function, ChooseCard():

• takes as input an integer to represent an array index from 1 to 30


• validates that the value is between 1 and 30 inclusive
• checks if the card is available (it has not already been selected)
• loops until an available card is selected
• returns the index of the card if it is available.

Amend the program to store which cards have already been selected and write program
code for the function ChooseCard(). [6]

(e) The main program needs to allow one player to select all their 4 cards.
(i) Amend the main program to:
• create an array, Player1, for player 1 of type Card
• ask player 1 to input 4 integers using the function from part 3(d)
• store the cards in Player1
• output the number and colour of the 4 cards in Player1.
[5]
(ii) Test your program with the following test data:

Test 1: 1 5 9 10

Test 2: 2 2 3 4 4 5

Take a screenshot to show the output. [1]


3 A 1-dimensional array, TheData, stores the following data:

(a) Write a program to declare the array as a local variable, and initialise the values with the
data given. Give the array the identifier TheData.
[2]

(b) Pseudocode for an insertion sort is shown below with three pieces of code missing.

In the program you wrote for part 1(a), write the procedure InsertionSort to perform an
insertion sort on the data in TheData. Pass the array you declared in part 1(a) by reference.
Follow the pseudocode given and insert the missing pieces of code in your program.
[7]

(c) Write a procedure to output all the contents of the array TheData to the screen. The
procedure should use iteration. Pass the array into the procedure as a parameter.
[3]

(d) (i) The main program needs to output the data before the data has been sorted, and
after the date has been sorted.

Use the subroutines you declared in part (b) and part (c).

Edit the main program so it:

• outputs all the data in TheData before sorting


• sorts the data in TheData
• outputs the data after sorting
• outputs appropriate headings to identify the outputs before and after sorting.
[3]

(ii) Test your program and take a screenshot to show the result. [2]

(e) (i) Write a function that:

• takes a whole number as input from the user


• if the number is in TheData outputs ‘found’ and returns true
• if the number is not in TheData outputs ‘not found’ and returns false.
[6]
(ii) Test the function using the number 8 as input, then the number 9 as input.

Take a screenshot of the results of each test, making sure the input is visible in the
screenshot.
[2]

4 QueueData is a queue that stores up to 20 string values. The queue has a start pointer to identify
the first element in the queue, and an end pointer to identify that last element in the queue.

(a) Write a program that defines QueueData and its pointers.


[2]

(b) Write program code for a function, Enqueue.


• The function should take an item to be added to the queue as a parameter.
• if the element was successfully added to the queue, the function should return TRUE
• if the queue was full and the item could not be added to the queue the function
should returns FALSE
• each time an item is successfully added, the function should updates the pointers.
[4]

You might also like