Pseudocode Translation Quick Reference Guide

 Click Here for PDF Version

Category

Pseudocode

C/C++ Source Code Equivalent

(Basic)
Data types

Integer
Floating Point 
Character

int, long
float, double
char

Module 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
ENDIF

if (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


ENDCASE

switch (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)
ENDDO

while (condition)

   {
    
statement(s);
  
}

DO-WHILE

Repetition

DO
    
statement(s)

WHILE
(condition)

do

   {
    
statement(s);
  
}while (condition);

Repeat-Until

Repetition

REPEAT
    
statement(s)
UNTIL

do
  
{
    
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
     

    
fieldnameN    

struct 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 - Writing

Write variableName

#include <fstream.h>

ofstream
outFileHandle;

outFileHandle.open(“sourcefile”);

outFileHandle << variableName << “ ”;

outFileHandle
.close();


Declaring 1D

SET arrayName(MaxNumElements)

datatype arrayName[maxNumElements];

Arrays
Declaring 2D

SET 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