PDF version - Computing Help - University of Cambridge
PDF version - Computing Help - University of Cambridge
PDF version - Computing Help - University of Cambridge
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
1A C++ courseworkhttp://www-h.eng.cam.ac.uk/help/tpl/languages/C++/...The value <strong>of</strong> num=5Putting it all together [ back to contents (#Contents) ]All the examples so far have been fragments. Now you're going to write complete programs. All theC++ programs that you're likely to write will need the following framework. The Input/Output andstring functionality is not actually part <strong>of</strong> the core language. To use it you need the following lines atthe start <strong>of</strong> your code.#include #include using namespace std;In C++ a function is a runnable bit <strong>of</strong> code that has a name. The code might calculate a value (like a function in mathematics does)but it might just perform a task (like printing something to the screen). Every C++ program has a function called main. When theprogram is started, the main function is run first. So your program needs a main function which will look like this.int main() {}...Don't worry for now what this all means. Just remember that all your programs will probably need lines like these.Now we'll write a minimal program. At the moment your 1A<strong>Computing</strong> folder is nearly empty. In the File menu <strong>of</strong> the 1A<strong>Computing</strong> -File Browser window pick the Create Document option and create a file called program1.cc . Drop the file into the Geany iconon the desktop and you'll get the following window4 <strong>of</strong> 36 11/01/2012 04:05 PM