My initiative The reason I post my computer science notes is to help others learn computer science more easily. I used to struggle with the Pseudocode rules and details. If you have any problems, please contact me at my email.
Pseudocode General Rules Identifiers
Meaningful Name : describe variants well(to be simple, longer :D)
Key Words
not using existing key words!!
Using comments as more as you can (//)
Naming Conventions
Data Normal Data Type :
INTEGER
REAL (float) : real number
CHAR : One character
STRING
BOOLEAN : TRUE or FALSE.
DATE : format is dd/mm/yyyy
ARRAY : a list
FILE : a single file
RECORD : using 1 id to include multiple data type
Abstract Data Type :
Definition : A collection of data and a set of operations on those data
STACK :First in Last out
push
pop
QUEUE :First in First out
enqueue
dequeue
LINKED LIST : like a pointer-oriented array
Declare Constants 1 CONSTANT HourlyRate = 6.5
Variables 1 DECLARE <variable_name1> : <datatype>, <variable_name2> : <datatype>
Assignments 1 <variable_name> ← <value>
Assign Date 1 <variable_name> ← SETDATE(<day>, <month>, <year>)
Control IF Statements (Nested, Maximum of three times)
1 2 3 4 5 6 IF <condition> THEN <do> ELSE (optional) <do> ENDIF
or(I think this is better)
1 2 3 4 5 IF <condition> THEN <do> ELSE (optional) <do> ENDIF
1 2 3 4 5 6 CASE OF <identifiers> <value 1>: <do> <value 2>, <value3>: <do> <value 4> TO <value5>: <do> OTHERWISE: <do> ENDCASE
Identifiers
Starts with a letter, supports only standard English characters, numbers + letters, case sensitive, includes underscores (_).
Loops Q :
Justify why one loop structure may be better suited to solve a problem than the others
A :
Count-Controlled Loop: Count is known, easy to write and read.
Pre-condition loop: Count is unknown, pre-condition check, dynamically stops.
Post-condition loop: Count is unknown, at least once, very user-friendly.
Count-Controlled Loop
1 2 3 4 FOR <identifier> ← <value1> TO <value2> <do> ... NEXT <identifier>
While Loops
WHILE Loop :Pre-condition loop
1 2 3 4 WHILE <statement> <do> ... ENDWHILE
Repeat-Until Loops
REPEAT UNTIL Loop :Post-condition loop 1 2 3 4 REPEAT <do> ... UNTIL <statement>
IO control
Output
File Open file: 1 OPENFILE "<filename>" FOR <filemode>
file mode: READ, WRITE, APPEND
note that APPEND mode is writing after the origin content, WRITE mode will remove all existing content.
Close file
Read file
Read a file (read a line into the variable )
1 READFILE "<filename>", <variable_name>
Write file
1 WRITEFILE "<filename>", <data>
EOF
Check whether the file is end
Function If the question specified that the variable is global, you don’t have to import yourself
Procedures:
1 2 3 PROCEDURE <precedure_name> ((Default is BYVAL)<param1>:<datatype>, <param1>:<datatype>) <do> ENDPROCEDURE
1 CALL <procedure_name> (<param1>, <param2>)
By reference
1 2 3 PROCEDURE <precedure_name> (<param1>:<datatype>, BYREF <param1>:<datatype>) <do> ENDPROCEDURE
1 2 3 4 FUNCTION <function_name> (<param1>:<datatype>, ...) RETURNS <datatype> <do> RETURN <variable_name> ENDFUNCTION
Array Define Array : One-dimension Array
1 DECLARE <variable_name> : ARRAY[<lower>:<upper>] OF <datatype>
Two-dimension Array
1 DECLARE <variable_name> : ARRAY[<low>:<up>, <low>:<up>] OF <datatype>
Assignment
Assign a value to a specified position
1 <array_name>[i] ← <data>
User defined datatype Non-composite Enumerated
Composite Record Definition :
hold a set of data
different data types
under one identifier
1 2 3 4 5 6 TYPE <type_name> DECLARE <subtype_name1> : <data_type> DECLARE <subtype_name2> : <data_type> DECLARE <subtype_name3> : <data_type> ...... ENDTYPE
data_type : INTEGER, CHAR, BOOLEAN, REAL, STRING, DATE
1 2 DECLARE <variable_name> : <type_name> <variable_nale>.<subtype_name1> ← <data>