Introduction to C++ (and C) Programming

[Pages:350]Intro Classes Efficiency OOP

Introduction to C++ (and C) Programming

Hans Petter Langtangen1,2

Simula Research Laboratory1 Dept. of Informatics, Univ. of Oslo2

January 2006

H. P. Langtangen

Introduction to C++ (and C) Programming

Outline

Intro Classes Efficiency OOP

1 Intro to C++ programming

About C and C++

Introductory C++ example

Manipulate data files

Matrix-vector product

The C preprocessor

Exercises

About classes in C++

A simple class

2 Class programming

Class Complex

A vector class

Standard Template Library

3 Efficiency; C++ vs. F77

4 Object-Oriented Numerical Programming

OOP example: ODE solvers

Classes for PDEs

H. P. Langtangen

Introduction to C++ (and C) Programming

Contents

Intro Classes Efficiency OOP

Gentle introduction to C++ File I/O Arrays and loops Detailed explanation of classes with built-in arithmetics Computational efficiency aspects Object-oriented programming and class hierarchies Using C++ objects in numerical applications

H. P. Langtangen

Introduction to C++ (and C) Programming

Intro Classes Efficiency OOP

Required background

Programming experience with either Java or Fortran/Matlab Interest in numerical computing with C++ Interest in low-level details of the computer Knowledge of some C is advantageous (but not required)

H. P. Langtangen

Introduction to C++ (and C) Programming

Intro Classes Efficiency OOP

About learning C++

C++ is a complicated computer language It takes time to master C++ ? one year is the rule of thumb Four days can only give a taste of C++ You need to work intensively with C++ in your own projects to master the language C++ exposes you to lots of "low-level details" ? these are hidden in languages like Java, Matlab and Python Hopefully, you will appreciate the speed and flexibility of C++

H. P. Langtangen

Introduction to C++ (and C) Programming

Intro Classes Efficiency OOP

Teaching philosophy

Intensive course:

Lectures 9-12 Hands-on training 13-16 Learn from dissecting examples Get in touch with the dirty work Get some overview of advanced topics Focus on principles and generic strategies Continued learning on individual basis

This course just gets you started - use textbooks, reference manuals and software examples from the Internet for futher work with projects

H. P. Langtangen

Introduction to C++ (and C) Programming

Intro Classes Efficiency OOP

Recommended attitude

Dive into executable examples Don't try to understand everything Try to adapt examples to new problems Look up technical details in manuals/textbooks Learn on demand Stay cool

H. P. Langtangen

Introduction to C++ (and C) Programming

Intro Classes Efficiency OOP

C/C++ Hello World I/O A*x Macros Exercises Classes

Why do you need to learn "old" compiled languages?

Because C, C++, and Fortran (77/95) are the most efficient existing tools for intensive numerical computing

Because tons of fast and well-tested codes are available in Fortran, C/C++

Newer languages have emphasized simplicity and reliability ? at the cost of computational efficiency

To get speed, you need to dive into the details of compiled languages, and this course is a first, gentle step

H. P. Langtangen

Introduction to C++ (and C) Programming

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download