Notes: Stroustrup's Programming book

Bjarne Stroustrup's Programming -- Principles and Practice Using C++ book is a fantastic for those people who are new to programming in general and C++ in particular.

The problem, though, is that at least in the introductory chapters of the book, all the code heavily depends on the header file std_lib_facilities.h. I don't like my programs, even these early ones, to be dependent on such header files, so while trying out the codes he provided in the book, I also tried to write them such that the program would compile and run without that header file.

Another problem with that header file, is that (at least as of the date I am writing this), that header file is written for Windows and g++ shows some comments when you compile it, which is not too encouraging. On his webpage, Bjarne has a link to a Linux based header file, but the link doesn't point to a valid address, therefore Linux based learners will have a harder job at using this book. I hope these codes can provide some help.

Chapter 6: Calculator
The code to compile the calculator in Chapter 6 can be downloaded here. To compile and then run it you just have to run the following code in the folder containing the source code. (The $ is the shell prompt):
     $ g++ -o ch6cal ch6cal.cpp
     $ ./ch6cal

Chapter 7: Calculator [Continued]

  1. Calculator with no variables: download.
  2. Calculator with variables: the Token_stream::get() function (§7.8.2) has not been modified to read variables, so I had to add these two lines after the if in the default section of the switch statement in that function so it does the job:
    else if (is_declared(s))
        return Token(number, get_value(s));
    You can download the code for the final calculator of Chapter 7 here.

 

Some nice general quotes from the book:

  • Without understanding software [programming] you are reduced to believing in magic. p. xxiv.
  • Nobody should be satisfied with "because that is the way it is". p. 8.
  • [While explaining the wrong methods to teach programming, as a type of a wrong teaching method he explains:] Just believe in magic: this approach relies on demonstrations of powerful tools and techniques without introducing the novice to the underlying techniques and facilities. This leaves the student guessing - and usually guessing wrong - about why things are the way they are, what it costs to use them and where they can be reasonably applied. This can lead to over rigid following of familiar patterns of work and become a barrier to further learning. - p. 10.
  • Only a failed program will never be modified. - p. 34
  • Programming is understanding, when you program a task, you understand it. Conversely when you understand a task thoroughly, you can write a program to do it. In other words, we can see programming as part of an effort to thoroughly understand a topic. A program is a precise presentation of our understanding of a topic. - p. 35

 

Updated on: October 25th, 2013.
Created on: September 15th, 2013.

Tohoku University Astronomical Institute, 6-3 Aramaki, Aoba-ku, Sendai, Japan, 980-8578
    akhlaghi :a:t: astr.tohoku.ac.jp, Office: Physics A; 838, +81-80-3335-9474