Category
Pseudocode
C/C++ Source Code Equivalent
(Basic)
Data typesInteger
Floating Point
Characterint, long
float, double
charModule declarations
moduleName (parameter list if any)
Statement(s)
END
NB: Parameter list should also indicate whether the parameter(s) is being received or returned e.g.
SubAlgoritmTotal(receives num1 and num2, returns total)
void moduleName(parameter list if any)
{
Statement(s);
}OR
datatype moduleName(parameter list if any)
{
Statement(s);
return value;
}Variable declaration
Let variableName1 store a datatype value
datatype variableName1;
Constant declaration
CONSTNAME = value
NB: It is convention to use all uppercase characters when naming constants to distinguish them from variables.
Const datatype CONSTNAME = value;
Assigning Values
SET variableName TO value
OR
VariableName = value
VariableName = value;
Conditional Operators
operand1 = operand2
operand1 NOT = operand2
operand1 < operand2
operand1 > operand2
operand1 <= operand2
operand1 >= operand2
NB: The alternative is to express the operators in text e.g.
operand1 greater than or equal to operand2(operand1 == operand2)
(operand1 != operand2)
(operand1 < operand2)
(operand1 > operand2)
(operand1 <= operand2)
(operand1 >= operand2)Logical Operators
operand1 AND operand2
operand1 OR operand2
NOT operand1(operand1 && operand2)
(operand1 || operand2)
!(operand1)Selection
IF (condition) THEN
True statement(s) block
ELSE
False statement(s) block
ENDIFif (condition)
{
True statement(s) block;
}
else
{
False statement(s) block;
}Case/Switch
CASE OF single_variable
value_1 : statement block_1
value_2 : statement block_2
…
value_n : statement block_n
value_other : statement block_other
ENDCASEswitch (single_variable)
{
case value_1 : statement(s);
break;case value_2 : statement block_2;
break;
…case value_n : statement block_n;
break;
default value_other : statement block_other;
}WHILE-DO
Repetition
DOWHILE (condition)
statement(s)
ENDDOwhile (condition)
{
statement(s);
}DO-WHILE
Repetition
DO
statement(s)
WHILE (condition)do
{
statement(s);
}while (condition);Repeat-Until
Repetition
REPEAT
statement(s)
UNTILdo
{
statement(s);
}while !(condition);For loop
Repetition
DO counter = begin TO end
statement(s)
REPEAT
for (counter=begin; counter<=end; counter++)
{
statement(s);
}Record
Structures
recordName
fieldname1
fieldname2
…
fieldnameNstruct recordName
{
datatype fieldname1;
datatype fieldname2;
…
datatype fieldnameN;
}Sequential Files - Reading
Initial processing
READ variableName
DOWHILE NOT EOF
…
READ variableName
ENDDO
Final processing#include <fstream.h>
…
ifstream inFileHandle;
…
inFileHandle.open(“sourcefile”);
while(!inFileHandle.eof())
{
…
inFileHandle >> variableName;
}
inFileHandle.close();
Sequential Files - WritingWrite variableName
#include <fstream.h>
…
ofstream outFileHandle;
…
outFileHandle.open(“sourcefile”);
…
outFileHandle << variableName << “ ”;
…
outFileHandle.close();
Declaring 1DSET arrayName(MaxNumElements)
datatype arrayName[maxNumElements];
Arrays
Declaring 2DSET arrayName(rows, columns) datatype arrayName[rows][columns];
Array Proccessing
Assigning a value
arrayName(index) = value arrayName[index] = value;
Array Proccessing
Reading a value
VariableName = arrayName(index) variableName = arrayName[index];
Adapted from Simple Programming Design, 4th Edition, by Lesley Anne Robertson