Designing an algorithm - example two
Algorithm design option one - flow diagram
Algorithm design option two - pseudocode
{set error flag to True to enable loop}
Set error = True
{iterate until a valid password is entered}
while error == True
{set all variables to default values }
set error = False
set lower case = 0
set upper case = 0
set number = 0
{input the password}
Output "Type in a password of at least 5
characters including 1 l/c letters, 1 u/c, 1 number: "
input password
{check password length - error if not at least 5 characters}
if len(password)< 5 then
error = True
end if
{if the password is the right length then}
{inspect each character in the password}
{add 1 to the number of upper case for each upper case character}
{add 1 to the number of lower case for each lower case character}
{add 1 to the number of numbers for each number}
if error = False then
for position (0 to len(password))
{loop between 0 and length of password}
if password[position] >="A" AND password[position]
< ="Z" then
upper case = upper case + 1
else if password[position] >="a" AND
password[position]< ="z" then
lower case = lower case 1
else if password[position] >="0" AND
password[position]< ="9" then
number = number + 1
next position
end if
{if character requirements are not met, an error has occured}
if upper case < 1 OR lower case < 1 OR number < 1 then
error = True
output "Password not accepted"
Else
{output acceptance}
output "Password accepted: "< password
end if
ENDOutput table
With the inputs stated below the outputs would be:
Example:
Type in a password of at least 5 characters including 1 l/c letters, 1 u/c, 1 number: Pass1234
Password accepted: Pass1234
Testing table
Tests will be required to test that the final program runs correctly.
| Test no. | Description | Test data | Test type | Expected outcome |
| 1 | Enter a valid password | Abcd36 | Valid | Password should be accepted |
| 2 | Enter a ten-character password | ABcd457Anz | Valid | Password should be accepted |
| 3 | Enter a five-character password | Abc67 | Extreme | Password should be accepted |
| 4 | Password has at least one lower case character | ABCd57 | Extreme | Password should be accepted |
| 5 | Password has at least one number | ABcd36 | Extreme | Password should be accepted |
| 6 | Password has at least one upper case character | Abcd45 | Extreme | Password should be accepted |
| 7 | Password is too short | Abc5 | Invalid | Password must be re-entered |
| 8 | Password does not contain at least one upper case character | abcd5 | Invalid | Password must be re-entered |
| 9 | Password does not contain at least one lower case character | ABCD8 | Invalid | Password must be re-entered |
| 10 | Password does not contain at least one number | ABcde | Invalid | Password must be re-entered |
| Test no. | 1 |
|---|---|
| Description | Enter a valid password |
| Test data | Abcd36 |
| Test type | Valid |
| Expected outcome | Password should be accepted |
| Test no. | 2 |
|---|---|
| Description | Enter a ten-character password |
| Test data | ABcd457Anz |
| Test type | Valid |
| Expected outcome | Password should be accepted |
| Test no. | 3 |
|---|---|
| Description | Enter a five-character password |
| Test data | Abc67 |
| Test type | Extreme |
| Expected outcome | Password should be accepted |
| Test no. | 4 |
|---|---|
| Description | Password has at least one lower case character |
| Test data | ABCd57 |
| Test type | Extreme |
| Expected outcome | Password should be accepted |
| Test no. | 5 |
|---|---|
| Description | Password has at least one number |
| Test data | ABcd36 |
| Test type | Extreme |
| Expected outcome | Password should be accepted |
| Test no. | 6 |
|---|---|
| Description | Password has at least one upper case character |
| Test data | Abcd45 |
| Test type | Extreme |
| Expected outcome | Password should be accepted |
| Test no. | 7 |
|---|---|
| Description | Password is too short |
| Test data | Abc5 |
| Test type | Invalid |
| Expected outcome | Password must be re-entered |
| Test no. | 8 |
|---|---|
| Description | Password does not contain at least one upper case character |
| Test data | abcd5 |
| Test type | Invalid |
| Expected outcome | Password must be re-entered |
| Test no. | 9 |
|---|---|
| Description | Password does not contain at least one lower case character |
| Test data | ABCD8 |
| Test type | Invalid |
| Expected outcome | Password must be re-entered |
| Test no. | 10 |
|---|---|
| Description | Password does not contain at least one number |
| Test data | ABcde |
| Test type | Invalid |
| Expected outcome | Password must be re-entered |
The problem has now been fully decomposed and an algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs. has been designed.