A program reads data from a file and searches for specific data.
- (a)(i)Write program code to declare the local array DataArray[1]
- (a)(ii)Amend the main program to read the contents of Data.txt into DataArray[4]
- (b)(i)The procedure PrintArray() takes an integer array as a parameter and outputs the contents of the array in the order they are stored. The items are printed on the same line, for example: 10 4 5 13 25 Write program code for the procedure PrintArray()[3]
- (b)(ii)Amend the main program to output the contents of DataArray using the procedure PrintArray()[1]
- (b)(iii)Test your program. Take a screenshot of the output.[1]
- (c)The function LinearSearch(): • takes an integer array and integer search value as parameters • counts and returns the number of times the search value is found in the array. Write program code for the function LinearSearch()[3]
- (d)(i)Amend the main program to: • prompt the user to input a whole number between 0 and 100 inclusive • read and validate the input from the user • call LinearSearch() with DataArray and the validated input value • output the result in the format: The number 7 is found 2 times. Write program code for the main program.[4]
- (d)(ii)Test your program by inputting the number 12. Take a screenshot of the output.[1]
Mark scheme
Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.
- [1] 1 mark for • 1D array with name DataArray (with 25 elements of type Integer)
- [4] 1 mark each to max 4 • Opening file Data.txt to read • Looping through all the 25/EOF • reading each line and storing/appending into array • Exception handling with appropriate output • Closing the file (in an appropriate place)
- [3] 1 mark each • Procedure header (and close where appropriate) with (at least) one (integer array) parameter • Outputting all (25) array elements • ...on one line
- [1] 1 mark for calling PrintArray with the array as a parameter
- [1] 1 mark for screenshot e.g. 10 4 5 13 25 31 4 66 12 5 0 11 15 20 21 12 33 49 12 12 7 7 4 22 0
- [3] 1 mark each • Function header (and close where appropriate) taking array and search value as parameters • Looping through each array element and keeping count of the number of times the parameter appears • Returning the calculated count value
- [4] 1 mark each • Prompt and reading input • .with validation for whole number between 0 and 100 inclusive • Calling LinearSearch() with array and valid data input and storing/using return value • Output of the message with return value
- [1] 1 mark for screenshot e.g. 10 4 5 13 25 31 4 66 12 5 0 11 15 20 21 12 33 49 12 12 7 7 4 22 Enter a number to find 12 The number 12 is found 4 times
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 →