Example :

Write pseudocode to validate a given password.

For a password to be valid it must contain:

  • at least two lower case letters
  • at least two uppercase characters
  • at least three digits
  • minimum 8 characters long

A function ValidatePassword is needed to check if a given password follows the above rules. This function takes a parameter Pass as a parameter and returns TRUE if it is valid and FALSE otherwise.

FUNCTION ValidatePassword(Pass: STRING) RETURNS BOOLEAN
DECLARE Result: BOOLEAN
DECLARE Lcase: INTEGER
DECLARE Ucase: INTEGER
DECLARE len: INTEGRER
DECLARE Letter: CHARACTER

Lcase ← 0
Ucase ← 0
Digits ← 0
Len ← LENGTH(Pass)

FOR x ← 1 TO Len
Letter ← MID(Pass,x,1)
IF Letter >= 'A' Letter <= Z THEN
Ucase ← Ucase + 1
ELSE IF Letter >= 'a' AND Letter <= 'z' THEN
Lcase ← Lcase + 1
ELSE IF Letter >= '0' AND Letter <= '9' THEN
Digits ← Digits + 1
ENDIF
NEXT x

IF len >= 8 AND Lcase >= 2 AND Ucase >= 2 AND Digits >= 2 THEN
Result ← True
ELSE
Result ← False
ENDIF

RETURN Result
ENDFUNCTION


Description:
LENGTH() function accepts a string and returns the number of characters in it.
MID(str,x,y) function extracts a substring of length y, from the string str, starting from the position x.
Pass - The variable which stores the password received by the function.
Letter - stores a character extracted by the MID() function from the string

STACK

sample:

Write pseudocode for implementing stack using array. Write the following procedure for stack operations:

  • Push() – Accepts an integer value to be pushed into the stack.
  • Pop() – to remove an item from the stack
  • and Display() – to display the content of the stack.

Display a menu to choose the stack operations like, Push, Pop, Display and Exit.

DECLARE MyStack: ARRAY[1,5] OF INTEGERS
DECLARE Choice: INTEGER
DECLARE Max: INTEGER
DECLARE Top: INTEGER
DECLARE Bottom: INTEGET
---------
PROCEDURE Push(val : INTEGER)
IF Top = StackFull THEN
OUTPUT "Sorry, Stack Full"
ELSE
Top Top + 1
MyStack[Top] Val
ENDIF
ENDPROCEDURE
---------
PROCEDURE Display()
IF Top = 0 THEN
OUTPUT "Stack is Empty"
ELSE
ind Top
WHILE ind > 0
OUTPUT MyStack[ind]
ind ind - 1
ENDIF
ENDPROCEDURE
---------
ROCEDURE Pop()
IF Top < 1 THEN
OUTPUT "Stack is Empty!"
ELSE
OUTPUT MyStack[Top],"has been removed from stack"
Top Top - 1
IF Top = 0 THEN
Bottom 0
ENDIF
ENDIF
ENDPROCEDURE
---------

StackFull 5
Top 0
Bottom 0
REPEAT
OUTPUT "1. PUSH"
OUTPUT "2. POP"
OUTPUT "3. DISPLAY"
OUTPUT "4. EXIT"
OUTPUT "Enter your choice"
INPUT choice

CASE Choice OF
1:
OUTPUT "Enter a number to push"
INPUT num
Push(num)

2: Pop()

3: Display()
ENDCASE
UNTIL Choice = 4