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
- (a)Write program code for a new program to: • declare the global 1D array, arrayData, with ten elements • initialise arrayData in the main program using the data values shown. Save your program as question2. 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. Write program code for the function linearSearch(). Save your program. Copy and paste the program code into part 2(b)(i) in the evidence document.[6]
- (b)(ii)Edit the main program to: • allow the user to input an integer value • pass the value to linearSearch() as the parameter • output an appropriate message to tell the user whether the search value was found or not. Save your program. Copy and paste the program code into part 2(b)(ii) in the evidence document.[4]
- (b)(iii)Test your program with one value that is in the array and one value that is not in the array. Take a screenshot to show the result of each test. Save your program. Copy and paste the screenshots into part 2(b)(iii) in the evidence document.[2]
- (c)The following bubble sort pseudocode algorithm sorts the data in theArray into descending numerical order. There are five incomplete statements. PROCEDURE bubbleSort() DECLARE temp : INTEGER FOR X ← 0 to FOR Y ← 0 to IF theArray[y] temp ← theArray[y] theArray[y] ← theArray[y + 1] ← ENDIF NEXT Y NEXT X theArray[y + 1] THEN ENDPROCEDURE Write program code for the procedure bubbleSort() to sort the data in arrayData into descending order. Save your program. Copy and paste the program code into part 2(c) in the evidence document.[6]
Mark scheme
Marking points from the official mark scheme (May/June 2021). The mark or mark type is shown in brackets.
- [2] 1 mark per bullet point • Array with identifier arrayData • correct 10 data items added
- [6] 1 mark per bullet point • function linearSearch with correct identifier • ...taking integer search value as a parameter • Searching 10 times/through all array elements ...comparing each element to search value • returning True if found • returning False if not found
- [4] 1 mark per bullet point to max 4 • Taking value as input...checking/casting to Integer • Calling linearSearch and sending input as parameter • Storing and checking return value...outputting appropriate message if found and if not found
- [2] 1 mark for screenshot showing input and output for number found 1 mark for screenshot showing input and output for number not found
- [6] 1 mark per bullet point • Correct outer loop stop • Correct inner loop stop • Correct < in the IF • Correct theArray(y + 1) • Correct temp • Remainder matching pseudocode
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 →