A 1D array needs to store the names of 10 animals.
- (a)Write program code to declare the global string array Animals to store 10 items.[2]
- (b)The main program needs to store the following animals in the array: horse lion rabbit mouse bird deer whale elephant kangaroo tiger Write program code to store these animal names in the array. The names must be in lower case and stored in the order given in the list.[2]
- (c)The following pseudocode procedure sorts the array into a descending alphabetical order using only the first character in each animal name. The function LENGTH (DataArray) returns the number of elements in the array DataArray. The function MID(String, Start, Quantity) returns Quantity number of characters from String starting at index Start. The first character in the string is index 0, for example: MID("tiger", 0, 2) will return "ti" There are four incomplete statements in the procedure. PROCEDURE SortDescending() DECLARE ArrayLength : INTEGER DECLARE Temp : STRING ArrayLength ← LENGTH(Animals) FOR X ← 0 TO ArrayLength - 1 FOR Y ← .......... TO ArrayLength - X - 1 IF MID(Animals[Y], 0, 1) < MID(Animals […], 0, 1) THEN Temp ← Animals [..........] Animals [Y] ← Animals [Y + 1] Animals [Y + 1] ← .......... ENDIF NEXT Y NEXT X ENDPROCEDURE Write program code for the procedure SortDescending().[6]
- (d)(i)Write program code to amend the main program to: • call the procedure SortDescending() • output the sorted contents of the array with each animal name on a new line.[3]
- (d)(ii)Test your program. 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] Global array named Animals
- [1] 10 string elements
- [1] Storing all 10 items in the array
- [1] in the correct order and all in lower case
- [1] Correct Y loop limit: TO ArrayLength - X - 1
- [1] Correct element in second MID: Animals [Y+1]
- [1] Correct element for Temp assignment: Temp ← Animals [Y]
- [1] Correct element for Animals[Y+1] assignment: Animals [Y + 1] ← Temp
- [1] Use of appropriate string functions to access e.g. MID and length
- [1] Remainder of procedure correct and following example
- [1] calling the procedure SortDescending()
- [1] looping through all array elements
- [1] outputting each array element on a new line
- [1] 1 mark for screenshot e.g. whale, tiger, rabbit, mouse, lion, kangaroo, horse, elephant, deer, bird
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 →