20an Algorith
20an Algorith
The names of the players are stored in an array with 6 elements called PlayerName. The index position of the array is
used to indicate the seat number. For example, the value of PlayerName(1) is ‘Helen’.
During the game, each player sometimes moves clockwise by a given number of places.
For example, if the number of places is 2, Helen will move to seat 3, Priya will move to seat 1 etc.
Write an algorithm, which updates the contents of the array ‘PlayerMove’ after a move has occurred. The algorithm
should:
- Allow the number of places to move to be input
- Use iteration
- Ensure that all of the players’ names are moved to the correct position in the array.
[6 marks]
Algorithm Example Answer
A computer game shows 6 players around a table on seats. They are numbered
1 to 6.
The names of the players are stored in an array with 6 elements called PlayerName. The index position of the array is
used to indicate the seat number. For example, the value of PlayerName(1) is ‘Helen’.
During the game, each player sometimes moves clockwise by a given number of places.
For example, if the number of places is 2, Helen will move to seat 3, Priya will move to seat 1 etc.
Write an algorithm, which updates the contents of the array ‘PlayerMove’ after a move has occurred. The algorithm
should:
- Allow the number of places to move to be input
- Use iteration
- Ensure that all of the players’ names are moved to the correct position in the array. [6 marks]
***There are always different ways to solve a problem. This algorithm is just an example. What is
important is that the logic is correct!***
LOGIC:
EXAMPLE ALGORITHM:
temp = playerName[6]
playerName[6] = playerName[5]
playerName[5] = playerName[4]
playerName[4] = playerName[3]
playerName[3] = playerName[2]
playerName[2] = playerName[1]
playerName[1] = temp
next i