INF-VERK3830/4830: C++ and C Programming

During the last decade, C++ has established itself as a flexible, advanced, and efficient language for software development in general, including high-performance numerical applications. This course aims at getting you started with C++ programming. The target audience consists of experienced programmers among master/phd students, researchers, and supervisors.

Most of the examples have their origin in numerical computations, and computational efficiency is particularly addressed. As a part of the presentation of C++ we will also outline some features of C and point out similarities and differences between C and C++. We also describe pitfalls and problems with C++.

Experience shows that it takes time to master C++, and a four-day course can at most get you started. However, we have put efforts into finding examples and teaching strategies that bring you right to useful applications, especially in numerical computing. Doing the compulsory exercises in addition to studying the slides should give you a good foundation for learning more by using C++ in your own projects.

Teaching

The course is taught over four days with lectures from 9.15 to 12.00 and hands-on programming sessions with guidance from 13.00 to 16.00. The location for the lectures is Auditorium 3 in the Helga Eng building, except on January 27 where we must use Auditorium 2 in the same building. The hands-on computer sessions will take place in the basement of the Mathematics building (Niels Henrik Abels hus). We have allocated about 20 machines in the room. Two students can share a machine, but it is not space for all the course participants. The rest has to do the exercises somewhere else.

All lectures will be given by Hans Petter Langtangen, Simula Research Laboratory and Department of Informatics (hpl at simula.no).

Teaching material

Slides from the lectures are available in different formats (last updated Jan 29, 2006): I also recommend to have access to a textbook. There are lots of books in the bookstore. For reference, I prefer Strousrup's book, but this is not a good book for novice C++ programmers. A good C++ introduction for numerical computing is Yang: C++ and Object-oriented Numeric Computing for Scientists and Engineers, Springer 2000.

Errata (teaching material)

In exercise 3, the sum over i should have n-2 (not n-1) as the upper limit.

In exercise 6, you can just do allocation/deallocation inside the loops:

for (i=1; i<=NREPETITIONS; i++)
{
  // allocate a vector of n doubles
  // deallocate the vector
}

for (i=1; i<=NREPETITIONS; i++)
{
  // allocate each of the doubles separately:
  for (j=1; j<=n; j++) 
  {
    // allocate a double
    // free the double
  }
}

Exam

To get the 5 point credit for this course at the University of Oslo, you need to The collection of solutions to exercises should be sent to hpl at ifi.uio.no> by June 1, 2005. Place all the files in a directory with your username as root. Files associated with solutions to exercise no. X should have filenames starting with exerciseX. Pack this directory tree in a tarfile or zipfile with the same name as your username, prefixed with cpp_ (for example, a user hpl will send a tarfile name cpp_hpl.tgz, which yields a directory hpl with all exercise files when packed out).

How to register

Ordinary UiO students use the student-web to register.

Others (from external institutions) can register here.

Feedback

Please give feedback on this course to hpl at simula.no!!

C++ programming resources

C programming resources

Other useful resources

This page is maintained by hpl at simula.no