You are on page 1of 4

T1W5 Assignment Alg Description Qualifying Array

The Aim of this assignment is to help you understand the application of algorithms to Arrays of Records.
Consider the "Qualifying" Array of Records data on Page 191.
The algorithm in Fig 4.28 calculates the fastest lap time for each car.
Complete these 2 parts in ONE word document and upload it when you are finished.

1. Copy the algorithm and FOR EACH LINE explain the purpose of the line. In doing so describe the purpose of all variables as
they occur and of the indices in the array. (It is not sufficient to write "starts a WHILE loop". You must explain the loop and say what
the loop achieves in the whole algorithm.) You can expect a question like this in the next assessment task. You might want to do this
in a table, in landscape.

2. Write down the output for the algorithm.

Algorithm
BEGIN CalculateFastestLaps
Count = 1
WHILE Count <= Total Cars
Num = 2
Fastest = 1
WHILE Num <= 5
IF Qualifying(Count).Lap(Num) < Qualifying(Count).Lap(Fastest) THEN
Fastest = Num
ENDIF
Num = Num + 1
ENDWHILE
Display Qulifying(Count).Driver, Qualifying(Count).Lap(Fastest)
Count = Count + 1
ENDWHILE
END CalculateFastestLaps

Output
The output of this algorithm will display the fastest lap time for each car.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++

Algorithm

The Algorithm
BEGIN CalculateFastestLaps
Count = 1
WHILE Count <= Total cars

Num = 2
Fastest = 1
WHILE Num <= 5
IF Qualifying(Count).Lap(Num) <
Qualifying(Count).Lap(Fastest) THEN
Fastest = Num
ENDIF
Num = Num + 1
ENDWHILE
Display Qualifying(Count).Driver,
Qualifying(Count).Lap(Fastest)
Count = Count + 1
ENDWHLE
END CalculateFastestLaps

Explanation of the algorithm


Commences the CalculateFastestLaps section
A defined Variable that declares the count as 1
Commences the WHILE loop which is sustained that
counts through all the cars until the amount of cars is
less than the count which is 1
a defined variable that declares the Num as 2
a defined variable that sets Fastest as 1
Commences another WHILE loop that is sustained until
the Num is more or equal to 5
Begins the nested IF statement prompts the lap time
only if the Qualifying(Count).Lap(Num) is less than the
Qualifying(Count).Lap(Fastest)
Establishes the index Fastest into Num
Ends the nest IF statement
Establishes the Num to + 1
Ends the WHILE loop
It displays every driver and their fastest lap time
Establishes the Count to + 1
Ends the WHILE loop
Completes the CalculateFastestLaps section

Output
The output of this algorithm will display the fastest lap time for each car, such as: KLINGMANN- 7:59, STIPPLER- 7:57,
MULLER- 8:31

You might also like