The text file IntegerData.txt stores 100 integer numbers between 1 and 100 inclusive. A program is required to read in this data and perform searching and sorting on the data.
- (a)Write program code to declare a global 1D array, DataArray, with space for 100 integer values.[2]
- (b)The procedure ReadFile() must read in the numbers from the text file and store each one in the array. Use appropriate exception handling. Write program code for the procedure ReadFile().[6]
- (c)The function FindValues() asks the user to enter a number to search for in the array. The number input must be a whole number between 1 and 100 inclusive. The function then returns the number of times the number input appears in the array. Write program code for the function FindValues().[7]
- (d)(i)Write program code to call ReadFile() and FindValues() from the main program. The return value from FindValues() must be output with an appropriate message.[3]
- (d)(ii)Test your program using the number 61 as input. Take a screenshot to show the output. Copy and paste the screenshot into part 1(d)(ii) in the evidence document.[1]
- (e)The procedure BubbleSort() needs to perform a bubble sort on the array and print the contents of the sorted array. Write program code for the procedure BubbleSort() and call it from the main program.[4]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2022). The mark or mark type is shown in brackets.
- 1 mark per point:
- [1] (global) 1D (Integer) array DataArray
- [1] 100 elements
- 1 mark per point:
- [1] Procedure ReadFile() header (and end where appropriate)
- [1] opening file IntegerData.txt (for read)
- [1] looping through the 100 elements // looping to end of file
- [1] reading each (and all) value from file and storing in array
- [1] closing file (in appropriate place)
- 1 mark per point:
- [1] Exception Handling (for opening the file, or for reading values from the file)...
- [1] ...with appropriate catch and output messages
- 1 mark per point:
- [1] Function FindValues()(and end where appropriate) and input of data to search for in the array
- [1] ...validation/casting(/storing as) of input as integer
- [1] .validation of input between 1 and 100 (inclusive)
- [1] looping through all 100 array elements...
- [1] .comparing input to each array element...
- [1] .initialising counter to 0 and then adding 1 each time it is found...
- [1] Returning the total
- 1 mark per point:
- [1] Calling ReadFile() and then FindValues() (in the main program)
- [1] storing/using return value from FindValues()
- [1] ...outputting return value with appropriate message
- [1] Screenshot showing 61 input and 2 output, e.g.
- 1 mark per point:
- [1] procedure declaration (and end where appropriate) and outputting array contents at end of procedure and calling procedure from main program
- [1] correct outer loop
- [1] correct inner loop ...
- [1] swapping all elements if in incorrect order
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 →