So I'm bored so I decided to do the algorithm answers. I got some of these wrong in the actual exam but after looking at them now these are most likely all correct:
22 b)
(i)
position end current maximum Index(1) Index(2) Index(3) Index(4)
1 4 2 1 S F W A
1 4 3 3 S F W A
1 4 4 3 S F W A
1 4 5 3 W F S A
2 4 3 3 W F S A
2 4 4 3 W F S A
2 4 5 3 W S F A
3 4 4 3 W S F A
3 4 5 3 W S F A
(ii) A selection sort is used as the largest number is idenitified in the names array and then swapped with the number at the start of the array. After each swap, the number at the start of the array in increased by one (position = position +1) so the next largest number can be swapped into that position. This is the modelling of a selection sort.
(iii)
23 b)
(i) The error is WHILE touchPad = TRUE, it should be FALSE. This is so the timer is updated constantly until a person touches the touchpad which is makes sense. In it's current state, swimmer_time is only gotten when the gun goes off, the program would end as soon as the swimmer left the blocks as TouchPad = FALSE.
(ii) If a person false started, the swimmer_start_time is never gotten because startBlockOccupied would be FALSE and therefore the variable never gets the value of the timer as it is located in the conditional loop. So a false start is detected if swimmer_start_time = -1.000 as it would be greater than 0 if they didn't false start.
(iii) Not sure why this is worth 2 marks but I think you just need to have some sort of output (PRINT) of the swimmer_time between lines 140 and 150. Maybe 1 mark for the correct variable output and 1 mark for the correct placement of the code.
23 c)
(i) Array of Records.
(ii) - First error is that WHILE i < 100 should be i <= 100. Currently, the 100th record would miss out as when i is 100, the loop would end so only the first 99 records would be printed.
- Second error is that i is never incremented and so there would be an endless (infinite) loop as the value of i never changes and only the first record would be printed. Add i = i + 1 between lines 60-70.
(iii) There's obviously numerous ways to do this, here's mine:
22 b)
(i)
position end current maximum Index(1) Index(2) Index(3) Index(4)
1 4 2 1 S F W A
1 4 3 3 S F W A
1 4 4 3 S F W A
1 4 5 3 W F S A
2 4 3 3 W F S A
2 4 4 3 W F S A
2 4 5 3 W S F A
3 4 4 3 W S F A
3 4 5 3 W S F A
(ii) A selection sort is used as the largest number is idenitified in the names array and then swapped with the number at the start of the array. After each swap, the number at the start of the array in increased by one (position = position +1) so the next largest number can be swapped into that position. This is the modelling of a selection sort.
(iii)
Code:
BEGIN SUBPROGRAM swap(names, maximum, position)
temp = names(maximum)
names(maximum) = names(position)
names(position) = temp
END SUBPROGRAM
(i) The error is WHILE touchPad = TRUE, it should be FALSE. This is so the timer is updated constantly until a person touches the touchpad which is makes sense. In it's current state, swimmer_time is only gotten when the gun goes off, the program would end as soon as the swimmer left the blocks as TouchPad = FALSE.
(ii) If a person false started, the swimmer_start_time is never gotten because startBlockOccupied would be FALSE and therefore the variable never gets the value of the timer as it is located in the conditional loop. So a false start is detected if swimmer_start_time = -1.000 as it would be greater than 0 if they didn't false start.
(iii) Not sure why this is worth 2 marks but I think you just need to have some sort of output (PRINT) of the swimmer_time between lines 140 and 150. Maybe 1 mark for the correct variable output and 1 mark for the correct placement of the code.
23 c)
(i) Array of Records.
(ii) - First error is that WHILE i < 100 should be i <= 100. Currently, the 100th record would miss out as when i is 100, the loop would end so only the first 99 records would be printed.
- Second error is that i is never incremented and so there would be an endless (infinite) loop as the value of i never changes and only the first record would be printed. Add i = i + 1 between lines 60-70.
(iii) There's obviously numerous ways to do this, here's mine:
Code:
BEGIN maxKingdom
set i to 1
set count(1) to 0
set count(2) to 0
set count(3) to 0
WHILE i <= 100
IF organismDB(i).kingdom = "Animalia" THEN
count(1) = count(1) + 1
ELSEIF organismDB(i).kingdom = "Plantae" THEN
count(2) = count(2) + 1
ELSE
count(3) = count(3) + 1
END IF
i = i + 1
ENDWHILE
IF count(1) > count(2) THEN
max = 1
ELSE
max = 2
END IF
IF count(max) > count(3) THEN
ELSE
max = 3
END IF
SELECT CASE max
CASE 1: Print "Animalia"
CASE 2: Print "Plantae"
CASE 3: Print "Fungi"
END SELECT
Print count(max)
END maxKingdom
Last edited: