C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden C++ for Scientists - Technische Universität Dresden

math.tu.dresden.de
from math.tu.dresden.de More from this publisher
03.12.2012 Views

Copyright c○ 2010 Copyright (c); Peter Gottschling, René Heinzl, Karl Meerbergen, and Philipp Schwaha

Contents I Understanding C++ 7 Introduction 9 0.1 Programming languages for scientific programming . . . . . . . . . . . . . . . . . 9 0.2 Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1 Good and Bad Scientific Software 11 2 C++ Basics 19 2.1 Our First Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.2 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.4 Expressions and Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.5 Control statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.6 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.7 Input and output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.8 Structuring Software Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.9 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.10 Pointers and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.11 Real-world example: matrix inversion . . . . . . . . . . . . . . . . . . . . . . . . 53 2.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 2.13 Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3 Classes 65 3.1 Program for universal meaning not for technical details . . . . . . . . . . . . . . 65 3.2 Class members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 3.3 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 3.4 Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 3.5 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 3.6 Automatically Generated Operators . . . . . . . . . . . . . . . . . . . . . . . . . 76 3.7 Accessing object members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 3.8 Other Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4 Generic programming 89 4.1 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 4.2 Generic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 3

Copyright c○ 2010 Copyright (c); Peter Gottschling, René Heinzl, Karl Meerbergen, and<br />

Philipp Schwaha

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

Saved successfully!

Ooh no, something went wrong!