12.07.2015 Views

1 Preface 2 Linux as operating system, C++ as programming lan ...

1 Preface 2 Linux as operating system, C++ as programming lan ...

1 Preface 2 Linux as operating system, C++ as programming lan ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1 <strong>Preface</strong>We expect you, <strong>as</strong> students attending to the course “Introduction to Computational Physics”,to have already some, at le<strong>as</strong>t b<strong>as</strong>ic, knowledge about computers and computer <strong>programming</strong>and experience working with a <strong>programming</strong> <strong>lan</strong>guage like <strong>C++</strong>, Java, Fortran and tool likeMatlab, Maple, Mathematica, etc.While any familiarity with such <strong>lan</strong>guages and tools is highly favorable and makes is muche<strong>as</strong>ier for you to keep pace with this course with lesser amount of time and afford, being anabsolute beginner will not disqualify you from taking the course. In this c<strong>as</strong>e, however, you willneed more time and dedication to get the most out of the lessens and exercises. We will do ourbest to help you establish a solid and comprehensive background in this field which you willbe able in the future to further develop and of which you will have benefits for the rest of yourcareer.2 <strong>Linux</strong> <strong>as</strong> <strong>operating</strong> <strong>system</strong>, <strong>C++</strong> <strong>as</strong> <strong>programming</strong> <strong>lan</strong>guageWe, generally, regard <strong>Linux</strong> <strong>as</strong> the most convenient <strong>operating</strong> <strong>system</strong> and <strong>C++</strong> <strong>as</strong> the mostsuitable <strong>programming</strong> <strong>lan</strong>guage under which we will develop our programs and simulations.The re<strong>as</strong>on is to have a uniform working environment and to avoid diversity facilitating an e<strong>as</strong>yand f<strong>as</strong>t interaction between the students. However, everyone is free to choose his/her <strong>operating</strong><strong>system</strong>and<strong>programming</strong><strong>lan</strong>guage,<strong>as</strong>long<strong>as</strong>thegoalofthelessonsandtheexercisesisreached.In the following sections, we will help you writing simple programs in <strong>C++</strong> and run them under<strong>Linux</strong> and <strong>as</strong>sign you with simple t<strong>as</strong>ks introducing you to the subject.3 Logging in and getting things to work• The computers are double boot machines, i.e. you may have to restart for <strong>Linux</strong>. Log inwith your account information.• Open a browser. Under the following address you can find all the information and scriptsabout this course: http://www.ifb.ethz.ch/education/IntroductionComPhys• Open a terminal (shell). A shell is a program that provides the traditional, text-onlyuser interface for <strong>Linux</strong> and other Unix-like <strong>operating</strong> <strong>system</strong>s. Its primary function isto read commands that are typed into a console (i.e., an all-text display mode) or terminalwindow (an all-text window) and then execute (i.e., run) them. (Definition fromhttp://www.linfo.org)• Create a new directory named, e.g. test: mkdir test• Enter the created directory: cd test• Start an editor (here, e.g. gedit) to write a program in <strong>C++</strong>: gedit Hello.cc (Alwaysuse re<strong>as</strong>onable names telling a little bit about the content.)• Write whatever you like, save and exit the editor.


4 Some useful commandsCOMMAND USAGEpwd shows the path of the current directorymkdir name creates directory name“ ”cd name change to directory name“ ”gedit starts GNU-Editor (recommended)(x)emacs Starts (X)EMACS editorls lists files and directoriesls -l also display more information, <strong>as</strong> sizecp, mv copy, move files and directoriesman displays the documentation to a commandg++ compiles C, <strong>C++</strong> programscommand & command into backgroundexit exit shell/window5 Our first programm• Create a new directory (subdirectory) for the exercises, e.g., comphys.• Copy our little program hello.cc into this directory: cp hello.cc comphys/• Change into comphys: cd comphys• Open the editor to edit hello.cc. Write the following code and save it:#include using namespace std;int main(){cout


cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!