A Level Computer Science 9618 Paper 42, Oct/Nov 2024

Question paper and mark scheme75 marks3 questions

Solve it on ExamPal

Practise

Untimed. Write on the paper and check as you go.

Start

Exam

Timed, with a clock you set, like sitting the real paper.

Start

Opens full screen.

Papers open in

Opening the question paper

Read as textThe questions and the mark scheme as plain text. Easier to read on a phone.

Question paper

9618/42 · Oct/Nov 2024

Download PDF
1

A computer game is designed for users to select characters. Each character can take part in a group of events. Each group has five events. There are four types of event: jump, swim, run, drive. The program is written using object-oriented programming.

a(i)

The class EventItem stores data about the events. EventItem EventName : STRING stores the name of the event Type : STRING stores the type of event, either: jump, swim, run or drive Difficulty : INTEGER stores the difficulty of the event from 1 (easiest) to 5 (hardest) Constructor() initialises EventName, Type and Difficulty to its parameter values GetName() returns the name of the event GetDifficulty() returns the difficulty of the event GetEventType() returns the type of event Write program code to declare the class EventItem and its constructor. Do not declare the other methods. Use your programming language’s appropriate constructor. All attributes must be private. If you are writing in Python, include attribute declarations, using comments. Save your program as Question1_N24. Copy and paste the program code into part 1(a)(i) in the evidence document.

[4]
a(ii)

The get methods GetName(), GetDifficulty() and GetEventType() each return the relevant attribute. Write program code for the three get methods. Save your program. Copy and paste the program code into part 1(a)(ii) in the evidence document.

[3]
b(i)

The array Group stores five objects of type EventItem. Write program code to declare Group local to the main program. Save your program. Copy and paste the program code into part 1(b)(i) in the evidence document.

[1]
b(ii)

One group has the following events: Event name | Event type | Event difficulty Bridge | jump | 3 Water wade | swim | 4 100 mile run | run | 5 Gridlock | drive | 2 Wall on wall | jump | 4 Write program code to create an instance of EventItem for each of the five events, and store them in Group. Save your program. Copy and paste the program code into part 1(b)(ii) in the evidence document.

[3]
c

The class Character stores data about the characters in the game. Each character has a skill level for each type of event. The skill level is an integer between 1 and 5 inclusive. Skill level 1 is the lowest skill level, and skill level 5 is the highest skill level. Character CharacterName : STRING stores the name of the character Jump : INTEGER stores the character’s skill level at events of type jump Swim : INTEGER stores the character’s skill level at events of type swim Run : INTEGER stores the character’s skill level at events of type run Drive : INTEGER stores the character’s skill level at events of type drive Constructor() initialises CharacterName, Jump, Swim, Run and Drive to its parameter values GetName() returns the name of the character CalculateScore() takes the type of event and difficulty as parameters. Calculates and returns the chance of the character completing the event Write program code to declare the class Character, its constructor and get method. Use your programming language’s appropriate constructor. All attributes must be private. If you are writing in Python, include attribute declarations, using comments. Save your program. Copy and paste the program code into part 1(c) in the evidence document.

[4]
d

The method CalculateScore() in the Character class calculates and returns the percentage chance of a character completing an event. When a character’s skill level is greater than or equal to the difficulty of that event, the percentage chance of completing the event is 100%. When a character’s skill level is less than the difficulty of that event, the character’s skill level is subtracted from the difficulty of that event. This difference is used to identify the percentage chance of success using this table: Difference | Percentage chance of success 1 | 80 2 | 60 3 | 40 4 | 20 For example: • A character has a skill level of 3 for events of type run. • An event of type run has a difficulty level of 5 • The character’s skill level is less than the difficulty, therefore the difference is calculated. • The difference is the character’s skill level subtracted from the event difficulty, 5 – 3 = 2 • The difference is 2, therefore the percentage chance of succeeding is 60% Write program code for the method CalculateScore() to: • take the type of event and difficulty as parameters • calculate the percentage chance of the character completing the event • return the percentage chance of completing the event as an integer number, for example 60 Save your program. Copy and paste the program code into part 1(d) in the evidence document.

[4]
e(i)

Two characters are attempting each event in the group you created in part 1(b). One character has the name Tarz and the skill levels: Jump 5 Swim 3 Run 5 Drive 1 The second character has the name Geni and the skill levels: Jump 2 Swim 2 Run 3 Drive 4 Each Character object is stored in a variable. Amend the main program to declare and create an instance of a Character object for Tarz and for Geni. Save your program. Copy and paste the program code into part 1(e)(i) in the evidence document.

[2]
e(ii)

Both characters Tarz and Geni take part in each event in the group you created in part 1(b). These steps are repeated for all five events: • The percentage chance of each character completing the event is calculated and compared. • The character with the highest percentage chance of completing the event gets 1 point. Their character name is output together with a message telling them they have won that event. • If both characters have the same percentage chance of completing the event, the scores do not change, and a message is output stating that the event is a draw. When the total score for each character has been calculated, the name of the character with the highest score is output stating they have won and the number of points they have. If both characters have the same number of points, a message is output telling them the group is a draw. Amend the main program to: • calculate the score for each character in each event • output the name of the character that wins each event or that the event is a draw • output the name of the character that has the most points for the group or that the group is a draw. Save your program. Copy and paste the program code into part 1(e)(ii) in the evidence document.

[7]
e(iii)

Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 1(e)(iii) in the evidence document.

[1]
2

A linear queue data structure is designed using a record structure. The record structure Queue has the following fields: • QueueArray, a 1D array of up to 100 integer values • Headpointer, a variable that stores the index of the first data item in QueueArray • Tailpointer, a variable that stores the index of the next free location in QueueArray.

a

Write program code to declare the record structure Queue and its fields. If your programming language does not support record structures, a class can be declared instead. If you are writing in Python, use comments to declare the appropriate data types. Save your program as Question2_N24. Copy and paste the program code into part 2(a) in the evidence document.

[3]
b

The main program creates a new Queue record with the identifier TheQueue. The head pointer is initialised to –1. The tail pointer is initialised to 0. Each element in the array is initialised with –1. Write program code for the main program. Save your program. Copy and paste the program code into part 2(b) in the evidence document.

[3]
c

The pseudocode function Enqueue() inserts an integer value into the queue. The function is incomplete. There are three incomplete statements. FUNCTION Enqueue(BYREF AQueue : Queue, BYVAL TheData : INTEGER) RETURNS INTEGER IF AQueue.Headpointer = -1 THEN AQueue.QueueArray[AQueue.Tailpointer] ← ........................................ AQueue.Headpointer ← 0 AQueue.Tailpointer ← AQueue.Tailpointer + 1 RETURN 1 ELSE IF AQueue.Tailpointer > ........................................ THEN RETURN -1 ELSE AQueue.QueueArray[AQueue.Tailpointer] ← TheData AQueue.Tailpointer ← AQueue.Tailpointer ........................................ RETURN 1 ENDIF ENDIF ENDFUNCTION Write program code for Enqueue(). Save your program. Copy and paste the program code into part 2(c) in the evidence document.

[5]
d

The function ReturnAllData() accesses TheQueue. It concatenates all the integer values that have been inserted into the queue’s array, starting from the value stored at HeadPointer, with a space between each integer value. The string of concatenated values is returned. None of the integer values are removed from the queue. Write program code for ReturnAllData(). Save your program. Copy and paste the program code into part 2(d) in the evidence document.

[3]
e(i)

The main program asks the user to enter 10 integers with values of 0 or greater. It reads each input repeatedly until a valid number is entered. All 10 valid inputs are added to the queue, using Enqueue(). If the value returned from Enqueue() is –1, a message is output to state that the queue is full, otherwise a message is output to state that the item has been added to the queue. The function ReturnAllData() is called once all 10 integers have been entered and the return value from the function call is output. Amend the main program to perform these actions. Save your program. Copy and paste the program code into part 2(e)(i) in the evidence document.

[5]
e(ii)

Test your program with the following inputs in the order given: 10 9 –1 8 7 6 5 4 3 2 1 Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 2(e)(ii) in the evidence document.

[2]
f

The function Dequeue() accesses TheQueue. The function returns –1 if the queue is empty. If the queue is not empty, the function returns the next item in the queue and updates the relevant pointer(s). The data is not replaced or deleted from the queue. Write program code for Dequeue(). Save your program. Copy and paste the program code into part 2(f) in the evidence document.

[4]
g(i)

The main program calls Dequeue() twice, and each time it either outputs ‘Queue empty’ if there is no data in the queue or outputs the return value. The main program then calls ReturnAllData() a second time. Amend the main program. Save your program. Copy and paste the program code into part 2(g)(i) in the evidence document.

[3]
g(ii)

Test your program with the following inputs in the order given: 10 9 8 7 6 5 4 3 2 1 Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 2(g)(ii) in the evidence document.

[1]
3

The text file HighScoreTable.txt stores the top seven player scores for a game. The data in the file is stored in the order: Player ID Game level Score Each item of data is stored on a new line. For example, the first set of data in the file is: Player ID: GHEH Game level: 3 Score: 10

a

The data about the players and their scores is stored in a 2D array of strings with the identifier HighScores. The first dimension of the array has seven elements: one for each player. The second dimension of the array has three elements: one for the player ID, one for the game level and one for the score. All data is stored in the array as strings. HighScores is declared local to the main program, and all elements are initialised to an empty string, for example "". Write program code to declare and initialise HighScores. Save your program as Question3_N24. Copy and paste the program code into part 3(a) in the evidence document.

[2]
b

The function ReadData() reads the data from HighScoreTable.txt and stores the data in a 2D array. The function returns the 2D array. The function uses exception handling when opening and reading data from the file. Write program code for ReadData(). Save your program. Copy and paste the program code into part 3(b) in the evidence document.

[5]
c

The procedure OutputHighScores() takes a 2D array as a parameter. It outputs each player’s ID, level and score in the order they are in the array. The outputs are in the format: GHEH reached level 3 with a score of 10 Write program code for OutputHighScores(). Save your program. Copy and paste the program code into part 3(c) in the evidence document.

[2]
d

The scores in HighScoreTable.txt are not in order. The player scores are first sorted by the game level they reached. For example, all players that reached level 5 are higher in the high score table than players that reached level 4. The players that reached the same level are then sorted in descending order of score. An example sorted high score table is: Position | Player ID | Game level | Score 1 | GFED | 5 | 25 2 | HJKM | 4 | 21 3 | RERR | 4 | 19 4 | TTYU | 4 | 15 5 | WSVG | 3 | 20 6 | PPTR | 3 | 15 7 | SNQT | 2 | 10 The function SortScores() uses a bubble sort to sort the data as described and returns the sorted array. Write program code for SortScores(). Save your program. Copy and paste the program code into part 3(d) in the evidence document.

[4]
e(i)

Amend the main program to implement these steps in the order given: • call ReadData() and store the returned array in HighScores • output "Before" • call OutputHighScores() with HighScores as a parameter • call SortScores() and store the returned array in HighScores • output "After" • call OutputHighScores() with HighScores as a parameter. Save your program. Copy and paste the program code into part 3(e)(i) in the evidence document.

[2]
e(ii)

Test your program Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 3(e)(ii) in the evidence document.

[2]

Mark scheme

9618/42 · Oct/Nov 2024

Download PDF

1a(i) · 4 marks

  • 1 mark

    Class EventItem header (and end where appropriate)

  • 1 mark

    3 private attributes with suitable data types

  • 1 mark

    Constructor header (and end where appropriate) with 3 (min) parameters within class declaration …

  • 1 mark

    … assigning parameters to attributes within constructor

1a(ii) · 3 marks

  • 1 mark

    1 get method with no parameter …

  • 1 mark

    … return correct attribute (without changing)

  • 1 mark

    Remaining 2 correct get methods returning the attributes

1b(i) · 1 mark

  • 1 mark

    1D array name Group with (min 5 elements and of type EventItem)

1b(ii) · 3 marks

  • 1 mark

    Any 1 instance of EventItem declared with values passed in correct order …

  • 1 mark

    … stored in the array Group …

  • 1 mark

    … remaining 4 correctly instantiated and stored in Group

1c · 4 marks

  • 1 mark

    Class Character declared (and end where appropriate)

  • 1 mark

    5 private attributes with correct data types

  • 1 mark

    Constructor header (and end) taking (min) 5 parameters and parameters assigned to attributes

  • 1 mark

    Get method (with no parameter) returning name attribute

1d · 4 marks

  • 1 mark

    Method header CalculateScore (and end where appropriate) taking (min) 2 parameters

  • 1 mark

    Selection on the type of event using the parameter

  • 1 mark

    … if skill value is  = difficulty return 100

  • 1 mark

    …otherwise subtracting skill value from the difficulty and return correct value 80 (diff 1), 60 (diff 2), 40 (diff 3) and 20 (diff 4)

1e(i) · 2 marks

  • 1 mark

    Creating one new instance of Character with correct name and values for 1 character and storing

  • 1 mark

    2nd correct instance of Character and storing

1e(ii) · 7 marks

  • 1 mark

    Looping through each event in Group (or checking each of the 5 events manually)

  • 1 mark

    Using CalculateScore() for each Character object with parameters of type and difficulty

  • 1 mark

    …comparing the return values from the two function calls …

  • 1 mark

    …incrementing points for winning player and outputting their name and message stating they have won for each event.

  • 1 mark

    …outputting message if it's a draw.

  • 1 mark

    Comparing the total points for each character after all events checked and outputting name of player with most points (and their points) and outputting message if it's a draw

  • 1 mark

    Using get methods correctly throughout

1e(iii) · 1 mark

  • 1 mark

    1 mark for output showing the correct winner for each event, the final winner’s name (and their points)

2a · 3 marks

  • 1 mark

    Record structure or class with constructor Queue (and end where appropriate) …

  • 1 mark

    … containing a 1D array of (100) integers QueueArray

  • 1 mark

    … containing HeadPointer and TailPointer as integers

2b · 3 marks

  • 1 mark

    New Queue record/object created/instance of class

  • 1 mark

    Queue field/attribute head pointer initialised to –1, tail pointer to 0

  • 1 mark

    All 100 array field/attribute elements initialised with –1

2c · 5 marks

  • 1 mark

    Completed statement (1)

  • 1 mark

    Completed statement (2)

  • 1 mark

    Completed statement (3)

  • 1 mark

    Correct values returned in correct places

  • 1 mark

    Function header taking (at least) one parameter and the rest of function correct and using the record/class data structure accurately.

2d · 3 marks

  • 1 mark

    Function header (and end) iterating through each element in the queue

  • 1 mark

    Starting at HeadPointer and incrementing until TailPointer – 1 …

  • 1 mark

    … concatenating and returning all integer values with a space between

2e(i) · 5 marks

  • 1 mark

    Taking only 10 inputs in loop/one at a time

  • 1 mark

    Calling Enqueue() with each input (min) and storing/using return value …

  • 1 mark

    … only calling Enqueue() once when each input is an integer  = 0. Do not award if this validation stops 10 valid inputs being enqueued.

  • 1 mark

    Outputting message if each item is inserted and outputting a message if queue is full

  • 1 mark

    Calling ReturnAllData() and outputting return value at the end

2e(ii) · 2 marks

  • 1 mark

    All values input and 10 messages ‘Inserted’ (i.e. –1 is not inserted)

  • 1 mark

    Screenshot show 10 9 8 7 6 5 4 3 2 1 on one line with a space between each number

2f · 4 marks

  • 1 mark

    Function Dequeue() (head and close), returning a value in all cases

  • 1 mark

    Checking if empty and returning –1

  • 1 mark

    Returning item at HeadPointer without deleting/changing it

  • 1 mark

    Incrementing HeadPointer

2g(i) · 3 marks

  • 1 mark

    Calls Dequeue() twice and stores/uses return value

  • 1 mark

    Outputs "Queue empty" when each return values is –1 and outputs return value otherwise

  • 1 mark

    Calls ReturnAllData() at the end

2g(ii) · 1 mark

  • 1 mark

    Screenshot shows the input of 10 9 8 7 6 5 4 3 2 1 Output for 10 returned Output for 9 is returned

3a · 2 marks

  • 1 mark

    HighScores created as 2D array, (of strings) with (min) 7  3 elements (local to main) …

  • 1 mark

    … all elements initialised to empty string ("")

3b · 5 marks

  • 1 mark

    Function header (and end where appropriate) that returns populated array

  • 1 mark

    Opening text file to read and closing the file in an appropriate place

  • 1 mark

    Looping through 7 players/to EOF/21 times …

  • 1 mark

    … reading in each group of 3 data items and storing each in separate element in 2D array for each player

  • 1 mark

    Exception handling with all file handling within the try, appropriate catch and an output

3c · 2 marks

  • 1 mark

    Procedure (header and end) taking (min) 1 parameter (2D array), looping through each of the first dimension in array …

  • 1 mark

    … outputting all data in correct format

3d · 4 marks

  • 1 mark

    Function header (and end taking array as parameter) returning sorted array.

  • 1 mark

    Comparing the levels and swapping all dimensions when in incorrect order

  • 1 mark

    Comparing scores when levels are the same and swapping all dimensions when in incorrect order

  • 1 mark

    Correct loops and comparisons to put data in correct order

3e(i) · 2 marks

  • 1 mark

    Code statements in order: HighScores = ReadData() HighScores = SortScores(HighScores) // HighScores = SortScores()

  • 1 mark

    Code statements in order: OUTPUT "Before" OutputHighScores(HighScores) unsorted OUTPUT "After" OutputHighScores(HighScores) sorted

3e(ii) · 2 marks

  • 1 mark

    Output showing ‘Before’ and players and scores in correct format before sorting

  • 1 mark

    Output showing ‘After’ players and scores in correct order and format after sorting

Questions

  1. 1
    Question 129 marks
    Mark scheme ›
  2. 2
    Question 229 marks
    Mark scheme ›
  3. 3
    Question 317 marks
    Mark scheme ›

More 9618 papers

Other papers from Oct/Nov 2024

Solve it on ExamPalStart