Header file crr.h, general:  This file is included in the other
files and tells them about type declarations.  Most statements in
C++ end with a semicolon.  An exception is a sequence of lines,
treated as one, in curly brackets.  An exception to the
exception is at the end of a class definition, which requires
a semicolon after the curly bracket.
// crr.h
//
// Simple binomial option pricing model: declarations
//
 ^
 |
 The // indicates this line is a comment ignored by the compiler

#define MAXTERNODES 400
 ^
 |
 The preprocessor deletes this line and substitutes 400 for
 every instance of MAXTERNODES before compilation

class crr {
 ^
 |
 This is the declaration of a new type of object called crr.
 This declaration tells about the members of each object of
 type crr.

public:
 ^
 |
 The public functions and variables (just functions in this
 program) are members that can be accessed from outside of
 the object.

  crr(double ttm=.25,int npers=4,double r=.05,double sigma=.3);
   ^
   |
   The member function crr is a constructor which does the
   initial set-up of an object of type crr.  The various arguments
   have type declarations (double means double-precision floating
   point number, int means integer), and default values (the
   numbers) for omitted arguments.

  double eurcall(double S0,double X);
   ^
   |
   The member function eurcall prices european call options.  The
   double at the start is the type of object the function
   returns.

  double binopt(double S0,double lower,double upper);
   ^
   |
   The member function binopt prices binary options.

private:
 ^
 |
 The private functions and variables (only variables in this
 program) are members that can be accessed only by members
 of the object.  Therefore, when we make changes to the
 internal workings of crr, we know that the only changes
 we need to make are for members of crr, since only members
 of crr can access the private members.  This is consistent
 with the philosophy in C++ of keeping the functions that
 act on an object together with the object, to minimize
 the probability of a programming error when we make changes.

  int nper;
  double tinc,r1per,disc,up,down,prup,prdn,Sprice;
  double val[MAXTERNODES];};
  ^
  |
  These are type declarations for various variables within an
  object of type crr.  The last declaration is for the vector
  val, which simultaneously declares val[0], val[1],...
  val[MAXTERNODES-1] (this last is val[399] given the definition
  of MAXTERNODES near the top of the file).  The curly bracket
  at the end closes the class definition started on the line
  class crr {

File crrtest.cc, general

// crrtest.cc
//
// Binomial option pricing model: test
//
 ^
 |
 Comment lines

#include <iostream.h>
#include "crr.h"
 ^
 |
 Include statements.  The preprocessor replaces each of these with
 the contents of the referenced file before compilation.  The first
 is a system file describing type declarations for input-output
 (where having the file name between "<" and ">" indicates the
 file is located in the usual place for system include files).  The
 second include statement is for our own file crr.h.

main() {
 ^
 |
 This is the routine that is run when we start the program.  It has
 no arguments, hence the ().  From the open curly bracket until the
 matched close curly bracket (at the end of the file) is the content
 of this routine.  The type is implicit (int) since not declared.

  crr c1;
   ^
   |
   c1 is an object of type crr.  This declaration (without arguments)
   initializes c1 using the constructor crr::crr with the default
   parameters as specified in the header file.  (For some reason,
   it is not okay to say crr c1() instead.)  To change from the
   default value, we could have instead a line here with the values
   we want, for example crr c1(.5,4,.05,.4); would have different
   time-to-maturity (1/2 year instead of 1/4 year) and standard
   deviation (.4 instead of .3) but the same number of periods and
   riskless rate.

  double stockP,strikeP;
   ^
   |
   This statement declares two double precision floating-point
   variables, stockP and strikeP, which are used to store the
   values provided by the user.

  cout << "\nType the stock price, a space, the strike"
    << " price, and then ENTER." << "\n"
    << "Make the stock price negative to terminate." << "\n\n";
   ^
   |
   This statement sends information to cout (normally the screen).
   Having \n in a string indicates moving to the start of the next
   line.  Multiple <<s allows the printing of multiple strings in
   one statement.

  while(1) {
   ^
   |
   This says to go through the steps from the curly bracket until
   its match (at the end of the file) so long as the argument is
   true.  However, 1 is always true, so this will try to do this
   indefinitely until something in the loop (or the operating
   system) terminates the program.

    cout << "stock-price strike-price: ";
     ^
     |
     More prompting the user.  Since there is no newline at the end,
     the user's response will appear on the same line.

    cin >> stockP >> strikeP;
     ^
     |
     This looks for two floating point numbers input from cin
     (normally the keyboard).
     
    if(stockP < 0.0){
      cout << "\nBye!\n" << endl;
      return(0);}
     ^
     |
     This test checks for a negative stock price (a signal to
     terminate) in the value just input.  If it finds the negative
     stock price, it prints a cute message, clears the output
     buffer, and terminates using return(0).  The 0 indicates
     completion of the program without error.  The endl goes to
     a new line and clears the output buffer; without the endl
     many dos or windows compilers will cause a segmentation
     fault.

    if(!cin){
      cout << "\nError: enter stock-price strike-price\n"
        << "Terminating\n" << endl;
      return(1);}
     ^
     |
     This says that if there was an input error (e.g. letters
     when numbers were expected), print an error message and
     return with a value 1 indicating an error.

    cout << "call option value = " << c1.eurcall(stockP,strikeP)
      << "\n\n";}}
     ^
     |
     This prints the computed value.  The expression
     c1.eurcall(stockP,strikeP) calls the member function
     eurcall of the object c1 (which is a binomial option
     pricing object of type crr) with arguments stockP and
     strikeP.  Conceptually, this works just like a function
     call in a spreadsheet, except that this is a function
     we have defined ourselves.  The function returns a
     double precision constant (as expressed in the type
     declaration crr.h).