±«Óătv

Designing an algorithm flow chart

Algorithm design option one - flow diagram

A flow diagram showing how a program would enable a user to play the game rock, paper, scissors against a computer

Algorithm design option two - pseudo-code

# for the purpose of this example the array starts at 1
Options ← [“paper”, “rock”, “scissors”]

OUTPUT “Please enter your choice: 1, 2, or 3:”
player_choice ← USERINPUT
comp_choice ← RANDOM_INT (1, 3)
IF player_choice = comp_choice THEN
   OUTPUT “d°ùČč·É”
ELSE
       IF player_choice = 1 THEN
          IF comp_choice = 2 THEN
             winner ← “player”
          ELSE
             winner ← “comp”
          END IF
       ELSE IF player_choice = 2 THEN
         IF comp_choice = 3 THEN
            winner ← “player”
         ELSE
            winner ← “comp”
         END IF
       ELSE IF player_choice = 3 THEN
         IF comp_choice = 1 THEN
            winner ← “player”
         ELSE
            winner ← “comp”
         END IF
       IF winner = “player” THEN
          OUTPUT choices[player_choice] + “ beats” + choices[comp_choice]
       ELSE
         OUTPUT choices[comp_choice] + “ beats “ + choices[player_choice]
       END IF
END IF

Testing table

Tests will be required to check that the final program runs correctly, although this will be more difficult than example one as one value is a random number. Because of the complexity of the program, is not included in the exam question. However, it would be expected if this was a programming project scenario.

Test noDescriptionTest dataTest typeExpected outcome
1Both computer and player select 22Normal“d°ùČč·É”
2Computer selects winning choice of rock2Normal“rock beats scissors”
3Player selects winning choice of paper1Normal“paper beats rock”
1Both computer and player select 11Normal“d°ùČč·É”
2Computer selects winning choice of scissors3Normal“scissors beats paper”
3Player selects winning choice of rock2Normal“rock beats scissors”
Test no1
DescriptionBoth computer and player select 2
Test data2
Test typeNormal
Expected outcome“d°ùČč·É”
Test no2
DescriptionComputer selects winning choice of rock
Test data2
Test typeNormal
Expected outcome“rock beats scissors”
Test no3
DescriptionPlayer selects winning choice of paper
Test data1
Test typeNormal
Expected outcome“paper beats rock”
Test no1
DescriptionBoth computer and player select 1
Test data1
Test typeNormal
Expected outcome“d°ùČč·É”
Test no2
DescriptionComputer selects winning choice of scissors
Test data3
Test typeNormal
Expected outcome“scissors beats paper”
Test no3
DescriptionPlayer selects winning choice of rock
Test data2
Test typeNormal
Expected outcome“rock beats scissors”

The problem has now been fully decomposed and an algorithm has been designed.