CSC-9618 Mock 1 A2 Paper 4
CSC-9618 Mock 1 A2 Paper 4
20 3 4 8 12 99 4 26 4
(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.
(b) Pseudocode for an insertion sort is shown below with three pieces of code missing.
PROCEDURE InsertionSort(TheData())
FOR Count FirstElement TO ………………………………………………
DataToInsert TheData(i)
Inserted 0
NextValue Count - 1
WHILE (NextValue >= 0 AND ……………………………………………… <> 1)
IF (DataToInsert < TheData(NextValue)) THEN
TheData(NextValue + 1) TheData(NextValue)
NextValue NextValue - 1
TheData(NextValue + 1) ………………………………………………
ELSE
Inserted 1
ENDIF
ENDWHILE
NEXT
ENDPROCEDURE
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.
[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).
(ii) Test your program and take a screenshot to show the result.
(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.
(a) Write the program code for the class, HiddenBox. Declare the properties as private.
If you are using Python, add a comment for each property to give its identifier and data
type.
• takes the box name, creator, date hidden and game location as parameters
• sets the box to be inactive
• initialises all the array elements as empty.
Edit your program from part 2(a) and write the constructor for HiddenBox.
Edit your program and write the getter methods GetBoxName and GetGameLocation in the
class HiddenBox.
(d) (i) The main program declares a 1D array named TheBoxes of type HiddenBox.
• takes the Name, Creator, Date Hidden and Game Location of the box as input
• creates an instance of HiddenBox and appends it to the end of TheBoxes
(iii) After declaring the array, the main program calls NewBox.
• PuzzleText as String
• Solution as String
The constructor for PuzzleBox extends the constructor from HiddenBox to also take the
values for PuzzleText and Solution.
If you are using Python, add a comment for each property to give its identifier and data
type.
[3]
3 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.
• all of the data is successfully read into the queue, the function returns the value 1
• the queue is full and not all the data could be inserted into the queue, the function returns
the value 2
• the text file could not be found, the function returns the value –1.
Edit the main program to call ReadFile and output the appropriate message.
• DataToAdd.txt
• SecondData.txt
• ThirdData.txt (this file does not need to be created)
Take a screenshot to show the result from each test. Make sure you show the name of
the text file being input in your screenshots.