Designing an algorithm flow chart
Algorithm design option one - flow diagram
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, validationChecking input data is sensible and in the right format. is not included in the exam question. However, it would be expected if this was a programming project scenario.
Test no | Description | Test data | Test type | Expected outcome |
1 | Both computer and player select 2 | 2 | Normal | âd°ùČč·Éâ |
2 | Computer selects winning choice of rock | 2 | Normal | ârock beats scissorsâ |
3 | Player selects winning choice of paper | 1 | Normal | âpaper beats rockâ |
1 | Both computer and player select 1 | 1 | Normal | âd°ùČč·Éâ |
2 | Computer selects winning choice of scissors | 3 | Normal | âscissors beats paperâ |
3 | Player selects winning choice of rock | 2 | Normal | ârock beats scissorsâ |
Test no | 1 |
---|---|
Description | Both computer and player select 2 |
Test data | 2 |
Test type | Normal |
Expected outcome | âd°ùČč·Éâ |
Test no | 2 |
---|---|
Description | Computer selects winning choice of rock |
Test data | 2 |
Test type | Normal |
Expected outcome | ârock beats scissorsâ |
Test no | 3 |
---|---|
Description | Player selects winning choice of paper |
Test data | 1 |
Test type | Normal |
Expected outcome | âpaper beats rockâ |
Test no | 1 |
---|---|
Description | Both computer and player select 1 |
Test data | 1 |
Test type | Normal |
Expected outcome | âd°ùČč·Éâ |
Test no | 2 |
---|---|
Description | Computer selects winning choice of scissors |
Test data | 3 |
Test type | Normal |
Expected outcome | âscissors beats paperâ |
Test no | 3 |
---|---|
Description | Player selects winning choice of rock |
Test data | 2 |
Test type | Normal |
Expected outcome | ârock beats scissorsâ |
The problem has now been fully decomposed and an algorithm has been designed.