Skip to main content

Pseudocode

IA1:image.pngimage.pngimage.png

IA2 & IA3:image.png

Official guidance from the syllabus:

Pseudocode does not have a standard format and varies between programmers; however, algorithms must be able to be understood by anyone independent of a particular programming language. When students use pseudocode, they should: 

  • implement the basic control structures of assignment, sequence, selection, condition, iteration and modularisation using capitalised keywords associated with the constructs
  • indent algorithmic steps where appropriate
  • consider a case style that works best with the programming language they will be using in their project, e.g. Pascal Case or Camel Case. 

The following pseudocode demonstrates examples of assignment (DECLARE), sequence, condition (IF), selection (THEN), iteration (WHILE), modularisation (FUNCTION, CALL), indentation and two variations of case (UserLogin, userName) for a user authentication 
process:

image.png

Password DB Example - Pseudocode

Login
BEGIN
  DECLARE password, valid
  valid = False
  WHILE valid == False
    INPUT "Please enter the password:" -> password
    valid = CheckPassword(password)
  END WHILE
END

FUNCTION CheckPassword(password) AS BOOLEAN:
  DECLARE result, DB
  DB.connect()
  result = DB.query("SELECT * FROM Passwords
                     WHERE username = '_master' AND password = ?", [password])
  DB.disconnect()
  RETURN length(result) == 1
END FUNCTION

4-7: Keep asking the user for a password if it is wrong.

 

10: Create a function to make the code more modular.

 

12-15: Connect to the database and see if the password is in the database.

 

16: If a record is returned from the database, then it means that the correct password was entered so true is returned.

List Password
BEGIN
  DECLARE passwords
  
  ClearExistingData()

  FOR heading in ["Icon", "Name", "Username", "Action"]
    AddHeading(heading)
  NEXT heading

  passwords = GetPasswords()
  FOR row in passwords
    AddData(row['icon'], row['name'], row['username'], row['action'])
  NEXT row
END

FUNCTION GetPasswords() AS ARRAY:
  DECLARE result, DB
  DB.connect()
  result = DB.query("SELECT * FROM Passwords ORDER BY name")
  DB.disconnect()
  RETURN result
END FUNCTION

4: This is a method that will clear all old passwords information from the UI.

 

6-8: Add new headings.

 

10: get the data from the database.

 

11-14:  Add the information to the UI.

 

16: Function to make the core easier to maintain. 

 

18-21: connect to the database and get the information from the database about users.

Update Password
BEGIN
  DECLARE password
  DECLARE valid = false
  WHILE valid == false
    INPUT "Please enter the password:" -> password
    IF password != "" THEN
      valid = true
    END IF
  END WHILE
  UpdatePassword(password)
END

FUNCTION UpdatePassword(password):
  DECLARE DB
  DB.connect()
  result = DB.query("UPDATE Passwords SET password = ?
                     WHERE username = '_master'", [password])
  DB.disconnect()
END FUNCTION

3-9: Make sure that the data has been validated.

 

13: Function to make the core easier to maintain. 

 

15-18: connect to the database and update the data.