2011 Old Spec
Question 7
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.
Table 4
Identifier | Data Type | Purpose |
---|---|---|
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 |
Figure 4
Names[1] = 'Ben'
Names[2] = 'Thor'
Names[3] = 'Zoe'
Names[4] = 'Kate'
Max = 4
Current = 1
Found = False
OUTPUT 'What player are you looking for?'
INPUT PlayerName
WHILE (Found = False) AND (Current <= Max)
IF Names[Current] = PlayerName
THEN Found = True
ELSE Current = Current + 1
ENDIF
ENDWHILE
IF Found = True
THEN OUTPUT 'Yes, they have a top score'
ELSE OUTPUT 'No, they do not have a top score'
ENDIF
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'.