Skip to main content
A-LevelComputer ScienceProgramming9618/43 · Oct/Nov 2024 · Q122 Marks

A program sorts string data using different sorting methods. One source file is used to answer Question 1. The file is called Data.txt

  1. (a)The text file Data.txt stores string data items. Each data item is on a new line in the text file. The function ReadData(): • has a local array of strings that can store 45 items • reads each line of data and stores it in the array • returns the array. Write program code for the function ReadData(). Save your program as Question1_N24. Copy and paste the program code into part 1(a) in the evidence document.[6]
  2. (b)(i)The function FormatArray() takes an array of strings as a parameter. It concatenates the contents of the array into one string with a space between each array element. The function returns the concatenated string. Write program code for FormatArray(). Save your program. Copy and paste the program code into part 1(b)(i) in the evidence document.[2]
  3. (b)(ii)The main program: • calls ReadData() and stores the returned array • calls FormatArray() with the returned array and outputs the returned string. Write program code for the main program. Save your program. Copy and paste the program code into part 1(b)(ii) in the evidence document.[3]
  4. (b)(iii)Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 1(b)(iii) in the evidence document.[1]
  5. (c)The function CompareStrings(): • takes two strings as parameters • compares each string, one character at a time, to identify which string comes first alphabetically. If the first two characters are the same, the second character of each string is compared. This continues until the two characters are different. The function: • returns 1 if the first parameter comes before the second alphabetically • returns 2 if the second parameter comes before the first alphabetically. Write program code for CompareStrings(). Assume that all strings are in lower case. Assume that a difference between two strings will always be identified before the end of one string is reached. Do not use an in-built string comparison function. The strings must be compared one character at a time. Save your program. Copy and paste the program code into part 1(c) in the evidence document.[4]
  6. (d)(i)The function Bubble() takes an array of strings as a parameter and sorts the data into ascending alphabetical order, using a bubble sort. The bubble sort uses CompareStrings() to compare each string. The function returns the sorted list. Write program code for Bubble(). Save your program. Copy and paste the program code into part 1(d)(i) in the evidence document.[3]
  7. (d)(ii)Write program code to amend the main program to: • call Bubble() with the unsorted array as a parameter • call FormatArray() with the sorted array and output the returned string. Save your program. Copy and paste the program code into part 1(d)(ii) in the evidence document.[2]
  8. (d)(iii)Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 1(d)(iii) in the evidence document.[1]

Mark scheme

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

  1. [1] (a) Function declaration (and close where appropriate)
  2. [1] (a) Declaration/use of an array (with space/initialised with 45 spaces/strings)
  3. [1] (a) Opening the file Data.txt for read and closing in an appropriate place
  4. [1] (a) Looping through all file contents/Looping 45 times and reading each line ...
  5. [1] (a) storing all items from file into array
  6. [1] (a) Returning the populated array
  7. [1] (a) Exception handling with suitable try, catch and output
  8. [1] (b)(i) Function header (and end where appropriate) taking (min) one parameter
  9. [1] (b)(i) Looping through each parameter array element, concatenating with space and returning
  10. [1] (b)(ii) Calling ReadData() and storing returned array ...
  11. [1] (b)(ii) ... calling FormatArray() with returned array
  12. [1] (b)(ii) Outputting return value from FormatArray()
  13. [1] (b)(iii) 1 mark for output showing all colours in one string
  14. [1] (c) Function header (and close where appropriate) taking (min) two parameters and returns a value in all cases
  15. [1] (c) Looping through each character in each string parameter ...
  16. [1] (c) ... return 1 when first parameter < second
  17. [1] (c) ... return 2 when first parameter > second
  18. [1] (d)(i) Bubble sort function header taking array parameter and returns sorted array in all cases
  19. [1] (d)(i) Comparing strings using CompareStrings() and correctly swapping values when needed
  20. [1] (d)(i) Correct bubble sort that sorts the data correctly
  21. [1] (d)(ii) Calling Bubble () with array as parameter and using/storing return value
  22. [1] (d)(ii) Calling FormatArray() with return value from Bubble () and outputting return value
  23. [1] (d)(iii) 1 mark for sorted data

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, 22 marks.
Source
A-Level Computer Science, Oct/Nov 2024 Paper 4 Variant 3, question 1.

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