Skip to main content
A-LevelComputer ScienceProgramming9618/22 · Oct/Nov 2024 · Q818 Marks

A program is being developed to implement a game for up to six players. During the game, each player assembles a team of characters. At the start of the game there are 45 characters available. Each character has four attributes, as follows: | Attribute | Examples | Comment | |-----------|--------------------------|-------------------------------------------------------------------------------------------------------| | Player | 0, 1, 3 | The player the character is assigned to. | | Role | Builder, Teacher, Doctor | The job that the character will perform in the game. | | Name | Bill, Lee, Farah, Mo | The name of the character. Several characters may perform the same role, but they will each have a unique name. | | Level | 14, 23, 76 | The skill level of the character. An integer in the range 0 to 100 inclusive. | The programmer has defined a record type to define each character. The record type definition is shown in pseudocode as follows: TYPE CharacterType DECLARE Player : INTEGER DECLARE Role : STRING DECLARE Name : STRING DECLARE Level : INTEGER ENDTYPE The Player field indicates the player to which the character is assigned (1 to 6). The field value is 0 if the character is not assigned to any player. The programmer has defined a global array to store the character data as follows: DECLARE Character : ARRAY[1:45] OF CharacterType At the start of the game all record fields are initialised, and all Player field values are set to 0 The programmer has defined a program module as follows: | Module | Description | |----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Assign() | • called with two parameters: | Ο an integer representing a player | Ο a string representing a character role | • search the Character array for an unassigned character with the required role | • If found, assign the character to the given player and output a confirmation message, for example: | "Bill the Builder has been assigned to player 3" | • If no unassigned character with the required role is found, output a suitable message. |

  1. (a)Write pseudocode for module Assign().[7]
  2. (b)A new module will store the contents of the Character array in a text file. The module is defined as follows: | Module | Description | |--------|---------------------------------------------------------------------------------------------------------| | Save() | • form a string from each record with fields separated by the character '^' | • write each string to a separate line of the new file named SaveFile.txt | Complete the pseudocode for module Save(). PROCEDURE Save() ENDPROCEDURE[7]
  3. (c)The program is changed and the record type definition is modified as follows: TYPE CharacterType DECLARE Player : INTEGER DECLARE Role : STRING DECLARE Name : STRING DECLARE Level : INTEGER DECLARE Status : BOOLEAN ENDTYPE Describe how the additional Boolean field may be stored with the rest of the fields on one line of a text file.[2]
  4. (d)The save operation is to be extended so that multiple files may be saved as the game progresses. This will allow the user to restore the game from any saved position. The filename must reflect the sequence in which the files are saved. Describe a method that would allow multiple files to be saved and give an example of two consecutive filenames. Method Example[2]

Mark scheme

Marking points from the official mark scheme (Oct/Nov 2024). The mark or mark type is shown in brackets.

  1. [1] PROCEDURE Assign(ThisRole : STRING, ThisPlayer : INTEGER)
  2. [1] DECLARE Index : INTEGER
  3. [1] DECLARE Done : BOOLEAN
  4. [1] Done ← FALSE
  5. [1] Index ← 1
  6. [1] WHILE Index < 46 AND Done = FALSE
  7. [1] IF Character[Index].Player = 0 AND Character[Index].Role = ThisRole THEN
  8. [1] Character[Index].Player ← ThisPlayer
  9. [1] Done ← TRUE
  10. [1] ELSE Index ← Index + 1
  11. [1] ENDIF
  12. [1] ENDWHILE
  13. [1] IF Done = TRUE THEN OUTPUT Character[Index].Name, " the ", Character[Index].Role, " has been assigned to player ", ThisPlayer
  14. [1] ELSE OUTPUT "No characters with this role are available"
  15. [1] ENDIF
  16. [1] ENDPROCEDURE
  17. [1] PROCEDURE Save()
  18. [1] DECLARE Index : INTEGER
  19. [1] DECLARE Line : STRING
  20. [1] CONSTANT SEP = '^'
  21. [1] OPENFILE "SaveFile.txt" FOR WRITE
  22. [1] FOR Index ← 1 TO 45
  23. [1] Line ← NUM_TO_STR(Character[Index].Player) & SEP
  24. [1] Line ← Line & Character[Index].Role & SEP
  25. [1] Line ← Line & Character[Index].Name & SEP
  26. [1] Line ← Line & NUM_TO_STR(Character[Index].Level)
  27. [1] WRITEFILE "SaveFile.txt", Line
  28. [1] NEXT Index
  29. [1] CLOSEFILE "SaveFile.txt"
  30. [1] ENDPROCEDURE
  31. [1] Encode Status as a character / string
  32. [1] Append the '^' separator and the character/string
  33. [1] Method: Create a filename suffix which is incremented for each file save
  34. [1] Example: SaveFile01.txt, SaveFile02.txt

Write your answer and get it marked

On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.

Sign up free →

About this question

Topic
Programming, A-Level Computer Science (syllabus 9618). Structured question, 18 marks.
Source
A-Level Computer Science, Oct/Nov 2024 Paper 2 Variant 2, question 8.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep