For the compiler to use a function, it must be defined before it is used. The solution in C/C++ is to use header files that defines functions and macros.
For example, in many of the formulas we use in the text, the cumulative normal distribution function (N(z)) enters. This function is declared in a file normdist.h that looks like the following.
// normdist.h // author: Bernt A Oedegaard #ifndef _NORMAL_DIST_H_ #define _NORMAL_DIST_H_ double n(double z); // normal distribution function double n(double r,double mu, double sigmasqr); // normal distribution function double N(double z); // cumulative probability of normal double N(double a, double b, double rho); // cum prob of bivariate normal #endif
This header file declares two versions of the normal distribution, the univariate and the bivariate.
When N() is called with one argument, it is the univariate distribution that is referenced.
When N() is called with three arguments, it is the bivariate distribution which is referenced.
To make these function available in a subroutine, use the include statement to define them. Assume the header file normdist.h holds the defintions. The following is a complete program.
cout " Bivariate cum. normal dist (0,0,0) = "
<< N(0,0,0) << endl;
When compiled, linked and run, the program should print
Bivariate cum. normal dist (0,0,0) = 0.25