2011 Old Spec
The variable table, Table 4, and the Structured English algorithm, Figure 4, describe a linear search algorithm that could be used with a simplified version of the Dice Cricket game to find out if a particular player’s name appears in the high score table.
In this simplified version only the names of the players getting a top score are stored. Their scores are not stored.
|Names||Array[1..4] of String||Stores the names of the players|
|PlayerName||String||Stores the name of the player being looked for|
|Max||Integer||Stores the size of the array|
|Current||Integer||Indicates which element of the array Names is currently being examined|
|Found||Boolean||Stores True if the player’s name has been found in the array, False otherwise|
Names = 'Ben'
Names = 'Thor'
Names = 'Zoe'
Names = 'Kate'
Max = 4
Current = 1
Found = False
OUTPUT 'What player are you looking for?'
WHILE (Found = False) AND (Current <= Max)
IF Names[Current] = PlayerName
THEN Found = True
ELSE Current = Current + 1
IF Found = True
THEN OUTPUT 'Yes, they have a top score'
ELSE OUTPUT 'No, they do not have a top score'
What you need to do
- Write a program for the above algorithm.
- Test the program by searching for a player named 'Thor'.
- Test the program by searching for a player named 'Imran'.