Question 3
OCR Computer Science June 2024 Algorithms and problem solving (H046-02)AS9 marks
On the specification
- 2.2 Problem solving and programming2.3 Algorithms
Question text
3* Kofi and Zac both write a different pseudocode algorithm to read the data from a text file into an array. Kofi’s Algorithm Zac’s Algorithm fileName = "data.txt" function readData(fileName) fileToRead = openRead(fileName) array data[100] for x = 0 to 1000 x = 0 anyData = fileToRead.endOfFile() fileToRead = openRead(fileName) if NOT anyData then while NOT fileToRead.endOfFile() x = 1001 data[x] = fileToRead.readLine() else x = x + 1 dataValue = fileToRead.readLine() endwhile array[x] = dataValue return data endif endfunction next x fileToRead.close() The solution needs to be used in different programs. Each program will use a different text file where the number lines in the text file is unknown. Compare the suitability of each algorithm for the given problem. You should include the following in your answer: • the suitability of the programming techniques including the use of loops • how effectively the solution meets the requirements. [9]