P4 Linearsearch
P4 Linearsearch
2 A program stores the following ten integers in a 1D array with the identifier arrayData.
10 5 6 7 1 12 13 15 21 8
Copy and paste the program code into part 2(a) in the evidence document.
[2]
(b) (i) A function, linearSearch(), takes an integer as a parameter and performs a linear
search on arrayData to find the parameter value. It returns True if it was found and
False if it was not found.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[6]
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[4]
(iii) Test your program with one value that is in the array and one value that is not in the
array.
Copy and paste the screenshots into part 2(b)(iii) in the evidence document.
[2]
Make sure that your name, centre number and candidate number will appear on every page of this
document. This document must contain your answers to each question.
One source file is used to answer Question 1 and two source files are used to answer Question 3.
The files are called Data.txt, AnimalData.txt and ColourData.txt
1 A program reads data from a file and searches for specific data.
(a) The main program needs to read 25 integer data items from the text file Data.txt into a
local 1D array, DataArray
Copy and paste the program code into part 1(a)(i) in the evidence document.
[1]
(ii) Amend the main program to read the contents of Data.txt into DataArray
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[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.
10 4 5 13 25
Copy and paste the program code into part 1(b)(i) in the evidence document.
[3]
(ii) Amend the main program to output the contents of DataArray using the procedure
PrintArray()
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[1]
Copy and paste the screenshot into part 1(b)(iii) in the evidence document.
[1]
Copy and paste the program code into part 1(c) in the evidence document.
[3]
• 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.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[4]
Copy and paste the screenshot into part 1(d)(ii) in the evidence document.
[1]