Sunday, 23 April 2017

2D Arrays and IB Pseudocode

This brief post shows how to create a bi-dimentional array and describe it using IB pseudocode. It isn't stated in the IB Pseudocode in Examinations or Approved notation for developing pseudocode documents, so it's my answer to it, not an official one. Don't sue me if your examiner disagrees with me! O_o
declare A as integer array of size [ROWS][COLUMNS] or
declare A as integer array of size (ROWS, COLUMNS)
declare A as integer array of size [5][6]
declare A as integer array of size (5, 6)
Obviously, integer should be replaced by the appropriate data type.
IB papers may have defined it for you, or they may not ask you at all to define the size. You could define it (unknown size) as
declare A as integer array of size [ ][ ]
...then you'd use it like
loop ROW from 0 to 5
    loop COL from 0 to 6
        output A[ROW][COL]     or    output A(ROW, COL) 
    end loop
end loop
I'd recommend going for the [ ][ ] style as it'd be more consistent with the single dimensional arrays described in the IB pseudocode documents mentioned above.

No comments:

Technology and ethics

A very interesting article on drones... What price progress indeed. http://www.bbc.com/news/business-41737300 The comments and reflection ...