Writing Simulation Code¶

Choice of Programming Language¶

The recommended language is C. Although this language lacks many of the features of more modern languages, it supports all the constructs we need for our relatively simple algorithms. You may use another language only with the agreement of the module co-ordinator (please note that requests to use heavyweight interpreted languages such as Matlab scripting and Visual Basic for Applications will not meet with agreement).

Installing a compiler and an IDE¶

If you are skilled at programming, you should have done this already, but just in case....

If you have Linux installed on your laptop/PC, I recommend using that. For example, in Ubuntu 13.10, open a terminal and type

\$sudo apt-get install build-essential eclipse-cdt


This installs (amongst other tools) the gnu C compiler and the Eclipse IDE (configured for use with C/C++). My colleague Derek Molloy has provided a video for his module on Object-Oriented Programming showing how to install the same software in Windows (including the minGW port of the gnu compiler).

(It has been drawn to my attention that earlier versions of Ubuntu may not include the eclipse-cdt package. In this case, install eclipse instead and follow the procedure in Derek’s video from 09:30 on to install CDT from within Eclipse.)

An alternative, and arguably simpler IDE, is Code::Blocks. Download the Windows version from (at the time of writing) http://www.codeblocks.org/downloads/26. Pick the version that includes minGW unless you already have the latter installed.

Writing C code¶

Derek Molloy discusses this in Chapter Two of his notes on C++. Another resource to consider is http://www.learn-c.org/.

The concepts you will need for the simulation are variables and variable types, arrays, branching, looping, functions, using the printf() function and simple file i/o. If you can code these in C or C++, you know enough to write the assignment code.